delinquent_files/demon.php

Sat, 17 Feb 2024 15:36:09 +0100

author
Peter Gervai <grin@grin.hu>
date
Sat, 17 Feb 2024 15:36:09 +0100
changeset 6
8b4e205ffc94
parent 3
24d8f83459b3
child 8
38415be9f910
permissions
-rwxr-xr-x

demon.php: ease some db pressure by not querying old entries (7 days).
- replaced some rejects workaround by exclusions
- some moar debug msgs

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 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
83
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
84 function getRecentDeletedFiles ( $max_ts ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
85 # Open Commons database replica
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
86 $db_co = $this->getCommonsDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
87 $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
88
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
89 # Get all file deletions
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
90 $delink_files = array() ; # Files to delink
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
91 $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
92 $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
93 $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
94 $sql .= " ORDER BY log_timestamp ASC" ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
95 $result = $this->runQuery ( $db_co , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
96 while($o = $result->fetch_object()){
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
97 $delink_files[] = $o ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
98 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
99 foreach ( $delink_files AS $deletion ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
100 $filename = $deletion->log_title ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
101 $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
102 $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
103 $result = $this->runQuery ( $db_co , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
104 while($o = $result->fetch_object()){
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
105 if ( $this->isBadWiki($o->gil_wiki) ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
106 if ( $this->isBadPage($o,$filename) ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
107 $deletion->usage[] = $o ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
108 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
109 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
110 $db_co->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
111 // print_r ( $delink_files ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
112 return $delink_files ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
113 }
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 function getFileUsage ( $filename ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
116 $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
117 $ret = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
118 $db_co = $this->getCommonsDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
119 $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
120 $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
121 $this->d->trace("Try running: $sql");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
122 $result = $this->runQuery ( $db_co , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
123 $this->d->trace("Got result, looping through");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
124 while($o = $result->fetch_object()){
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
125 if ( $this->isBadWiki($o->gil_wiki) ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
126 $ret[] = $o ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
127 // $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
128 # 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
129 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
130 $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
131 $ret = array();
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
132 $ret[] = "*OVERFLOW*";
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
133 $db_co->close();
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
134 return $ret;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
135 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
136 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
137 $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
138 $db_co->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
139 return $ret ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
140 }
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 function canUnlinkFromNamespace ( $usage ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
143 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
144 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
145 return true ;
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 fileExistenceSanityCheck ( $e , $check_commons ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
149 if ( $this->hasLocalFile ( $e->wiki , $e->file ) ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
150 $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
151 return false ;
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 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
154 $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
155 return false ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
156 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
157 return true ;
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
160
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
161 function getTextFromWiki ( $wiki , $pagename ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
162 $ret = false ;
3
24d8f83459b3 demon.php: Add API debug output, lower speel delay
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
163 $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
164 // 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
165 //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
166 // 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
167 //}
0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
168 $api = $this->getAPI ( $wiki ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
169 if ( $api ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
170 $services = new \Mediawiki\Api\MediawikiFactory( $api );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
171 $page = $services->newPageGetter()->getFromTitle( $pagename );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
172 $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
173
0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
174 if ( $revision ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
175 $ret = $revision->getContent()->getData() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
176 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
177 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
178 return $ret ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
179 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
180
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
181 /**
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
182 mode "summary" or "replace"
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 function getLocalizedCommentPattern ( $wiki , $mode = 'summary') {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
185 if ( !isset($mode) ) $mode = 'summary' ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
186 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
187 $pattern = $this->comments_default[$mode] ; # Default
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
188
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
189 # Try local translation
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
190 $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
191 if ( $local !== false ) $pattern = $local ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
192
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
193 $this->comments[$mode][$wiki] = $pattern ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
194 return $pattern ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
195 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
196
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
197 function constructUnlinkComment ( $file , $usage ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
198 $pattern = $this->getLocalizedCommentPattern ( $usage->gil_wiki ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
199
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
200 $c = $file->comment_text ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
201 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
202 $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
203 $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
204 }
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 $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
207 $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
208 $pattern = preg_replace ( '/\$3/' , $c , $pattern ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
209 # print "\n$pattern\n" ; exit ( 0 ) ; // TESTING
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
210 return $pattern ;
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
213 function constructReplaceComment ( $params ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
214 $pattern = $this->getLocalizedCommentPattern ( $params['wiki'] , 'replace' ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
215
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
216 $c = $params['comment'] ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
217 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
218 $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
219 $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
220 }
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 $pattern = preg_replace ( '/\$1/' , $params['file'] , $pattern ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
223 $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
224 $pattern = preg_replace ( '/\$3/' , 'CommonsDelinker' , $pattern ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
225 $pattern = preg_replace ( '/\$4/' , $c , $pattern ) ;
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 if ( isset($params['user']) and $params['user'] != '' ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
228 $by = $this->getLocalizedCommentPattern ( $params['wiki'] , 'by' ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
229 $by = preg_replace ( '/\$1/' , $params['user'] , $by ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
230 $pattern .= ' ' . $by ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
231 }
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 return $pattern ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
234 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
235
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
236 function addUnlinkEvent ( $file , $usage , &$sqls ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
237 if ( !$this->canUnlinkFromNamespace ( $usage ) ) return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
238 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
239
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
240 $page = $usage->gil_page_title ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
241 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
242 $params = array (
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
243 'action' => 'unlink' ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
244 'file' => $usage->gil_to ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
245 'wiki' => $usage->gil_wiki ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
246 'page' => $page ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
247 'namespace' => $usage->gil_page_namespace_id ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
248 'comment' => $this->constructUnlinkComment ( $file , $usage ) ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
249 'timestamp' => date ( 'YmdHis' ) ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
250 'log_id' => $file->log_id ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
251 'log_timestamp' => $file->log_timestamp ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
252 'done' => 0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
253 ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
254 # print_r ( $params ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
255
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
256 $s1 = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
257 $s2 = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
258 foreach ( $params AS $k => $v ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
259 $s1[] = $k ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
260 $s2[] = "'" . $this->getDBsafe($v) . "'" ;
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
263 $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
264 $sqls[] = $sql ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
265 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
266
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
267 function addUnlinkEvents ( $delink_files ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
268 $sqls = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
269 foreach ( $delink_files AS $file ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
270 foreach ( $file->usage AS $usage ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
271 $this->addUnlinkEvent ( $file , $usage , $sqls ) ;
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 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
274
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
275 $db = $this->getToolDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
276 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
277 $db->close() ;
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 function getJSON4Q ( $e ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
281 $q = $e->page ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
282 $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
283 $j = json_decode ( file_get_contents ( $url ) ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
284 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
285 $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
286 return false ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
287 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
288 if ( !isset ( $j->entities->$q->claims ) ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
289 $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
290 return false ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
291 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
292 return $j ;
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
295 function performEditUnlinkWikidata ( $e ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
296 $j = $this->getJSON4Q ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
297 if ( $j === false ) return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
298
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
299 $q = $e->page ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
300 $j = $j->entities->$q->claims ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
301 $remove = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
302 foreach ( $j AS $prop => $claims ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
303 foreach ( $claims AS $c ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
304 if ( $c->type != 'statement' ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
305 if ( $c->mainsnak->datatype != 'commonsMedia' ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
306 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
307 $remove[] = $c->id ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
308 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
309 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
310
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
311 if ( count($remove) > 0 ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
312 $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
313 if ( !$ok ) return ;
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 $this->setDone ( $e->id , 1 ) ; # OK!
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
317 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
318
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
319
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
320 function performEditReplaceWikidata ( $e ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
321 $j = $this->getJSON4Q ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
322 if ( $j === false ) return ;
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 $q = $e->page ;
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 $j = $j->entities->$q->claims ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
327 $remove = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
328 foreach ( $j AS $prop => $claims ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
329 foreach ( $claims AS $c ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
330 if ( $c->type != 'statement' ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
331 if ( $c->mainsnak->datatype != 'commonsMedia' ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
332 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
333 $remove[] = array ( $c->id , $prop ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
334 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
335 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
336
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
337 if ( count($remove) > 0 ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
338
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
339 # Remove old image entries
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
340 $ids = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
341 foreach ( $remove AS $r ) $ids[] = $r[0] ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
342 $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
343 if ( !$ok ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
344 $this->d->error("performEditReplaceWikidata:1 failed");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
345 return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
346 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
347
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
348 # Add new image entries
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
349 foreach ( $remove AS $r ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
350 $params = array(
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
351 'snaktype' => 'value' ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
352 'property' => $r[1] ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
353 '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
354 'entity' => $e->page ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
355 'summary' => $e->comment
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
356 ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
357
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
358 $ok = $this->editWikidata ( 'wbcreateclaim' , $params ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
359 if ( !$ok ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
360 $this->d->error( "performEditReplaceWikidata:2 failed" );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
361 return ;
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 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
365 } else {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
366 $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
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 $this->setDone ( $e->id , 1 ) ; # OK!
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
371 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
372
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
373
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 ## Here we make the changes.
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
377 ## 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
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 function performEditText ( $e ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
381 $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
382 $api = $this->getAPI ( $e->wiki ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
383 if ( $api === false ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
384 $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
385 return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
386 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
387 $services = new \Mediawiki\Api\MediawikiFactory( $api );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
388 try {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
389 $page = $services->newPageGetter()->getFromTitle( $e->page );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
390 } catch (Exception $ex) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
391 $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
392 $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
393 return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
394 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
395 $revision = $page->getRevisions()->getLatest();
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
396
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
397 if ( !$revision ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
398 $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
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
402 $rev_id = $revision->getId() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
403 $text = $revision->getContent()->getData() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
404
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
405 $file = $e->file ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
406 $pattern = $this->matcher->matcher_prepare_pattern( $file );
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 $new_text = $text ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
409
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
410 if ( $e->action == 'unlink' ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
411 ## 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
412 $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
413 $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
414
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
415 } else if ( $e->action == 'replace' ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
416 ## 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
417 $new_file = $e->replace_with_file;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
418 $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
419 $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
420 }
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 ( $text == $new_text ) { # No change
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
423 $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
424 $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
425 return ;
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
428 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
429 $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
430 $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
431 return ;
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 ( !isset($e->comment) ) $e->comment = '' ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
435 $e->comment = (string)$e->comment ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
436
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
437 $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
438
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
439 $params = array (
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
440 'title' => $e->page ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
441 'text' => trim($new_text) ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
442 'summary' => $e->comment ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
443 'bot' => 1
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 $x = $this->editWiki ( $e->wiki , 'edit' , $params ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
447 if ( $x and $x['edit']['result'] == 'Success' ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
448 $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
449 } else {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
450 $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
451 $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
452 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
453
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
454 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
455
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
456 function performEditReplace ( $e ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
457 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
458 if ( !isset($e->namespace) ) return ; # Paranoia
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
459 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
460 $this->performEditReplaceWikidata ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
461 } else { # "Normal" edit
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
462 $this->performEditText ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
463 }
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 function performEditUnlink ( $e ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
467 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
468 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
469 $this->performEditUnlinkWikidata ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
470 } else { # "Normal" edit
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
471 $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
472 $this->performEditText ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
473 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
474 }
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 function performEdit ( $e ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
477 $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
478 if ( $e->action == 'unlink' ) $this->performEditUnlink ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
479 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
480 else {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
481 $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
482 print_r ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
483 die ( "Unknown action " . $e->action ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
484 }
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 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
488
8b4e205ffc94 demon.php: ease some db pressure by not querying old entries (7 days).
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
489 $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
490
0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
491 # Clear some previous issues
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
492 // 0=pending
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
493 // 1=done
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
494 // 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
495 $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
496 $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
497 $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
498 $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
499 $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
500 $this->runQuery ( $db , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
501 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
502
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
503 function performEdits () {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
504 $edits = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
505 $this->d->debug("Connecting to DB");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
506 $db = $this->getToolDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
507 ## 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
508 // $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
509 // $this->clearBogusIssues ( $db ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
510 $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
511 $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
512 $result = $this->runQuery ( $db , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
513 while($o = $result->fetch_object()){
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
514 $edits[] = $o ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
515 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
516 $db->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
517
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
518 $last_wiki = '' ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
519 foreach ( $edits AS $o ) {
3
24d8f83459b3 demon.php: Add API debug output, lower speel delay
Peter Gervai <grin@grin.hu>
parents: 2
diff changeset
520 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
521 $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
522 try {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
523 $this->performEdit ( $o ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
524 } 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
525 echo 'Caught exception: ', $e->getMessage(), "\n";
0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
526 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
527 $last_wiki = $o->wiki ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
528 }
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 $this->d->debug("Connecting to DB");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
531 $db = $this->getToolDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
532 $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
533 $this->clearBogusIssues ( $db ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
534 $db->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
535 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
536
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
537 function addReplaceEvents () {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
538 $cmd_page = 'User:CommonsDelinker/commands' ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
539 $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
540 $t = $this->getTextFromWiki ( 'commonswiki' , $cmd_page ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
541 if ( $t === false ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
542 $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
543 return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
544 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
545
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
546 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
547
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
548 $sqls = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
549
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
550 # $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
551
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
552 $this->d->trace("Processing page content...");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
553 $ts = date ( 'YmdHis' ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
554 $t = explode ( "\n" , $t ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
555 $nt = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
556 foreach ( $t AS $l ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
557 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
558 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
559 $nt[] = $l ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
560 continue ;
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 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
563 $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
564 $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
565 $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
566
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
567 $comment = trim($m[3]) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
568 $user = '' ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
569 if ( isset($m[4]) ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
570 $user = str_replace(' ','_',trim($m[4])) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
571 $user = preg_replace ( '/^\s*\[\[[^:]+(.+?)\s*(\||\]\]).*$/' , '$1' , $user ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
572 }
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 if ( !$this->hasLocalFile ( 'commonswiki' , $new_file ) ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
575 $nt[] = "No such replacement file: " . $l ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
576 continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
577 }
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 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
580 $nt[] = "Non-SVG to SVG replacement: " . $l ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
581 continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
582 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
583
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
584 $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
585 $usages = $this->getFileUsage ( $old_file ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
586 if( $usages[0] == "*OVERFLOW*" ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
587 $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
588 $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
589 continue;
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
592 $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
593 $db = $this->getToolDB() ;
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 $this->d->trace("Generate replaces...");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
596 foreach ( $usages AS $usage ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
597 $page = $usage->gil_page_title ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
598 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
599 $params = array (
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
600 'action' => 'replace' ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
601 'file' => $old_file ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
602 'wiki' => $usage->gil_wiki ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
603 'page' => $page ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
604 'namespace' => $usage->gil_page_namespace_id ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
605 'timestamp' => $ts ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
606 'comment' => $comment ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
607 'log_id' => -1 ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
608 'log_timestamp' => $ts ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
609 'user' => $user ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
610 'done' => 0 ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
611 'replace_with_file' => $new_file
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
612 ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
613 $params['comment'] = $this->constructReplaceComment ( $params ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
614 // print_r ( $params ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
615
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
616 $s1 = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
617 $s2 = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
618 foreach ( $params AS $k => $v ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
619 $s1[] = $k ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
620 $s2[] = "'" . $this->getDBsafe($v) . "'" ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
621 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
622
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
623 $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
624 $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
625 $sqls[] = $sql ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
626 $this->d->trace("SQL:$sql");
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 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
629
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
630 $db->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
631
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
632 }
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 $t = implode ( "\n" , $t ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
635 $nt = implode ( "\n" , $nt ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
636 if ( $t == $nt ) return ; // No change
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
637
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
638 # Run SQL
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
639 $db = $this->getToolDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
640 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
641 $db->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
642
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
643 # Save new text to Wiki
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
644 $params = array (
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
645 'title' => $cmd_page ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
646 'text' => trim($nt) ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
647 '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
648 'bot' => 1
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
651 $this->d->info( "Editing $cmd_page...") ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
652 $x = $this->editWiki ( 'commonswiki' , 'edit' , $params ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
653 $this->d->debug( "Editing $cmd_page done.") ;
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
656 function fixFauxTemplateReplacements () {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
657 $todo = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
658 $db = $this->getToolDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
659 $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
660 $result = $this->runQuery ( $db , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
661 $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
662 $result = $this->runQuery ( $db , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
663 while($o = $result->fetch_object()){
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
664 $file = $this->getDBsafe ( $o->file ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
665 $wiki = $this->getDBsafe ( $o->wiki ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
666 $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
667 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
668 foreach ( $todo AS $sql ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
669 $this->runQuery ( $db , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
670 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
671 $db->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
672 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
673
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
674 // Unlinks deleted files
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
675 function run () {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
676 $this->d->debug("Get last timestamp");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
677 $max_ts = $this->getLastTimestamp() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
678 $this->d->debug("Get recent deleted files");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
679 $delink_files = $this->getRecentDeletedFiles ( $max_ts ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
680 $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
681 $this->addUnlinkEvents ( $delink_files ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
682 $this->d->debug("Add replace events");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
683 $this->addReplaceEvents () ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
684 $this->d->debug("Fix bogus template replacements");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
685 $this->fixFauxTemplateReplacements() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
686 $this->d->debug("Perform the queued edits");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
687 $this->performEdits() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
688 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
689
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
690 function debug_run0() {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
691 $this->d->debug("Add replace events");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
692 $this->addReplaceEvents () ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
693
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
694 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
695
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
696 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
697
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
698 print "Bot is starting.\n";
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
699 $demon = new CommonsDelinquentDemon ;
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 //$demon->addReplaceEvents () ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
702 //$demon->performEdits() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
703 //$demon->fixFauxTemplateReplacements() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
704
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
705 $demon->set_debug_mode(8);
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 // test
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
708 # $demon->debug_run0();
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
711 $demon->debug("Performing edits...");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
712 $demon->performEdits() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
713 while ( 1 ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
714 $demon->debug("Calling run loop...");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
715 $demon->run() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
716 $demon->debug("Sleeping 30...");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
717 sleep ( 30 ) ;
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
720 ?>

mercurial