Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions action_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,21 +181,12 @@ public static function doRevert($change, $score)
public static function shouldRevert($change)
{
$reason = 'Default revert';
if (preg_match('/(assisted|manual)/iS', Config::$status)) {
echo 'Revert [y/N]? ';
if (strtolower(substr(fgets(Globals::$stdin, 3), 0, 1)) != 'y') {
return [false, 'Manual mode says no'];
}
}
if (!Globals::$run) {
return [false, 'Run disabled'];
}
if ($change['user'] == Config::$user) {
return [false, 'User is myself'];
}
if (Config::$angry) {
return [true, 'Angry-reverting in angry mode'];
}
if (!self::findAndParseBots($change)) {
return [false, 'Exclusion compliance'];
}
Expand Down
71 changes: 38 additions & 33 deletions cbng.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,48 @@
* You should have received a copy of the GNU General Public License
* along with ClueBot NG. If not, see <http://www.gnu.org/licenses/>.
*/
function isValidRevisionData($data)
{
return $data !== null
and isset($data['revisions'][1]['user'])
and isset($data['revisions'][0]['timestamp'])
and isset($data['revisions'][0]['*'])
and isset($data['revisions'][1]['timestamp'])
and isset($data['revisions'][1]['*']);
}

function fetchRevisionData($url)
{
$ch = curl_init();
if (isset($proxyhost) and isset($proxyport) and $proxyport != null and $proxyhost != null) {
$page = null;
for ($attempt = 1; $attempt <= 3; $attempt++) {
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_PROXYTYPE => isset($proxytype) ? $proxytype : CURLPROXY_HTTP,
CURLOPT_PROXY => $proxyhost,
CURLOPT_PROXYPORT => $proxyport,
CURLOPT_USERAGENT => 'ClueBot/2.0',
CURLOPT_URL => $url,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_MAXREDIRS => 10,
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_TIMEOUT => 120,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_HTTPGET => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_ENCODING => '',
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
]);
$data = json_decode(curl_exec($ch), true);
$page = isset($data['query']['pages']) ? current($data['query']['pages']) : null;

if (isValidRevisionData($page)) {
return $page;
}

// Try again after a short wait - hopefully the change has replicated
sleep(1);
}
curl_setopt_array($ch, [
CURLOPT_USERAGENT => 'ClueBot/2.0',
CURLOPT_URL => $url,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_MAXREDIRS => 10,
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_TIMEOUT => 120,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_HTTPGET => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_ENCODING => '',
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
]);
$result = curl_exec($ch);
$data = json_decode($result, true);
if (!isset($data['query']['pages'])) {
return null;
}
return current($data['query']['pages']);

return $page;
}

function xmlizePart($doc, $key, $data)
Expand Down Expand Up @@ -95,13 +106,7 @@ function parseFeedData($feedData)
'&rvstartid=' . $feedData['revid'] . '&rvlimit=2&rvprop=timestamp|user|content&format=json',
);

if (
!(isset($api['revisions'][1]['user'])
and isset($api['revisions'][0]['timestamp'])
and isset($api['revisions'][0]['*'])
and isset($api['revisions'][1]['timestamp'])
and isset($api['revisions'][1]['*']))
) {
if (!isValidRevisionData($api)) {
$logger->warning(
"Failed to get revision info",
['revision_id' => $feedData['revid'], 'title' => $feedData['namespaced_title']]
Expand Down
2 changes: 0 additions & 2 deletions cluebot-ng.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class Config
{
public static $user = 'ClueBot NG';
public static $pass = ""; // Read from disk
public static $status = 'auto';
public static $angry = false;
public static $owner = 'Cobi';
public static $friends = ['ClueBot', 'DASHBotAV'];
public static $mw_mysql_host = 'enwiki.labsdb';
Expand Down
Loading