delinquent_files/demon.php

Wed, 06 Mar 2024 02:54:34 +0100

author
Peter Gervai <grin@grin.hu>
date
Wed, 06 Mar 2024 02:54:34 +0100
changeset 10
d80db6c7a442
parent 9
43902b1af1b9
permissions
-rwxr-xr-x

demon: fake timestamp for replaces

0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
1 #!/usr/bin/php
6
8b4e205ffc94 demon.php: ease some db pressure by not querying old entries (7 days).
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
2 #$Id$
8b4e205ffc94 demon.php: ease some db pressure by not querying old entries (7 days).
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
3 #
8b4e205ffc94 demon.php: ease some db pressure by not querying old entries (7 days).
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
4
0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
5 <?PHP
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
6
6
8b4e205ffc94 demon.php: ease some db pressure by not querying old entries (7 days).
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
7
0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
8 chdir ( '/data/project/commons-delinquent' ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
9
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
10 error_reporting(E_ERROR|E_CORE_ERROR|E_COMPILE_ERROR); # E_ALL|
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
11 ini_set('display_errors', 'On');
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
12
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
13 require_once ( './shared.inc' ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
14 require_once( './matcher.inc' );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
15 require_once( './debug.inc' );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
16
6
8b4e205ffc94 demon.php: ease some db pressure by not querying old entries (7 days).
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
17 print "Bot startup in progress...\n";
8b4e205ffc94 demon.php: ease some db pressure by not querying old entries (7 days).
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
18
0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
19 class CommonsDelinquentDemon extends CommonsDelinquent {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
20
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
21 var $avoidNamespaceOnWiki = [
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
22 'dewiki' => [4]
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
23 ] ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
24
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
25 private $d;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
26 private $matcher;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
27
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
28 var $maximum_file_usage_limit = 65535; # prevent memory explosion by extreme used files (65535 ~ 650 MB)
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
29 var $delay_minutes = 10 ; # Wait after deletion
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
30 var $fallback_minutes = 120 ; # Only used if DB is empty
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
31 var $max_text_diff = 1500 ; # Max char diff
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
32 var $min_faux_template_icon = 500 ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
33 var $comments = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
34 var $comments_default = array (
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
35 'summary' => 'Removing [[:c:File:$1|$1]], it has been deleted from Commons by [[:c:User:$2|$2]] because: $3.' ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
36 'replace' => 'Replacing $1 with [[File:$2]] (by [[:c:User:$3|$3]] because: $4).' ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
37 'by' => ' Requested by [[User:$1|]].'
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
38 ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
39
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
40 function __construct() {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
41 parent::__construct();
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
42 $this->d = new Debug;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
43 $this->matcher = new Matcher($this->d);
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
44 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
45
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
46 function set_debug_mode($l) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
47 $this->d->set_level( $l );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
48 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
49
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
50 function debug($msg) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
51 $this->d->debug($msg);
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
52 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
53
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
54 // Returns the last timestamp in the tool database, or a dummy (current time - X min)
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
55 function getLastTimestamp () {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
56 # Open tool database
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
57 $db = $this->getToolDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
58
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
59 # Get highest timestamp in tool DB as a starting point
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
60 $max_ts = '' ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
61 $sql = "SELECT max(log_timestamp) AS max_ts FROM event WHERE done=1" ; # Timestamp of Commons logging table, NOT tool edit timestamp!
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
62 $result = $this->runQuery ( $db , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
63 while($o = $result->fetch_object()){
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
64 $max_ts = $o->max_ts ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
65 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
66 $db->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
67 if ( $max_ts == '' ) $max_ts = date ( 'YmdHis' , time() - $this->fallback_minutes*60 ) ; # Fallback to current date minus X min
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
68 return $max_ts ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
69 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
70
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
71 function isBadPage ( $o , $filename ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
72 if ( $o->gil_page_namespace_id == 6 and $o->gil_wiki == 'commonswiki' and $o->gil_to == $filename ) return true ; // Self-reference
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
73 if ( $o->gil_page_namespace_id == 2 and $o->gil_wiki == 'commonswiki' and preg_match ( '/^\w+Bot\b/' , $o->gil_page_title ) ) return true ; // Bot subpage on Commons
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
74 if ( $o->gil_page_namespace_id == 4 and $o->gil_wiki == 'commonswiki' and preg_match ( '/(Deletion(_| )requests\/.*|Undeletion(_| )requests\/.*)\b/' , $o->gil_page_title ) ) return true ; // DR and UDR on Commons
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
75 foreach ( $this->avoidNamespaceOnWiki AS $wiki => $namespaces ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
76 if ( $o->gil_wiki != $wiki ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
77 foreach ( $namespaces AS $namespace ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
78 if ( $namespace == $o->gil_page_namespace_id ) return true ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
79 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
80 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
81 return false ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
82 }
8
38415be9f910 Skipping {{nobots}} pages
Peter Gervai <grin@grin.hu>
parents: 6
diff changeset
83
38415be9f910 Skipping {{nobots}} pages
Peter Gervai <grin@grin.hu>
parents: 6
diff changeset
84 ## page content forbidding bots, like {{nobots}} or {{bots|deny=..us..}}
38415be9f910 Skipping {{nobots}} pages
Peter Gervai <grin@grin.hu>
parents: 6
diff changeset
85 function isForbiddenPage ( $content ) {
38415be9f910 Skipping {{nobots}} pages
Peter Gervai <grin@grin.hu>
parents: 6
diff changeset
86 if ( preg_match( '\{\{nobots\}\}|\{\{bots\s*\|\s*deny=([^}]*CommonsDelinker|all)', $content) ) return true;
38415be9f910 Skipping {{nobots}} pages
Peter Gervai <grin@grin.hu>
parents: 6
diff changeset
87 return false;
38415be9f910 Skipping {{nobots}} pages
Peter Gervai <grin@grin.hu>
parents: 6
diff changeset
88 }
0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
89
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
90 function getRecentDeletedFiles ( $max_ts ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
91 # Open Commons database replica
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
92 $db_co = $this->getCommonsDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
93 $cur_ts = date ( 'YmdHis' , time() - $this->delay_minutes*60 ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
94
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
95 # Get all file deletions
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
96 $delink_files = array() ; # Files to delink
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
97 $sql = "SELECT * FROM logging_compat LEFT JOIN comment ON comment_id = log_comment_id WHERE log_type='delete' AND log_action='delete' AND log_timestamp>='$max_ts' AND log_timestamp<'$cur_ts' AND log_namespace=6" ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
98 $sql .= " AND NOT EXISTS (SELECT * FROM image WHERE img_name=log_title)" ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
99 $sql .= " AND NOT EXISTS (SELECT * FROM page WHERE page_title=log_title AND page_namespace=6 AND page_is_redirect=1)" ; # Do not remove redirects. Is that OK???
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
100 $sql .= " ORDER BY log_timestamp ASC" ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
101 $result = $this->runQuery ( $db_co , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
102 while($o = $result->fetch_object()){
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
103 $delink_files[] = $o ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
104 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
105 foreach ( $delink_files AS $deletion ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
106 $filename = $deletion->log_title ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
107 $sql = "SELECT * FROM globalimagelinks WHERE gil_to='" . $this->getDBsafe($filename) . "'" ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
108 $deletion->usage = array() ; # Usage instances for this file
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
109 $result = $this->runQuery ( $db_co , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
110 while($o = $result->fetch_object()){
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
111 if ( $this->isBadWiki($o->gil_wiki) ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
112 if ( $this->isBadPage($o,$filename) ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
113 $deletion->usage[] = $o ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
114 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
115 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
116 $db_co->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
117 // print_r ( $delink_files ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
118 return $delink_files ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
119 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
120
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
121 function getFileUsage ( $filename ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
122 $this->d->trace("Get file usage for $filename");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
123 $ret = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
124 $db_co = $this->getCommonsDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
125 $cur_ts = date ( 'YmdHis' , time() - $this->delay_minutes*60 ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
126 $sql = "SELECT * FROM globalimagelinks WHERE gil_to='" . $this->getDBsafe($filename) . "'" ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
127 $this->d->trace("Try running: $sql");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
128 $result = $this->runQuery ( $db_co , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
129 $this->d->trace("Got result, looping through");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
130 while($o = $result->fetch_object()){
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
131 if ( $this->isBadWiki($o->gil_wiki) ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
132 $ret[] = $o ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
133 // $this->d->trace("Added to ret, len=" . count($ret));
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
134 # limit the maximum matches because we use more memory than toolforge allows
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
135 if( count($ret) > $this->maximum_file_usage_limit ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
136 $this->d->error("Overflow!! We cannot get usage for $filename, too much hits (>$this->maximum_file_usage_limit)!");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
137 $ret = array();
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
138 $ret[] = "*OVERFLOW*";
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
139 $db_co->close();
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
140 return $ret;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
141 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
142 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
143 $this->d->trace("Processed " . count($ret) . " usage points");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
144 $db_co->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
145 return $ret ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
146 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
147
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
148 function canUnlinkFromNamespace ( $usage ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
149 if ( $usage->gil_page_namespace_id % 2 > 0 ) return false ; // Skip talk pages
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
150 if ( $usage->gil_page_namespace_id < 0 ) return false ; // Paranoia
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
151 return true ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
152 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
153
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
154 function fileExistenceSanityCheck ( $e , $check_commons ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
155 if ( $this->hasLocalFile ( $e->wiki , $e->file ) ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
156 $this->setDone ( $e->id , 2 , 'Skipped: Local file exists' ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
157 return false ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
158 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
159 if ( $check_commons and $this->hasLocalFile ( 'commonswiki' , $e->file ) ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
160 $this->setDone ( $e->id , 2 , 'Skipped: Commons file exists' ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
161 return false ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
162 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
163 return true ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
164 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
165
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
166
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
167 function getTextFromWiki ( $wiki , $pagename ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
168 $ret = false ;
3
24d8f83459b3 demon.php: Add API debug output, lower speel delay
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
169 $this->d->debug( "Getting api of " . $wiki) ;
6
8b4e205ffc94 demon.php: ease some db pressure by not querying old entries (7 days).
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
170 // temp workaround 3/22/2023
8b4e205ffc94 demon.php: ease some db pressure by not querying old entries (7 days).
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
171 //if ($wiki === 'bclwiktionary' || $wiki === 'bjnwiktionary' || $wiki === 'gorwiktionary') {
8b4e205ffc94 demon.php: ease some db pressure by not querying old entries (7 days).
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
172 // return false;
8b4e205ffc94 demon.php: ease some db pressure by not querying old entries (7 days).
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
173 //}
0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
174 $api = $this->getAPI ( $wiki ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
175 if ( $api ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
176 $services = new \Mediawiki\Api\MediawikiFactory( $api );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
177 $page = $services->newPageGetter()->getFromTitle( $pagename );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
178 $revision = $page->getRevisions()->getLatest();
6
8b4e205ffc94 demon.php: ease some db pressure by not querying old entries (7 days).
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
179
0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
180 if ( $revision ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
181 $ret = $revision->getContent()->getData() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
182 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
183 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
184 return $ret ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
185 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
186
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
187 /**
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
188 mode "summary" or "replace"
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
189 */
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
190 function getLocalizedCommentPattern ( $wiki , $mode = 'summary') {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
191 if ( !isset($mode) ) $mode = 'summary' ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
192 if ( isset ( $this->comments[$mode][$wiki] ) ) return $this->comments[$mode][$wiki] ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
193 $pattern = $this->comments_default[$mode] ; # Default
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
194
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
195 # Try local translation
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
196 $local = $this->getTextFromWiki ( $wiki , 'User:CommonsDelinker/' . $mode . '-I18n' ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
197 if ( $local !== false ) $pattern = $local ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
198
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
199 $this->comments[$mode][$wiki] = $pattern ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
200 return $pattern ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
201 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
202
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
203 function constructUnlinkComment ( $file , $usage ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
204 $pattern = $this->getLocalizedCommentPattern ( $usage->gil_wiki ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
205
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
206 $c = $file->comment_text ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
207 if ( $usage->wiki != 'commonswiki' ) { # Point original comment links to Commons
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
208 $c = preg_replace ( '/\[\[([^|]+?)\]\]/' , '[[:c:\1|]]' , $c ) ; # Pointing to Commons (no pipe)
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
209 $c = preg_replace ( '/\[\[([^:].+?)\]\]/' , '[[:c:\1]]' , $c ) ; # Pointing to Commons (with pipe)
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
210 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
211
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
212 $pattern = preg_replace ( '/\$1/' , $file->log_title , $pattern ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
213 $pattern = preg_replace ( '/\$2/' , $file->log_user_text , $pattern ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
214 $pattern = preg_replace ( '/\$3/' , $c , $pattern ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
215 # print "\n$pattern\n" ; exit ( 0 ) ; // TESTING
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
216 return $pattern ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
217 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
218
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
219 function constructReplaceComment ( $params ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
220 $pattern = $this->getLocalizedCommentPattern ( $params['wiki'] , 'replace' ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
221
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
222 $c = $params['comment'] ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
223 if ( $params['wiki'] != 'commonswiki' ) { # Point original comment links to Commons
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
224 $c = preg_replace ( '/\[\[([^|]+?)\]\]/' , '[[:c:\1|]]' , $c ) ; # Pointing to Commons (no pipe)
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
225 $c = preg_replace ( '/\[\[([^:].+?)\]\]/' , '[[:c:\1]]' , $c ) ; # Pointing to Commons (with pipe)
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
226 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
227
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
228 $pattern = preg_replace ( '/\$1/' , $params['file'] , $pattern ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
229 $pattern = preg_replace ( '/\$2/' , $params['replace_with_file'] , $pattern ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
230 $pattern = preg_replace ( '/\$3/' , 'CommonsDelinker' , $pattern ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
231 $pattern = preg_replace ( '/\$4/' , $c , $pattern ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
232
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
233 if ( isset($params['user']) and $params['user'] != '' ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
234 $by = $this->getLocalizedCommentPattern ( $params['wiki'] , 'by' ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
235 $by = preg_replace ( '/\$1/' , $params['user'] , $by ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
236 $pattern .= ' ' . $by ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
237 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
238
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
239 return $pattern ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
240 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
241
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
242 function addUnlinkEvent ( $file , $usage , &$sqls ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
243 if ( !$this->canUnlinkFromNamespace ( $usage ) ) return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
244 if ( $this->hasLocalFile ( $usage->gil_wiki , $usage->gil_to ) ) return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
245
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
246 $page = $usage->gil_page_title ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
247 if ( $usage->gil_page_namespace != '' ) $page = $usage->gil_page_namespace . ":$page" ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
248 $params = array (
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
249 'action' => 'unlink' ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
250 'file' => $usage->gil_to ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
251 'wiki' => $usage->gil_wiki ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
252 'page' => $page ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
253 'namespace' => $usage->gil_page_namespace_id ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
254 'comment' => $this->constructUnlinkComment ( $file , $usage ) ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
255 'timestamp' => date ( 'YmdHis' ) ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
256 'log_id' => $file->log_id ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
257 'log_timestamp' => $file->log_timestamp ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
258 'done' => 0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
259 ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
260 # print_r ( $params ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
261
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
262 $s1 = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
263 $s2 = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
264 foreach ( $params AS $k => $v ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
265 $s1[] = $k ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
266 $s2[] = "'" . $this->getDBsafe($v) . "'" ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
267 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
268
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
269 $sql = "INSERT IGNORE INTO event (" . implode ( ',' , $s1 ) . ") VALUES (" . implode ( "," , $s2 ) . ")" ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
270 $sqls[] = $sql ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
271 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
272
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
273 function addUnlinkEvents ( $delink_files ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
274 $sqls = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
275 foreach ( $delink_files AS $file ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
276 foreach ( $file->usage AS $usage ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
277 $this->addUnlinkEvent ( $file , $usage , $sqls ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
278 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
279 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
280
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
281 $db = $this->getToolDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
282 foreach ( $sqls AS $sql ) $this->runQuery ( $db , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
283 $db->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
284 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
285
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
286 function getJSON4Q ( $e ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
287 $q = $e->page ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
288 $url = "http://www.wikidata.org/w/api.php?action=wbgetentities&format=json&ids=" . $q ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
289 $j = json_decode ( file_get_contents ( $url ) ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
290 if ( isset ( $j->entities->$q->missing ) ) { # No such item
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
291 $this->setDone ( $e->id , 2 , "No such item $q" ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
292 return false ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
293 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
294 if ( !isset ( $j->entities->$q->claims ) ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
295 $this->setDone ( $e->id , 2 , "Did not find " . $e->file . " on " . $q ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
296 return false ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
297 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
298 return $j ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
299 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
300
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
301 function performEditUnlinkWikidata ( $e ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
302 $j = $this->getJSON4Q ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
303 if ( $j === false ) return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
304
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
305 $q = $e->page ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
306 $j = $j->entities->$q->claims ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
307 $remove = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
308 foreach ( $j AS $prop => $claims ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
309 foreach ( $claims AS $c ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
310 if ( $c->type != 'statement' ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
311 if ( $c->mainsnak->datatype != 'commonsMedia' ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
312 if ( str_replace ( ' ' , '_' , ucfirst ( trim ( $c->mainsnak->datavalue->value ) ) ) != $e->file ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
313 $remove[] = $c->id ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
314 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
315 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
316
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
317 if ( count($remove) > 0 ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
318 $ok = $this->editWikidata ( 'wbremoveclaims' , array ( 'claim'=>implode('|',$remove) , 'summary' => $e->comment ) ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
319 if ( !$ok ) return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
320 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
321
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
322 $this->setDone ( $e->id , 1 ) ; # OK!
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
323 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
324
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
325
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
326 function performEditReplaceWikidata ( $e ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
327 $j = $this->getJSON4Q ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
328 if ( $j === false ) return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
329
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
330 $q = $e->page ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
331
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
332 $j = $j->entities->$q->claims ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
333 $remove = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
334 foreach ( $j AS $prop => $claims ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
335 foreach ( $claims AS $c ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
336 if ( $c->type != 'statement' ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
337 if ( $c->mainsnak->datatype != 'commonsMedia' ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
338 if ( str_replace ( ' ' , '_' , ucfirst ( trim ( $c->mainsnak->datavalue->value ) ) ) != $e->file ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
339 $remove[] = array ( $c->id , $prop ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
340 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
341 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
342
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
343 if ( count($remove) > 0 ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
344
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
345 # Remove old image entries
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
346 $ids = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
347 foreach ( $remove AS $r ) $ids[] = $r[0] ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
348 $ok = $this->editWikidata ( 'wbremoveclaims' , array ( 'claim'=>implode('|',$ids) ) ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
349 if ( !$ok ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
350 $this->d->error("performEditReplaceWikidata:1 failed");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
351 return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
352 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
353
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
354 # Add new image entries
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
355 foreach ( $remove AS $r ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
356 $params = array(
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
357 'snaktype' => 'value' ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
358 'property' => $r[1] ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
359 'value' => json_encode(str_replace('_',' ',$e->replace_with_file)) ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
360 'entity' => $e->page ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
361 'summary' => $e->comment
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
362 ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
363
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
364 $ok = $this->editWikidata ( 'wbcreateclaim' , $params ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
365 if ( !$ok ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
366 $this->d->error( "performEditReplaceWikidata:2 failed" );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
367 return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
368 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
369
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
370 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
371 } else {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
372 $this->setDone ( $e->id , 2 , 'File link not found in page' ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
373 return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
374 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
375
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
376 $this->setDone ( $e->id , 1 ) ; # OK!
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
377 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
378
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
379
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
380 ##################################################################
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
381 ##
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
382 ## Here we make the changes.
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
383 ## Get the page, replace content and upload again.
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
384 ##
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
385 ##################################################################
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
386 function performEditText ( $e ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
387 $this->d->debug( "performEditText $e->action on id=$e->id wiki=$e->wiki page=$e->page." );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
388 $api = $this->getAPI ( $e->wiki ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
389 if ( $api === false ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
390 $this->setDone ( $e->id , 2 , "Could not connect to API" ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
391 return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
392 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
393 $services = new \Mediawiki\Api\MediawikiFactory( $api );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
394 try {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
395 $page = $services->newPageGetter()->getFromTitle( $e->page );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
396 } catch (Exception $ex) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
397 $this->setDone ( $e->id , 2 , "Page not found" ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
398 $this->d->debug("Page '$e->page' not found ($ex), id='$e->id' wiki=$e->wiki file=$e->file action=$e->action");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
399 return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
400 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
401 $revision = $page->getRevisions()->getLatest();
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
402
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
403 if ( !$revision ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
404 $this->setDone ( $e->id , 2 , "Latest revision not found" ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
405 return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
406 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
407
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
408 $rev_id = $revision->getId() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
409 $text = $revision->getContent()->getData() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
410
8
38415be9f910 Skipping {{nobots}} pages
Peter Gervai <grin@grin.hu>
parents: 6
diff changeset
411 if ( $this->isForbiddenPage( $text ) ) {
38415be9f910 Skipping {{nobots}} pages
Peter Gervai <grin@grin.hu>
parents: 6
diff changeset
412 $this->d->info("Skipping forbidden (nobots) page $e->wiki: $e->page");
38415be9f910 Skipping {{nobots}} pages
Peter Gervai <grin@grin.hu>
parents: 6
diff changeset
413 $this->setDone( $e->id, 2, "Change forbidden (nobots)" );
38415be9f910 Skipping {{nobots}} pages
Peter Gervai <grin@grin.hu>
parents: 6
diff changeset
414 return;
38415be9f910 Skipping {{nobots}} pages
Peter Gervai <grin@grin.hu>
parents: 6
diff changeset
415 }
38415be9f910 Skipping {{nobots}} pages
Peter Gervai <grin@grin.hu>
parents: 6
diff changeset
416
0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
417 $file = $e->file ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
418 $pattern = $this->matcher->matcher_prepare_pattern( $file );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
419
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
420 $new_text = $text ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
421
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
422 if ( $e->action == 'unlink' ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
423 ## remove image references in text; see ./matcher.inc
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
424 $this->d->info("Try to unlink '$pattern' in $e->wiki: $e->page");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
425 $new_text = $this->matcher->matcher_do_unlink( $new_text, $pattern );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
426
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
427 } else if ( $e->action == 'replace' ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
428 ## replace image with new_file in text; see ./matcher.inc
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
429 $new_file = $e->replace_with_file;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
430 $this->d->info("Try to replace '$pattern' with '$new_file' in $e->wiki: $e->page");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
431 $new_text = $this->matcher->matcher_do_replacement( $new_text, $pattern, $new_file );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
432 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
433
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
434 if ( $text == $new_text ) { # No change
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
435 $this->setDone ( $e->id , 2 , 'File link not found in page' ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
436 $this->d->info( "Article unchanged. id=$e->id; $e->wiki: $e->page" );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
437 return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
438 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
439
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
440 if ( strlen(trim($new_text)) == 0 or abs(strlen($text)-strlen($new_text)) > $this->max_text_diff ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
441 $this->setDone ( $e->id , 2 , 'Text change too big' ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
442 $this->d->warn( "Article text change is too big. id=$e->id; $e->wiki: $e->page" );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
443 return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
444 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
445
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
446 if ( !isset($e->comment) ) $e->comment = '' ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
447 $e->comment = (string)$e->comment ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
448
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
449 $this->d->info( "Editing $e->wiki: $e->page to $e->action $e->file (w/ $new_file) AS $e->comment") ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
450
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
451 $params = array (
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
452 'title' => $e->page ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
453 'text' => trim($new_text) ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
454 'summary' => $e->comment ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
455 'bot' => 1
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
456 ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
457
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
458 $x = $this->editWiki ( $e->wiki , 'edit' , $params ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
459 if ( $x and $x['edit']['result'] == 'Success' ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
460 $this->setDone ( $e->id , 1 , array('revision'=>$rev_id) ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
461 } else {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
462 $this->d->error( "Cannot edit wiki ($e->wiki: $e->page): " . $this->last_exception );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
463 $this->setDone ( $e->id , 2 , $this->last_exception ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
464 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
465
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
466 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
467
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
468 function performEditReplace ( $e ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
469 if ( !$this->fileExistenceSanityCheck($e,false) ) return ; # Nothing to do
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
470 if ( !isset($e->namespace) ) return ; # Paranoia
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
471 if ( $e->wiki == 'wikidatawiki' && $e->namespace == 0 ) { # Wikidata item
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
472 $this->performEditReplaceWikidata ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
473 } else { # "Normal" edit
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
474 $this->performEditText ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
475 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
476 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
477
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
478 function performEditUnlink ( $e ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
479 if ( !$this->fileExistenceSanityCheck($e,true) ) return ; # Nothing to do
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
480 if ( $e->wiki == 'wikidatawiki' && $e->namespace == 0 ) { # Wikidata item
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
481 $this->performEditUnlinkWikidata ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
482 } else { # "Normal" edit
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
483 $this->d->debug( "performEditUnlink $e->action on id=$e->id wiki=$e->wiki page=$e->page." );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
484 $this->performEditText ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
485 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
486 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
487
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
488 function performEdit ( $e ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
489 $this->d->debug( "performEdit $e->action on id=$e->id wiki=$e->wiki page=$e->page." );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
490 if ( $e->action == 'unlink' ) $this->performEditUnlink ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
491 else if ( $e->action == 'replace' ) $this->performEditReplace ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
492 else {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
493 $this->d->error( "PerformEdit got unknown action $e->action" );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
494 print_r ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
495 die ( "Unknown action " . $e->action ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
496 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
497 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
498
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
499 function clearBogusIssues ( $db ) {
6
8b4e205ffc94 demon.php: ease some db pressure by not querying old entries (7 days).
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
500
8b4e205ffc94 demon.php: ease some db pressure by not querying old entries (7 days).
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
501 $ts = date ( 'YmdHis' , time() - 60*60*24*7 ); # look back 7 days only
8b4e205ffc94 demon.php: ease some db pressure by not querying old entries (7 days).
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
502
0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
503 # Clear some previous issues
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
504 // 0=pending
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
505 // 1=done
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
506 // 2=skipped
6
8b4e205ffc94 demon.php: ease some db pressure by not querying old entries (7 days).
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
507 $sql = "update `event` set done=0,note='' where note like '%rate limit%' and done=2 and timestamp>'$ts'" ;
0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
508 $this->d->debug("Set done=0 (pending) on 'rate limit' events where done=2(skipped)");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
509 $this->runQuery ( $db , $sql ) ;
6
8b4e205ffc94 demon.php: ease some db pressure by not querying old entries (7 days).
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
510 $sql = "update `event` set done=0,note='' where note like '%edit conflict%' and done=2 and timestamp>'$ts'" ;
0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
511 $this->d->debug("Set done=0 (pending) on 'edit conflict' events where done=2(skipped)");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
512 $this->runQuery ( $db , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
513 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
514
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
515 function performEdits () {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
516 $edits = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
517 $this->d->debug("Connecting to DB");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
518 $db = $this->getToolDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
519 ## this is slow, let's do it at the end
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
520 // $this->d->debug("Clear bogus issues (reactivate rate limit/edit conflict skipped issues)");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
521 // $this->clearBogusIssues ( $db ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
522 $this->d->debug("Get work events (pending events)");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
523 $sql = "SELECT * FROM `event` WHERE done=0 ORDER BY timestamp ASC,log_timestamp ASC" ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
524 $result = $this->runQuery ( $db , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
525 while($o = $result->fetch_object()){
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
526 $edits[] = $o ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
527 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
528 $db->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
529
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
530 $last_wiki = '' ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
531 foreach ( $edits AS $o ) {
3
24d8f83459b3 demon.php: Add API debug output, lower speel delay
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
532 if ( $last_wiki == $o->wiki ) sleep ( 2 ) ; // Edit rate limiter
0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
533 $this->d->debug("Perform an edit in $o->wiki");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
534 try {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
535 $this->performEdit ( $o ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
536 } catch (Exception $e) {
6
8b4e205ffc94 demon.php: ease some db pressure by not querying old entries (7 days).
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
537 echo 'Caught exception: ', $e->getMessage(), "\n";
0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
538 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
539 $last_wiki = $o->wiki ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
540 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
541
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
542 $this->d->debug("Connecting to DB");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
543 $db = $this->getToolDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
544 $this->d->debug("Clear bogus issues (reactivate rate limit/edit conflict skipped issues)");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
545 $this->clearBogusIssues ( $db ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
546 $db->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
547 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
548
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
549 function addReplaceEvents () {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
550 $cmd_page = 'User:CommonsDelinker/commands' ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
551 $this->d->trace("getText from User:CommonsDelinker/commands");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
552 $t = $this->getTextFromWiki ( 'commonswiki' , $cmd_page ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
553 if ( $t === false ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
554 $this->d->error( "Could not open commands page") ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
555 return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
556 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
557
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
558 if ( preg_match ( '/\{\{[Ss]top\}\}/' , $t ) ) return ; // STOP
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
559
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
560 $sqls = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
561
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
562 # $t = "{{/front}}\n{{universal replace|Overzicht - Hulst - 20118655 - RCE.jpg|Red Weaver Ant, Oecophylla smaragdina.jpg|reason=Testing}}" ; # TESTING
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
563
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
564 $this->d->trace("Processing page content...");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
565 $ts = date ( 'YmdHis' ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
566 $t = explode ( "\n" , $t ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
567 $nt = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
568 foreach ( $t AS $l ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
569 if ( !preg_match ( '/^\s*\{\{\s*[Uu]niversal[ _]replace\s*\|\s*(.+?)\s*\|\s*(.+?)\s*\|\s*reason\s*=\s*(\S.*?)\s*\}\}/' , $l , $m ) ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
570 if ( !preg_match ( '/^\s*\{\{\s*[Uu]niversal[ _]replace\s*\|\s*(.+?)\s*\|\s*(.+?)\s*\|\s*reason\s*=\s*(.+?)\s*\|\s*user\s*=\s*(\S.*?)\s*\}\}/' , $l , $m ) ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
571 $nt[] = $l ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
572 continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
573 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
574 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
575 $old_file = ucfirst(str_replace(' ','_',trim($m[1]))) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
576 $new_file = ucfirst(str_replace(' ','_',trim($m[2]))) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
577 $this->d->trace("Process line; old:$old_file new:$new_file.");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
578
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
579 $comment = trim($m[3]) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
580 $user = '' ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
581 if ( isset($m[4]) ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
582 $user = str_replace(' ','_',trim($m[4])) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
583 $user = preg_replace ( '/^\s*\[\[[^:]+(.+?)\s*(\||\]\]).*$/' , '$1' , $user ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
584 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
585
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
586 if ( !$this->hasLocalFile ( 'commonswiki' , $new_file ) ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
587 $nt[] = "No such replacement file: " . $l ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
588 continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
589 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
590
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
591 if ( !preg_match('/\.svg$/i',$old_file) and preg_match('/\.svg$/i',$new_file) ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
592 $nt[] = "Non-SVG to SVG replacement: " . $l ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
593 continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
594 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
595
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
596 $this->d->trace("Get file usage for $old_file");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
597 $usages = $this->getFileUsage ( $old_file ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
598 if( $usages[0] == "*OVERFLOW*" ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
599 $nt[] = "File is used on too many pages: " . $l;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
600 $this->d->info("Skipping file $old_file; high usage (>$this->maximum_file_usage_limit)!");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
601 continue;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
602 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
603
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
604 $this->d->trace("Get db handle for TooDB");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
605 $db = $this->getToolDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
606
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
607 $this->d->trace("Generate replaces...");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
608 foreach ( $usages AS $usage ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
609 $page = $usage->gil_page_title ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
610 if ( $usage->gil_page_namespace != '' ) $page = $usage->gil_page_namespace . ':' . $page ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
611 $params = array (
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
612 'action' => 'replace' ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
613 'file' => $old_file ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
614 'wiki' => $usage->gil_wiki ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
615 'page' => $page ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
616 'namespace' => $usage->gil_page_namespace_id ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
617 'timestamp' => $ts ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
618 'comment' => $comment ,
10
d80db6c7a442 demon: fake timestamp for replaces
Peter Gervai <grin@grin.hu>
parents: 9
diff changeset
619 'log_id' => substr($ts,0,10), # was: -1 (into unsigned field!); db has a unique on action+page+log_id, so fake it hard
0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
620 'log_timestamp' => $ts ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
621 'user' => $user ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
622 'done' => 0 ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
623 'replace_with_file' => $new_file
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
624 ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
625 $params['comment'] = $this->constructReplaceComment ( $params ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
626 // print_r ( $params ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
627
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
628 $s1 = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
629 $s2 = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
630 foreach ( $params AS $k => $v ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
631 $s1[] = $k ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
632 $s2[] = "'" . $this->getDBsafe($v) . "'" ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
633 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
634
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
635 $this->d->trace("Add SQL to sqls[] array, len=" . count($sqls));
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
636 $sql = "INSERT IGNORE INTO event (" . implode ( ',' , $s1 ) . ") VALUES (" . implode ( "," , $s2 ) . ")" ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
637 $sqls[] = $sql ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
638 $this->d->trace("SQL:$sql");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
639
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
640 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
641
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
642 $db->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
643
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
644 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
645
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
646 $t = implode ( "\n" , $t ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
647 $nt = implode ( "\n" , $nt ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
648 if ( $t == $nt ) return ; // No change
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
649
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
650 # Run SQL
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
651 $db = $this->getToolDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
652 foreach ( $sqls AS $sql ) $this->runQuery ( $db , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
653 $db->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
654
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
655 # Save new text to Wiki
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
656 $params = array (
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
657 'title' => $cmd_page ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
658 'text' => trim($nt) ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
659 'summary' => 'Removing replace commands, will be executed soon' ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
660 'bot' => 1
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
661 ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
662
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
663 $this->d->info( "Editing $cmd_page...") ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
664 $x = $this->editWiki ( 'commonswiki' , 'edit' , $params ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
665 $this->d->debug( "Editing $cmd_page done.") ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
666 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
667
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
668 function fixFauxTemplateReplacements () {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
669 $todo = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
670 $db = $this->getToolDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
671 $sql = "DELETE FROM event WHERE action='' and file=''" ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
672 $result = $this->runQuery ( $db , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
673 $sql = 'select file,wiki, count(*) as cnt,namespace from event where done=0 group by file,wiki,namespace having cnt>' . $this->min_faux_template_icon ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
674 $result = $this->runQuery ( $db , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
675 while($o = $result->fetch_object()){
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
676 $file = $this->getDBsafe ( $o->file ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
677 $wiki = $this->getDBsafe ( $o->wiki ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
678 $todo[] = "UPDATE event SET done=2,note='Likely template icon, skipping' WHERE file='$file' AND wiki='$wiki' AND namespace=" . $o->namespace ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
679 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
680 foreach ( $todo AS $sql ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
681 $this->runQuery ( $db , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
682 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
683 $db->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
684 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
685
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
686 // Unlinks deleted files
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
687 function run () {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
688 $this->d->debug("Get last timestamp");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
689 $max_ts = $this->getLastTimestamp() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
690 $this->d->debug("Get recent deleted files");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
691 $delink_files = $this->getRecentDeletedFiles ( $max_ts ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
692 $this->d->debug("Add unlink events for recently deleted files");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
693 $this->addUnlinkEvents ( $delink_files ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
694 $this->d->debug("Add replace events");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
695 $this->addReplaceEvents () ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
696 $this->d->debug("Fix bogus template replacements");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
697 $this->fixFauxTemplateReplacements() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
698 $this->d->debug("Perform the queued edits");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
699 $this->performEdits() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
700 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
701
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
702 function debug_run0() {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
703 $this->d->debug("Add replace events");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
704 $this->addReplaceEvents () ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
705
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
706 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
707
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
708 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
709
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
710 print "Bot is starting.\n";
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
711 $demon = new CommonsDelinquentDemon ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
712
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
713 //$demon->addReplaceEvents () ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
714 //$demon->performEdits() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
715 //$demon->fixFauxTemplateReplacements() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
716
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
717 $demon->set_debug_mode(8);
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
718
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
719 // test
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
720 # $demon->debug_run0();
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
721 //\\\\\\
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
722
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
723 $demon->debug("Performing edits...");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
724 $demon->performEdits() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
725 while ( 1 ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
726 $demon->debug("Calling run loop...");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
727 $demon->run() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
728 $demon->debug("Sleeping 30...");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
729 sleep ( 30 ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
730 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
731
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
732 ?>

mercurial