From 5b321350e12d2f1a590bff2bb61471266e4cd05a Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Tue, 10 Dec 2024 02:11:21 +0100 Subject: [PATCH] Avoid dynamic property for PHP 8.2 compatibility Add a public method AbuseFilterChangesList that updates a map of RC IDs. I don't particularly like this approach, but I don't like the whole ChangesList situation either, so this should be fine for the time being. Bug: T381836 Change-Id: I0100ed64472de67cf4559f63f2c39eb2f882e0f5 --- includes/AbuseFilterChangesList.php | 17 ++++++++++++++--- includes/View/AbuseFilterViewTestBatch.php | 3 +-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/includes/AbuseFilterChangesList.php b/includes/AbuseFilterChangesList.php index 4b0095f24..091e1302f 100644 --- a/includes/AbuseFilterChangesList.php +++ b/includes/AbuseFilterChangesList.php @@ -20,6 +20,11 @@ class AbuseFilterChangesList extends OldChangesList { */ private $testFilter; + /** + * @var array Maps RC IDs to a boolean indicating whether the RC would match a filter that is being tested + */ + private array $rcResults = []; + /** * @param IContextSource $context * @param string $testFilter @@ -51,7 +56,8 @@ class AbuseFilterChangesList extends OldChangesList { $examineParams['testfilter'] = $this->testFilter; } - $title = SpecialPage::getTitleFor( 'AbuseFilter', 'examine/' . $rc->getAttribute( 'rc_id' ) ); + $rcid = $rc->getAttribute( 'rc_id' ); + $title = SpecialPage::getTitleFor( 'AbuseFilter', 'examine/' . $rcid ); $examineLink = $this->linkRenderer->makeLink( $title, new HtmlArmor( $this->msg( 'abusefilter-changeslist-examine' )->parse() ), @@ -62,8 +68,8 @@ class AbuseFilterChangesList extends OldChangesList { $s .= ' ' . $this->msg( 'parentheses' )->rawParams( $examineLink )->escaped(); // Add CSS classes for match and not match - if ( isset( $rc->filterResult ) ) { - $class = $rc->filterResult ? + if ( isset( $this->rcResults[$rcid] ) ) { + $class = $this->rcResults[$rcid] ? 'mw-abusefilter-changeslist-match' : 'mw-abusefilter-changeslist-nomatch'; @@ -158,4 +164,9 @@ class AbuseFilterChangesList extends OldChangesList { public function insertRollback( &$s, &$rc ) { // Kill rollback links. } + + public function setRCResult( RecentChange $rc, bool $matches ): void { + $id = $rc->getAttribute( 'rc_id' ); + $this->rcResults[$id] = $matches; + } } diff --git a/includes/View/AbuseFilterViewTestBatch.php b/includes/View/AbuseFilterViewTestBatch.php index 5e8a2c856..a414372b8 100644 --- a/includes/View/AbuseFilterViewTestBatch.php +++ b/includes/View/AbuseFilterViewTestBatch.php @@ -298,8 +298,7 @@ class AbuseFilterViewTestBatch extends AbuseFilterView { $result = $ruleChecker->checkConditions( $this->testPattern )->getResult(); if ( $result || $formData['ShowNegative'] ) { - // Stash result in RC item - $rc->filterResult = $result; + $changesList->setRCResult( $rc, $result ); $rc->counter = $counter++; $output .= $changesList->recentChangesLine( $rc, false ); }