-
Notifications
You must be signed in to change notification settings - Fork 1
/
process_functions.php
159 lines (153 loc) · 6 KB
/
process_functions.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
<?php
namespace CluebotNG;
/*
* Copyright (C) 2015 Jacobi Carter and Chris Breneman
*
* This file is part of ClueBot NG.
*
* ClueBot NG is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* ClueBot NG is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClueBot NG. If not, see <http://www.gnu.org/licenses/>.
*/
class Process
{
public static function processEdit($change)
{
global $logger;
if (
(time() - Globals::$tfas) >= 1800 and
preg_match(
'/\(\'\'\'\[\[([^|]*)\|more...\]\]\'\'\'\)/iU',
Api::$q->getpage('Wikipedia:Today\'s featured article/' . date('F j, Y')),
$tfam
)
) {
Globals::$tfas = time();
Globals::$tfa = $tfam[1];
}
if ((time() - Globals::$atime) >= 600) {
if (!Api::$a->loggedin()) {
$logger->addWarning('Lost authentication');
if (!Api::$a->login(Config::$user, Config::$pass)) {
$logger->addError('Failed to re-authenticate');
die(); // Before we fork, this is the parent
}
}
Globals::$atime = time();
}
if (Config::$fork) {
$pid = pcntl_fork();
if ($pid != 0) {
$logger->addDebug('Forked - ' . $pid);
return;
}
}
$change = parseFeedData($change);
$change['justtitle'] = $change['title'];
if (in_array('namespace', $change) && $change['namespace'] != 'Main:') {
$change['title'] = $change['namespace'] . $change['title'];
}
self::processEditThread($change);
if (Config::$fork) {
die();
}
}
public static function processEditThread($change)
{
global $logger;
$change['edit_status'] = 'not_reverted';
if (!isset($s)) {
$change['edit_score'] = 'N/A';
$s = null;
} else {
$change['edit_score'] = $s;
}
if (!in_array('all', $change)) {
Feed::bail($change, 'Missing edit data', $s);
return;
}
if (!isVandalism($change['all'], $s)) {
Feed::bail($change, 'Below threshold', $s);
return;
}
if (Action::isWhitelisted($change['user'])) {
$logger->addInfo("User " . $change['user'] . " is whitelisted");
Feed::bail($change, 'Whitelisted', $s);
return;
}
$reason = 'ANN scored at ' . $s;
$heuristic = '';
$log = null;
$diff = 'https://en.wikipedia.org/w/index.php' .
'?title=' . urlencode($change['title']) .
'&diff=' . urlencode($change['revid']) .
'&oldid=' . urlencode($change['old_revid']);
$report = '[[' . str_replace('File:', ':File:', $change['title']) . ']] was '
. '[' . $diff . ' changed] by '
. '[[Special:Contributions/' . $change['user'] . '|' . $change['user'] . ']] '
. '[[User:' . $change['user'] . '|(u)]] '
. '[[User talk:' . $change['user'] . '|(t)]] '
. $reason . ' on ' . gmdate('c');
$oftVand = unserialize(file_get_contents('oftenvandalized.txt'));
if (rand(1, 50) == 2) {
foreach ($oftVand as $art => $artVands) {
foreach ($artVands as $key => $time) {
if ((time() - $time) > 2 * 24 * 60 * 60) {
unset($oftVand[$art][$key]);
}
}
}
}
$oftVand[$change['title']][] = time();
file_put_contents('oftenvandalized.txt', serialize($oftVand));
$ircreport = "\x0315[[\x0307" . $change['title'] . "\x0315]] by \"\x0303" . $change['user'] .
"\x0315\" (\x0312 " . $change['url'] . " \x0315) \x0306" . $s . "\x0315 (";
$change['mysqlid'] = Db::detectedVandalism(
$change['user'],
$change['title'],
$heuristic,
$reason,
$change['url'],
$change['old_revid'],
$change['revid']
);
list($shouldRevert, $revertReason) = Action::shouldRevert($change);
$change['revert_reason'] = $revertReason;
if ($shouldRevert) {
$logger->addInfo("Reverting");
$rbret = Action::doRevert($change);
if ($rbret !== false) {
$change['edit_status'] = 'reverted';
IRC::revert(
$ircreport . "\x0304Reverted\x0315) (\x0313" . $revertReason .
"\x0315) (\x0302" . (microtime(true) - $change['startTime']) . " \x0315s)"
);
Action::doWarn($change, $report);
Db::vandalismReverted($change['mysqlid']);
Feed::bail($change, $revertReason, $s, true);
} else {
$change['edit_status'] = 'beaten';
$rv2 = Api::$a->revisions($change['title'], 1);
if ($change['user'] != $rv2[0]['user']) {
IRC::revert(
$ircreport . "\x0303Not Reverted\x0315) (\x0313Beaten by " .
$rv2[0]['user'] . "\x0315) (\x0302" . (microtime(true) - $change['startTime']) . " \x0315s)"
);
Db::vandalismRevertBeaten($change['mysqlid'], $change['title'], $rv2[0]['user'], $change['url']);
Feed::bail($change, 'Beaten by ' . $rv2[0]['user'], $s);
}
}
} else {
Feed::bail($change, $revertReason, $s);
}
}
}