From 351f9f02bcc5acd26721cffbadabaf13e62f75bb Mon Sep 17 00:00:00 2001 From: Func Date: Fri, 16 Apr 2021 15:19:54 +0000 Subject: [PATCH] Handle EditFilterMergedContent hook properly to break hook chains and display error message Extensions are supposed to return false to break hook chains when failed, which can avoid unnecessary call of later handlers in other extensions and work around with problems caused by difference betwen multiple triggers. On mediawiki version 1.36 and before, just returning false in this hook can't display error message by default. Set $status->value manually still to provide backward compatibility. Bug: T280312 Change-Id: I78888247063c726ebcd18ba54a21d6c7891481fc --- includes/AbuseFilterHooks.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/includes/AbuseFilterHooks.php b/includes/AbuseFilterHooks.php index 4d7219ded..e40cf0ecd 100644 --- a/includes/AbuseFilterHooks.php +++ b/includes/AbuseFilterHooks.php @@ -28,6 +28,7 @@ class AbuseFilterHooks { * @param User $user the user performing the edit * @param bool $minoredit whether this is a minor edit according to the user. * @param string $slot slot role for the content + * @return bool */ public static function onEditFilterMergedContent( IContextSource $context, Content $content, Status $status, $summary, User $user, $minoredit, $slot = SlotRecord::MAIN @@ -48,9 +49,13 @@ class AbuseFilterHooks { // Produce a useful error message for API edits $filterResultApi = self::getApiStatus( $filterResult ); $status->merge( $filterResultApi ); + // @todo Remove this line after this extension do not support mediawiki version 1.36 and before + $status->value = \EditPage::AS_HOOK_ERROR_EXPECTED; } MediaWikiServices::getInstance()->getStatsdDataFactory() ->timing( 'timing.editAbuseFilter', microtime( true ) - $startTime ); + + return $status->isOK(); } /**