-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuncat-remove.php
113 lines (97 loc) · 2.28 KB
/
uncat-remove.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
<?php
ini_set('memory_limit','16M');
define('PILLAR','PILLAR');
require_once('/home/soxred93/pillar/trunk/class.pillar.php');
$pillar = Pillar::ini_launch('/home/soxred93/configs/uncat-remove.cfg');
$site = $pillar->cursite;
$enablepage = "User:SoxBot/Run/Uncat";
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" );
}
$template = "Template:Uncategorized";
$p = array();
$ignorelist = array(
'Articles lacking sources (Erik9bot)',
);
$pages = $site->get_embeddedin($template,'500',$continue,0);
foreach( $pages as $page ) {
$p[] = $page;
}
while( isset($pages[499]) ) {
$pages = $site->get_embeddedin($template,'500',$continue,0);
foreach( $pages as $page ) {
$p[] = $page;
}
}
require_once('/home/soxred93/textdiff/textdiff.php');
$c = 1;
$tofind = array(
'Classify',
'CatNeeded',
'Uncategorised',
'Uncat',
'Categorize',
'Categories needed',
'Categoryneeded',
'Category needed',
'Category requested',
'Categories requested',
'Nocats',
'Categorise',
'Nocat',
'Uncat-date',
'Uncategorized-date',
'Needs cat',
'Needs cats',
'Cat needed',
'Cats needed',
);
foreach ($p as $pg) {
if( $c > 30 ) break;
try {
$page = new Page($site,$pg);
} catch (PillarException $e) {
continue;
}
$text = $page->get_text();
preg_match_all('/\[\[Category:(.*?)(\|(.*?))?\]\]/Si', $text, $cats);
if( $cats ) {
$cats = $cats[1];
$remove = 'no';
foreach( $cats as $cat ) {
if( in_array( $cat, $ignorelist ) ) {
continue;
}
$vars = array(
'action' => 'query',
'prop' => 'info',
'titles' => 'Category:'.$cat,
);
$request = new MWRequest($site,$vars);
$result = $request->get_result();
if( !isset($result['query']['pages']['-1']['missing']) ) {
$remove = 'yes';
break;
}
}
if( $remove == 'yes' ) {
$newtext = preg_replace('/\{\{('.implode('|',$tofind).')(.*?)\}\}/i', '', $text);
$diff = getTextDiff('unified', $text, $newtext);
echo $diff;
if( $page->checkexcluded() ) continue;
try {
$page->put($newtext,"Removing categorization template",true);
} catch (PillarException $e) {
continue;
}
$c++;
}
}
}
?>