delinquent_files/demon.php

Mon, 23 Jan 2023 21:42:29 +0100

author
Peter Gervai <grin@grin.hu>
date
Mon, 23 Jan 2023 21:42:29 +0100
changeset 2
cd58c0bc21d6
parent 0
3b714bbb1347
child 3
24d8f83459b3
permissions
-rwxr-xr-x

Add Id for trackable files.

0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
1 #!/usr/bin/php
2
cd58c0bc21d6 Add Id for trackable files.
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
2 # $Id$
cd58c0bc21d6 Add Id for trackable files.
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
3 #
cd58c0bc21d6 Add Id for trackable files.
Peter Gervai <grin@grin.hu>
parents: 0
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
7 chdir ( '/data/project/commons-delinquent' ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
8
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
9 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
10 ini_set('display_errors', 'On');
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
11
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
12 require_once ( './shared.inc' ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
13 require_once( './matcher.inc' );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
14 require_once( './debug.inc' );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
15
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
16 class CommonsDelinquentDemon extends CommonsDelinquent {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
17
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
18 var $avoidNamespaceOnWiki = [
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
19 'dewiki' => [4]
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
22 private $d;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
23 private $matcher;
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 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
26 var $delay_minutes = 10 ; # Wait after deletion
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
27 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
28 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
29 var $min_faux_template_icon = 500 ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
30 var $comments = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
31 var $comments_default = array (
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
32 '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
33 '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
34 'by' => ' Requested by [[User:$1|]].'
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
35 ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
36
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
37 function __construct() {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
38 parent::__construct();
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
39 $this->d = new Debug;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
40 $this->matcher = new Matcher($this->d);
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
41 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
42
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
43 function set_debug_mode($l) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
44 $this->d->set_level( $l );
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
47 function debug($msg) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
48 $this->d->debug($msg);
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
51 // 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
52 function getLastTimestamp () {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
53 # Open tool database
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
54 $db = $this->getToolDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
55
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
56 # 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
57 $max_ts = '' ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
58 $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
59 $result = $this->runQuery ( $db , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
60 while($o = $result->fetch_object()){
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
61 $max_ts = $o->max_ts ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
62 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
63 $db->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
64 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
65 return $max_ts ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
66 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
67
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
68 function isBadPage ( $o , $filename ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
69 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
70 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
71 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
72 foreach ( $this->avoidNamespaceOnWiki AS $wiki => $namespaces ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
73 if ( $o->gil_wiki != $wiki ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
74 foreach ( $namespaces AS $namespace ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
75 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
76 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
77 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
78 return false ;
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 function getRecentDeletedFiles ( $max_ts ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
82 # Open Commons database replica
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
83 $db_co = $this->getCommonsDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
84 $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
85
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
86 # Get all file deletions
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
87 $delink_files = array() ; # Files to delink
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
88 $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
89 $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
90 $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
91 $sql .= " ORDER BY log_timestamp ASC" ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
92 $result = $this->runQuery ( $db_co , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
93 while($o = $result->fetch_object()){
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
94 $delink_files[] = $o ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
95 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
96 foreach ( $delink_files AS $deletion ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
97 $filename = $deletion->log_title ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
98 $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
99 $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
100 $result = $this->runQuery ( $db_co , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
101 while($o = $result->fetch_object()){
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
102 if ( $this->isBadWiki($o->gil_wiki) ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
103 if ( $this->isBadPage($o,$filename) ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
104 $deletion->usage[] = $o ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
105 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
106 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
107 $db_co->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
108 // print_r ( $delink_files ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
109 return $delink_files ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
110 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
111
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
112 function getFileUsage ( $filename ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
113 $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
114 $ret = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
115 $db_co = $this->getCommonsDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
116 $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
117 $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
118 $this->d->trace("Try running: $sql");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
119 $result = $this->runQuery ( $db_co , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
120 $this->d->trace("Got result, looping through");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
121 while($o = $result->fetch_object()){
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
122 if ( $this->isBadWiki($o->gil_wiki) ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
123 $ret[] = $o ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
124 // $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
125 # 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
126 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
127 $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
128 $ret = array();
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
129 $ret[] = "*OVERFLOW*";
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
130 $db_co->close();
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
131 return $ret;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
132 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
133 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
134 $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
135 $db_co->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
136 return $ret ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
137 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
138
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
139 function canUnlinkFromNamespace ( $usage ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
140 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
141 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
142 return true ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
143 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
144
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
145 function fileExistenceSanityCheck ( $e , $check_commons ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
146 if ( $this->hasLocalFile ( $e->wiki , $e->file ) ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
147 $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
148 return false ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
149 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
150 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
151 $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
152 return false ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
153 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
154 return true ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
155 }
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
158 function getTextFromWiki ( $wiki , $pagename ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
159 $ret = false ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
160 $api = $this->getAPI ( $wiki ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
161 if ( $api ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
162 $services = new \Mediawiki\Api\MediawikiFactory( $api );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
163 $page = $services->newPageGetter()->getFromTitle( $pagename );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
164 $revision = $page->getRevisions()->getLatest();
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
165
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
166 if ( $revision ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
167 $ret = $revision->getContent()->getData() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
168 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
169 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
170 return $ret ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
171 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
172
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
173 /**
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
174 mode "summary" or "replace"
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
175 */
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
176 function getLocalizedCommentPattern ( $wiki , $mode = 'summary') {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
177 if ( !isset($mode) ) $mode = 'summary' ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
178 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
179 $pattern = $this->comments_default[$mode] ; # Default
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 # Try local translation
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
182 $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
183 if ( $local !== false ) $pattern = $local ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
184
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
185 $this->comments[$mode][$wiki] = $pattern ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
186 return $pattern ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
187 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
188
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
189 function constructUnlinkComment ( $file , $usage ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
190 $pattern = $this->getLocalizedCommentPattern ( $usage->gil_wiki ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
191
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
192 $c = $file->comment_text ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
193 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
194 $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
195 $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
196 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
197
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
198 $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
199 $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
200 $pattern = preg_replace ( '/\$3/' , $c , $pattern ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
201 # print "\n$pattern\n" ; exit ( 0 ) ; // TESTING
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
202 return $pattern ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
203 }
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 function constructReplaceComment ( $params ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
206 $pattern = $this->getLocalizedCommentPattern ( $params['wiki'] , 'replace' ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
207
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
208 $c = $params['comment'] ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
209 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
210 $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
211 $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
212 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
213
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
214 $pattern = preg_replace ( '/\$1/' , $params['file'] , $pattern ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
215 $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
216 $pattern = preg_replace ( '/\$3/' , 'CommonsDelinker' , $pattern ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
217 $pattern = preg_replace ( '/\$4/' , $c , $pattern ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
218
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
219 if ( isset($params['user']) and $params['user'] != '' ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
220 $by = $this->getLocalizedCommentPattern ( $params['wiki'] , 'by' ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
221 $by = preg_replace ( '/\$1/' , $params['user'] , $by ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
222 $pattern .= ' ' . $by ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
223 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
224
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
225 return $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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
228 function addUnlinkEvent ( $file , $usage , &$sqls ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
229 if ( !$this->canUnlinkFromNamespace ( $usage ) ) return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
230 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
231
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
232 $page = $usage->gil_page_title ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
233 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
234 $params = array (
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
235 'action' => 'unlink' ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
236 'file' => $usage->gil_to ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
237 'wiki' => $usage->gil_wiki ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
238 'page' => $page ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
239 'namespace' => $usage->gil_page_namespace_id ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
240 'comment' => $this->constructUnlinkComment ( $file , $usage ) ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
241 'timestamp' => date ( 'YmdHis' ) ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
242 'log_id' => $file->log_id ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
243 'log_timestamp' => $file->log_timestamp ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
244 'done' => 0
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
245 ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
246 # print_r ( $params ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
247
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
248 $s1 = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
249 $s2 = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
250 foreach ( $params AS $k => $v ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
251 $s1[] = $k ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
252 $s2[] = "'" . $this->getDBsafe($v) . "'" ;
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
255 $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
256 $sqls[] = $sql ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
257 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
258
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
259 function addUnlinkEvents ( $delink_files ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
260 $sqls = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
261 foreach ( $delink_files AS $file ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
262 foreach ( $file->usage AS $usage ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
263 $this->addUnlinkEvent ( $file , $usage , $sqls ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
264 }
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 $db = $this->getToolDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
268 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
269 $db->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
270 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
271
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
272 function getJSON4Q ( $e ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
273 $q = $e->page ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
274 $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
275 $j = json_decode ( file_get_contents ( $url ) ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
276 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
277 $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
278 return false ;
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 if ( !isset ( $j->entities->$q->claims ) ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
281 $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
282 return false ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
283 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
284 return $j ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
285 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
286
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
287 function performEditUnlinkWikidata ( $e ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
288 $j = $this->getJSON4Q ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
289 if ( $j === false ) return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
290
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
291 $q = $e->page ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
292 $j = $j->entities->$q->claims ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
293 $remove = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
294 foreach ( $j AS $prop => $claims ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
295 foreach ( $claims AS $c ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
296 if ( $c->type != 'statement' ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
297 if ( $c->mainsnak->datatype != 'commonsMedia' ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
298 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
299 $remove[] = $c->id ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
300 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
301 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
302
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
303 if ( count($remove) > 0 ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
304 $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
305 if ( !$ok ) return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
306 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
307
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
308 $this->setDone ( $e->id , 1 ) ; # OK!
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
312 function performEditReplaceWikidata ( $e ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
313 $j = $this->getJSON4Q ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
314 if ( $j === false ) return ;
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 $q = $e->page ;
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 $j = $j->entities->$q->claims ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
319 $remove = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
320 foreach ( $j AS $prop => $claims ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
321 foreach ( $claims AS $c ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
322 if ( $c->type != 'statement' ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
323 if ( $c->mainsnak->datatype != 'commonsMedia' ) continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
324 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
325 $remove[] = array ( $c->id , $prop ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
326 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
327 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
328
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
329 if ( count($remove) > 0 ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
330
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
331 # Remove old image entries
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
332 $ids = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
333 foreach ( $remove AS $r ) $ids[] = $r[0] ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
334 $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
335 if ( !$ok ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
336 $this->d->error("performEditReplaceWikidata:1 failed");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
337 return ;
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
340 # Add new image entries
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
341 foreach ( $remove AS $r ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
342 $params = array(
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
343 'snaktype' => 'value' ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
344 'property' => $r[1] ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
345 '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
346 'entity' => $e->page ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
347 'summary' => $e->comment
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
348 ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
349
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
350 $ok = $this->editWikidata ( 'wbcreateclaim' , $params ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
351 if ( !$ok ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
352 $this->d->error( "performEditReplaceWikidata:2 failed" );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
353 return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
354 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
355
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 } else {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
358 $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
359 return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
360 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
361
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
362 $this->setDone ( $e->id , 1 ) ; # OK!
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
366 ##################################################################
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
367 ##
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
368 ## Here we make the changes.
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
369 ## 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
370 ##
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 function performEditText ( $e ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
373 $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
374 $api = $this->getAPI ( $e->wiki ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
375 if ( $api === false ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
376 $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
377 return ;
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 $services = new \Mediawiki\Api\MediawikiFactory( $api );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
380 try {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
381 $page = $services->newPageGetter()->getFromTitle( $e->page );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
382 } catch (Exception $ex) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
383 $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
384 $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
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 $revision = $page->getRevisions()->getLatest();
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
388
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
389 if ( !$revision ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
390 $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
391 return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
392 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
393
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
394 $rev_id = $revision->getId() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
395 $text = $revision->getContent()->getData() ;
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 $file = $e->file ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
398 $pattern = $this->matcher->matcher_prepare_pattern( $file );
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
399
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
400 $new_text = $text ;
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 if ( $e->action == 'unlink' ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
403 ## 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
404 $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
405 $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
406
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
407 } else if ( $e->action == 'replace' ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
408 ## 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
409 $new_file = $e->replace_with_file;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
410 $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
411 $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
412 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
413
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
414 if ( $text == $new_text ) { # No change
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
415 $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
416 $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
417 return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
418 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
419
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
420 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
421 $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
422 $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
423 return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
424 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
425
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
426 if ( !isset($e->comment) ) $e->comment = '' ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
427 $e->comment = (string)$e->comment ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
428
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
429 $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
430
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
431 $params = array (
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
432 'title' => $e->page ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
433 'text' => trim($new_text) ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
434 'summary' => $e->comment ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
435 'bot' => 1
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
438 $x = $this->editWiki ( $e->wiki , 'edit' , $params ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
439 if ( $x and $x['edit']['result'] == 'Success' ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
440 $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
441 } else {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
442 $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
443 $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
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 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
447
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
448 function performEditReplace ( $e ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
449 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
450 if ( !isset($e->namespace) ) return ; # Paranoia
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
451 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
452 $this->performEditReplaceWikidata ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
453 } else { # "Normal" edit
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
454 $this->performEditText ( $e ) ;
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 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
457
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
458 function performEditUnlink ( $e ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
459 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
460 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
461 $this->performEditUnlinkWikidata ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
462 } else { # "Normal" edit
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
463 $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
464 $this->performEditText ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
465 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
466 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
467
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
468 function performEdit ( $e ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
469 $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
470 if ( $e->action == 'unlink' ) $this->performEditUnlink ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
471 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
472 else {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
473 $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
474 print_r ( $e ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
475 die ( "Unknown action " . $e->action ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
476 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
477 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
478
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
479 function clearBogusIssues ( $db ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
480 # Clear some previous issues
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
481 // 0=pending
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
482 // 1=done
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
483 // 2=skipped
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
484 $sql = "update `event` set done=0,note='' where note like '%rate limit%' and done=2" ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
485 $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
486 $this->runQuery ( $db , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
487 $sql = "update `event` set done=0,note='' where note like '%edit conflict%' and done=2" ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
488 $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
489 $this->runQuery ( $db , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
490 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
491
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
492 function performEdits () {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
493 $edits = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
494 $this->d->debug("Connecting to DB");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
495 $db = $this->getToolDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
496 ## 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
497 // $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
498 // $this->clearBogusIssues ( $db ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
499 $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
500 $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
501 $result = $this->runQuery ( $db , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
502 while($o = $result->fetch_object()){
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
503 $edits[] = $o ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
504 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
505 $db->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
506
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
507 $last_wiki = '' ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
508 foreach ( $edits AS $o ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
509 if ( $last_wiki == $o->wiki ) sleep ( 5 ) ; // Edit rate limiter
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
510 $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
511 try {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
512 $this->performEdit ( $o ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
513 } catch (Exception $e) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
514 echo 'Caught exception: ', $e->getMessage(), "\n";
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 $last_wiki = $o->wiki ;
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
519 $this->d->debug("Connecting to DB");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
520 $db = $this->getToolDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
521 $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
522 $this->clearBogusIssues ( $db ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
523 $db->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
524 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
525
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
526 function addReplaceEvents () {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
527 $cmd_page = 'User:CommonsDelinker/commands' ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
528 $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
529 $t = $this->getTextFromWiki ( 'commonswiki' , $cmd_page ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
530 if ( $t === false ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
531 $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
532 return ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
533 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
534
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
535 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
536
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
537 $sqls = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
538
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
539 # $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
540
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
541 $this->d->trace("Processing page content...");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
542 $ts = date ( 'YmdHis' ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
543 $t = explode ( "\n" , $t ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
544 $nt = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
545 foreach ( $t AS $l ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
546 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
547 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
548 $nt[] = $l ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
549 continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
550 }
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 $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
553 $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
554 $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
555
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
556 $comment = trim($m[3]) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
557 $user = '' ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
558 if ( isset($m[4]) ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
559 $user = str_replace(' ','_',trim($m[4])) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
560 $user = preg_replace ( '/^\s*\[\[[^:]+(.+?)\s*(\||\]\]).*$/' , '$1' , $user ) ;
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 if ( !$this->hasLocalFile ( 'commonswiki' , $new_file ) ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
564 $nt[] = "No such replacement file: " . $l ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
565 continue ;
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
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
568 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
569 $nt[] = "Non-SVG to SVG replacement: " . $l ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
570 continue ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
571 }
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 $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
574 $usages = $this->getFileUsage ( $old_file ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
575 if( $usages[0] == "*OVERFLOW*" ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
576 $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
577 $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
578 continue;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
579 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
580
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
581 $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
582 $db = $this->getToolDB() ;
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("Generate replaces...");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
585 foreach ( $usages AS $usage ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
586 $page = $usage->gil_page_title ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
587 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
588 $params = array (
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
589 'action' => 'replace' ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
590 'file' => $old_file ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
591 'wiki' => $usage->gil_wiki ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
592 'page' => $page ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
593 'namespace' => $usage->gil_page_namespace_id ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
594 'timestamp' => $ts ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
595 'comment' => $comment ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
596 'log_id' => -1 ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
597 'log_timestamp' => $ts ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
598 'user' => $user ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
599 'done' => 0 ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
600 'replace_with_file' => $new_file
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
601 ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
602 $params['comment'] = $this->constructReplaceComment ( $params ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
603 // print_r ( $params ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
604
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
605 $s1 = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
606 $s2 = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
607 foreach ( $params AS $k => $v ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
608 $s1[] = $k ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
609 $s2[] = "'" . $this->getDBsafe($v) . "'" ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
610 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
611
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
612 $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
613 $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
614 $sqls[] = $sql ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
615 $this->d->trace("SQL:$sql");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
616
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
617 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
618
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
619 $db->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
620
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 $t = implode ( "\n" , $t ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
624 $nt = implode ( "\n" , $nt ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
625 if ( $t == $nt ) return ; // No change
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
626
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
627 # Run SQL
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
628 $db = $this->getToolDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
629 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
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 # Save new text to Wiki
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
633 $params = array (
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
634 'title' => $cmd_page ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
635 'text' => trim($nt) ,
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
636 '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
637 'bot' => 1
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
638 ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
639
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
640 $this->d->info( "Editing $cmd_page...") ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
641 $x = $this->editWiki ( 'commonswiki' , 'edit' , $params ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
642 $this->d->debug( "Editing $cmd_page done.") ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
643 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
644
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
645 function fixFauxTemplateReplacements () {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
646 $todo = array() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
647 $db = $this->getToolDB() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
648 $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
649 $result = $this->runQuery ( $db , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
650 $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
651 $result = $this->runQuery ( $db , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
652 while($o = $result->fetch_object()){
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
653 $file = $this->getDBsafe ( $o->file ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
654 $wiki = $this->getDBsafe ( $o->wiki ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
655 $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
656 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
657 foreach ( $todo AS $sql ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
658 $this->runQuery ( $db , $sql ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
659 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
660 $db->close() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
661 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
662
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
663 // Unlinks deleted files
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
664 function run () {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
665 $this->d->debug("Get last timestamp");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
666 $max_ts = $this->getLastTimestamp() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
667 $this->d->debug("Get recent deleted files");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
668 $delink_files = $this->getRecentDeletedFiles ( $max_ts ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
669 $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
670 $this->addUnlinkEvents ( $delink_files ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
671 $this->d->debug("Add replace events");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
672 $this->addReplaceEvents () ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
673 $this->d->debug("Fix bogus template replacements");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
674 $this->fixFauxTemplateReplacements() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
675 $this->d->debug("Perform the queued edits");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
676 $this->performEdits() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
677 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
678
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
679 function debug_run0() {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
680 $this->d->debug("Add replace events");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
681 $this->addReplaceEvents () ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
682
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
683 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
684
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
685 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
686
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
687 print "Bot is starting.\n";
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
688 $demon = new CommonsDelinquentDemon ;
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 //$demon->addReplaceEvents () ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
691 //$demon->performEdits() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
692 //$demon->fixFauxTemplateReplacements() ;
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 $demon->set_debug_mode(8);
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 // test
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
697 # $demon->debug_run0();
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
698 //\\\\\\
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
699
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
700 $demon->debug("Performing edits...");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
701 $demon->performEdits() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
702 while ( 1 ) {
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
703 $demon->debug("Calling run loop...");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
704 $demon->run() ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
705 $demon->debug("Sleeping 30...");
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
706 sleep ( 30 ) ;
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
707 }
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
708
3b714bbb1347 Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff changeset
709 ?>

mercurial