From 27bef0ab9d5b5aa546a4d39d2e66a1a047e52102 Mon Sep 17 00:00:00 2001 From: Damian Zaremba Date: Fri, 13 Dec 2024 10:53:44 +0000 Subject: [PATCH 1/5] processEditThread - correct data check `in_array` prior to php 8 uses loose checking, since php 8 it now stricly checks the type... the type here being an array not a string. Change to array_key_exists, which is what we're really checking here. --- process_functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process_functions.php b/process_functions.php index c748f3e..8184a7b 100644 --- a/process_functions.php +++ b/process_functions.php @@ -75,7 +75,7 @@ public static function processEditThread($change) } else { $change['edit_score'] = $s; } - if (!in_array('all', $change)) { + if (!array_key_exists('all', $change)) { Feed::bail($change, 'Missing edit data', $s); return; } From 71a095569f5b795b64feeca6058c48c92797e7f7 Mon Sep 17 00:00:00 2001 From: Damian Zaremba Date: Fri, 13 Dec 2024 10:56:10 +0000 Subject: [PATCH 2/5] doRevert - store friends as array Rather than exploding into an array on every edit - this is essentially static config. --- action_functions.php | 2 +- cluebot-ng.config.php.dist | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/action_functions.php b/action_functions.php index 9043263..7074b55 100644 --- a/action_functions.php +++ b/action_functions.php @@ -134,7 +134,7 @@ public static function doRevert($change) if ($revdata === false) { return; } - if (($revdata['user'] == Config::$user) or (in_array($revdata['user'], explode(',', Config::$friends)))) { + if (($revdata['user'] == Config::$user) or (in_array($revdata['user'], Config::$friends))) { return false; } if (Config::$dry) { diff --git a/cluebot-ng.config.php.dist b/cluebot-ng.config.php.dist index 981e6e9..c9a13d7 100644 --- a/cluebot-ng.config.php.dist +++ b/cluebot-ng.config.php.dist @@ -25,7 +25,7 @@ namespace CluebotNG; public static $status = 'auto'; public static $angry = false; public static $owner = 'Cobi'; - public static $friends = 'ClueBot,DASHBotAV'; + public static $friends = ['ClueBot', 'DASHBotAV']; public static $mw_mysql_host = 'enwiki.labsdb'; public static $mw_mysql_port = 3306; public static $mw_mysql_user = ''; From da2900f682cc6d72565bb0a936470c7747899cdf Mon Sep 17 00:00:00 2001 From: Damian Zaremba Date: Fri, 13 Dec 2024 11:51:06 +0000 Subject: [PATCH 3/5] Another 2 array_key_exists cases --- feed_functions.php | 2 +- process_functions.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/feed_functions.php b/feed_functions.php index bc495e0..4be3fa5 100644 --- a/feed_functions.php +++ b/feed_functions.php @@ -128,7 +128,7 @@ public static function bail($change, $why = '', $score = 'N/A', $reverted = fals $rchange['edit_reason'] = $why; $rchange['edit_score'] = $score; - if (!in_array('raw_line', $change)) { + if (!array_key_exists('rawline', $change)) { return; } diff --git a/process_functions.php b/process_functions.php index 8184a7b..28c2010 100644 --- a/process_functions.php +++ b/process_functions.php @@ -56,7 +56,7 @@ public static function processEdit($change) } $change = parseFeedData($change); $change['justtitle'] = $change['title']; - if (in_array('namespace', $change) && $change['namespace'] != 'Main:') { + if (array_key_exists('namespace', $change) && $change['namespace'] != 'Main:') { $change['title'] = $change['namespace'] . $change['title']; } self::processEditThread($change); From 50a8a1619f41a4f9e28f64d202e8d818927638a7 Mon Sep 17 00:00:00 2001 From: Damian Zaremba Date: Fri, 13 Dec 2024 12:48:04 +0000 Subject: [PATCH 4/5] processEdit - fix TFA parsing --- action_functions.php | 12 ------------ process_functions.php | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/action_functions.php b/action_functions.php index 7074b55..117c5d7 100644 --- a/action_functions.php +++ b/action_functions.php @@ -172,18 +172,6 @@ public static function shouldRevert($change) if (Config::$angry) { return array(true, 'Angry-reverting in angry mode'); } - if ((time() - Globals::$tfas) >= 1800) { - if ( - 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 (!self::findAndParseBots($change)) { return array(false, 'Exclusion compliance'); } diff --git a/process_functions.php b/process_functions.php index 28c2010..043ea14 100644 --- a/process_functions.php +++ b/process_functions.php @@ -29,7 +29,7 @@ public static function processEdit($change) if ( (time() - Globals::$tfas) >= 1800 and preg_match( - '/\(\'\'\'\[\[([^|]*)\|more...\]\]\'\'\'\)/iU', + '/{{TFAFULL\|([^}]+)}}/iU', Api::$q->getpage('Wikipedia:Today\'s featured article/' . date('F j, Y')), $tfam ) From 1f71b86660f093a2a64ae1b2432f23f367a434f0 Mon Sep 17 00:00:00 2001 From: Damian Zaremba Date: Fri, 13 Dec 2024 12:56:58 +0000 Subject: [PATCH 5/5] Invert stripos calls We are searching for the needle in the haystack, not the haystack in the needl. --- action_functions.php | 2 +- feed_functions.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/action_functions.php b/action_functions.php index 117c5d7..a824ee3 100644 --- a/action_functions.php +++ b/action_functions.php @@ -210,7 +210,7 @@ public static function shouldRevert($change) public static function findAndParseBots($change) { $text = $change['all']['current']['text']; - if (stripos('{{nobots}}', $text) !== false) { + if (stripos($text, '{{nobots}}') !== false) { return false; } $botname = preg_quote(Config::$user, '/'); diff --git a/feed_functions.php b/feed_functions.php index 4be3fa5..ac01183 100644 --- a/feed_functions.php +++ b/feed_functions.php @@ -80,7 +80,7 @@ private static function loop($line) } $data['line'] = $message; $data['rawline'] = $rawmessage; - if (stripos('N', $data['flags']) !== false) { + if (stripos($data['flags'], 'N') !== false) { self::bail($data, 'New article'); return; }