-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathPCbot.php
executable file
·114 lines (93 loc) · 4.03 KB
/
PCbot.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
<?php
ini_set('memory_limit','16M');
echo "----------STARTING UP SCRIPT----------\nStart Timestamp: ".date('r')."\n\n";
require_once( '/home/cyberpower678/Peachy/Init.php' );
$site = Peachy::newWiki( "cyberbotii" );
$site->set_runpage( "User:Cyberbot II/Run/PC" );
while(true) {
echo "----------RUN TIMESTAMP: ".date('r')."----------\n\n";
$request = $site->get_http()->get( 'https://en.wikipedia.org/w/index.php?title=Special:StablePages&offset=&limit=500000000' );
$timestamp = date( 'Y-m-d\TH:i:s\Z' );
if( !preg_match( '/mw\.config\.set\(\{\"wgBackendResponseTime\"\:(.*?)\,\"wgHostname\"\:\"(.*?)\"\}\)\;/i', $request ) ) {
echo( "Site failure" );
exit(1);
}
$templatelist1 = initPage("Template:Pp-pc1")->embeddedin();
$templatelist2 = initPage("Template:Pp-pc2")->embeddedin();
echo "Retrieving Protected Pages...\n";
preg_match_all('/'.
'\<li\>\<a href=\".*?\"\s*title=\".*?\"\>(.*?)\<\/a\>.*?\[autoreview=(autoconfirmed|review)\]\<i\>(\s*\(expires\s*(.*?\s*\(UTC\))\))?\<\/i\>\<\/li\>/i',$request,$list);
$names = $list[1];
$level = $list[2];
$expiry = $list[4];
echo "Retrieved protected pages.\n";
//Tag each page with a protection template
foreach( $names as $i=>$page ) {
echo "Processing ".$page."...\nLevel: {$level[$i]}; Expires: {$expiry[$i]}\n";
$object = $site->initPage( $page, null, false, true, $timestamp );
$text = $object->get_text();
if( empty( $text ) ) continue;
$template = "";
if( $level[$i] == "autoconfirmed" ) $template .= "{{pp-pc1";
else $template .= "{{pp-pc2";
if( ($temp = strpos( strtolower( $text ), "{{pp-pc" )) !== false ) {
if( strpos( strtolower( $text ), "{{pp-pc", $temp + 1 ) !== false || ( $level[$i] == "autoconfirmed" && strpos( strtolower( $text ), "{{pp-pc2" ) !== false ) || ( $level[$i] == "review" && strpos( strtolower( $text ), "{{pp-pc1" ) !== false ) ) {
echo "Replacing existing PC tags with correct one...\n";
$text = preg_replace( '/\{\{[P|p]p-pc[1|2].*?\}\}(\s*?\n)?/i','',$text );
} elseif( strpos( strtolower( $text ), $template ) !== false ) {
echo "Page already tagged with $template}}\n";
continue;
}
}
if( !empty( $expiry[$i] ) ) $template .= "|expiry=".date( 'F j, Y', strtotime( $expiry[$i] ) );
$template .= "}}";
$logs = $site->logs( "stable", false, $page );
if( isset( $logs[0]['timestamp'] ) ) $lastprotectaction = strtotime( $logs[0]['timestamp'] );
else $lastprotectaction = 0;
$dt = time() - $lastprotectaction;
if( $dt <= 300 ) continue;
echo "Tagging ".$page." with $template...\n";
if( strtolower( substr( $text, 0, 9 ) ) != "#redirect" ) $object->edit( $template."\n".$text, "Tagging page with $template.", true );
else $object->edit( $text."\n".$template, "Tagging redirect with $template.", true );
}
//Removing templates from unprotected pages
echo "\nVerifying that all pages are tagged correctly...\n";
foreach($templatelist1 as $page) {
$i = 0;
$isprotected = false;
foreach($names as $page2) {
if(htmlspecialchars ($page) == $page2) {
if($level[$i] == "autoconfirmed") {
echo $page." has a correct tag\n";
$isprotected = true;
}
}
$i = $i+1;
}
if($isprotected == false) {
echo $page." is not PC1 protected. Removing template...\n";
$data = initPage($page, null, false, true, $timestamp);
$data->edit(preg_replace('/\{\{(P|p)?p-pc1(.*?)\}\}(\n)?/i','',$data->get_text()),"Removing {{Pp-pc1}}. Page is not protected.", true);
}
}
foreach($templatelist2 as $page) {
$i = 0;
$isprotected = false;
foreach($names as $page2) {
if(htmlspecialchars ($page) == $page2) {
if($level[$i] == "review") {
echo $page." has a correct tag\n";
$isprotected = true;
}
}
$i = $i+1;
}
if($isprotected == false) {
echo $page." is not PC2 protected. Removing template...\n";
$data = initPage($page, null, false, true, $timestamp);
$data->edit(preg_replace('/\{\{(P|p)?p-pc2(.*?)\}\}(\n)?/i','',$data->get_text()),"Removing {{Pp-pc2}}. Page is not protected.", true);
}
}
echo "Task completed!\n\n";
sleep( 60 );
}