-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbad-image.php
169 lines (144 loc) · 4.5 KB
/
bad-image.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
ini_set('memory_limit','16M');
define('PILLAR','PILLAR');
require_once('/home/soxred93/pillar/trunk/class.pillar.php');
require_once('/home/soxred93/textdiff/textdiff.php');
$pillar = Pillar::ini_launch('/home/soxred93/configs/bad-image.cfg');
$site = $pillar->cursite;
$enablepage = "User:SoxBot/Run/BIL";
try {
$run = new Page($site,$enablepage);
$run = $run->get_text();
} catch (PillarException $e) {
die( "Got an error when getting the enable page.\n" );
}
if( !preg_match( '/(enable|yes|run|go|start)/i', $run ) ) {
die( "Bot is disabled.\n" );
}
//START GENERATING TRANSCLUSIONS
$i = array();
$images = $site->get_embeddedin('Template:Badimage','500',$continue,'6|7');
foreach( $images as $image ) {
$i[] = $image;
}
while( isset($images[499]) ) {
$images = $site->get_embeddedin('Template:Badimage','500',$continue,'6|7');
foreach( $images as $image ) {
$i[] = $image;
}
}
//END GENERATING TRANSCLUSIONS
//START GENERATING BAD IMAGE LIST
try {
$bil = new Page($pillar->cursite,'MediaWiki:Bad image list');
} catch (PillarException $e) {
die();
}
$bil = $bil->get_text();
preg_match_all('/\*\s\[\[\:(File\:(.*?))\]\]/i', $bil, $bad_images);
$bad_images = $bad_images[1];
print_r($bad_images);
//END GENERATING BAD IMAGE LIST
//START PROCESSING EACH IMAGE
foreach( $i as $image ) {
if( in_array( str_replace('File talk','File',$image), $bad_images ) ) {
continue;
}
else {
try {
$image_page_object = new Page($pillar->cursite,$image);
} catch (PillarException $e) {
continue;
}
$image_page = $image_page_object->get_text();
$new_image_page = str_ireplace('{{badimage}}','',$image_page);
echo getTextDiff('unified', $image_page, $new_image_page);
if( $image_page == $new_image_page ) continue;
try {
$image_page_object->put($new_image_page,"Removing {{badimage}}, image is not on blacklist",true);
} catch (PillarException $e) {
continue;
}
continue;
}
if( str_replace('File talk','File',$image) != $image ) {
try {
$image_page_object = new Page($pillar->cursite,str_replace('File talk','File',$image));
$image_page = $image_page_object->get_text();
} catch (PillarException $e) {
continue;
}
try {
$image_talk_page_object = new Page($pillar->cursite,$image);
$image_talk_page = $image_talk_page_object->get_text();
} catch (PillarException $e) {
continue;
}
//START REMOVAL FROM TALK PAGE
$new_image_talk_page = str_ireplace('{{badimage}}','',$image_talk_page);
echo getTextDiff('unified', $image_talk_page, $new_image_talk_page);
if( $image_talk_page == $new_image_talk_page ) continue;
try {
$image_talk_page_object->put($new_image_talk_page,"Removing {{badimage}}, moving to main image page",true);
} catch (PillarException $e) {
continue;
}
//START ADDITION TO MAIN PAGE
if( preg_match('/\{\{badimage/i', $image_page ) ) continue;
$new_image_page = "{{badimage}}\n$image_page";
echo getTextDiff('unified', $image_page, $new_image_page);
if( $image_page == $new_image_page ) continue;
if( $image_page_object->checkexcluded() ) continue;
try {
$image_page_object->put($new_image_page,"Adding {{badimage}}",true);
} catch (PillarException $e) {
continue;
}
}
}
//END PROCESSING EACH IMAGE
//START GENERATING TRANSCLUSIONS
$i = array();
$images = $site->get_embeddedin('Template:Badimage','500',$continue,'6|7');
foreach( $images as $image ) {
$i[] = $image;
}
while( isset($images[499]) ) {
$images = $site->get_embeddedin('Template:Badimage','500',$continue,'6|7');
foreach( $images as $image ) {
$i[] = $image;
}
}
//END GENERATING TRANSCLUSIONS
//START GENERATING BAD IMAGE LIST
try {
$bil = new Page($pillar->cursite,'MediaWiki:Bad image list');
} catch (PillarException $e) {
die();
}
$bil = $bil->get_text();
preg_match_all('/\*\s\[\[\:(File\:(.*?))\]\]/i', $bil, $bad_images);
$bad_images = $bad_images[1];
//END GENERATING BAD IMAGE LIST
//START GOING THROUGH BIL
foreach( $bad_images as $bad_image ) {
try {
$image = new Page($pillar->cursite,$bad_image);
} catch (PillarException $e) {
continue;
}
//if( !$image->get_exists() ) continue;
$image_page = $image->get_text();
if( preg_match('/\{\{badimage/i', $image_page ) ) continue;
$new_image_page = "{{badimage}}\n$image_page";
echo getTextDiff('unified', $image_page, $new_image_page);
if( $image_page == $new_image_page ) continue;
if( $image->checkexcluded() ) continue;
try {
$image->put($new_image_page,"Adding {{badimage}}",true);
} catch (PillarException $e) {
continue;
}
}
//END GOING THROUGH BIL
?>