jenkins-bot has submitted this change and it was merged. Change subject: Use EditFilterMergedContent instead of APIEditBeforeSave hook ......................................................................
Use EditFilterMergedContent instead of APIEditBeforeSave hook It was only needed for MediaWiki prior to 1.25 (09a5febb7b024c0b6585141bb05cba13a642f3eb). We no longer support those versions after 5d882775f6323e9c23bed3abba9a4b8293c7b840. Bug: T137832 Change-Id: I97f6a3c20476f1a42e3fadc701df5870a30c790c --- M SpamBlacklistHooks.php M extension.json 2 files changed, 4 insertions(+), 52 deletions(-) Approvals: Jforrester: Looks good to me, approved jenkins-bot: Verified diff --git a/SpamBlacklistHooks.php b/SpamBlacklistHooks.php index e7df36c..184808e 100644 --- a/SpamBlacklistHooks.php +++ b/SpamBlacklistHooks.php @@ -53,11 +53,6 @@ static function filterMergedContent( IContextSource $context, Content $content, Status $status, $summary, User $user, $minoredit ) { $title = $context->getTitle(); - if ( isset( $title->spamBlackListFiltered ) && $title->spamBlackListFiltered ) { - // already filtered - return true; - } - // get the link from the not-yet-saved page content. $editInfo = $context->getWikiPage()->prepareContentForEdit( $content ); $pout = $editInfo->output; @@ -81,6 +76,10 @@ foreach ( $matches as $match ) { $status->fatal( 'spamprotectionmatch', $match ); } + + $status->apiHookResult = [ + 'spamblacklist' => implode( '|', $matches ), + ]; } // Always return true, EditPage will look at $status->isOk(). @@ -90,50 +89,6 @@ public static function onParserOutputStashForEdit( WikiPage $page ) { $spamObj = BaseBlacklist::getInstance( 'spam' ); $spamObj->warmCachesForFilter( $page->getTitle() ); - } - - /** - * Hook function for APIEditBeforeSave. - * This allows blacklist matches to be reported directly in the result structure - * of the API call. - * - * @param $editPage EditPage - * @param $text string - * @param $resultArr array - * @return bool - */ - static function filterAPIEditBeforeSave( $editPage, $text, &$resultArr ) { - $title = $editPage->mArticle->getTitle(); - - // get the links from the not-yet-saved page content. - $content = ContentHandler::makeContent( - $text, - $editPage->getTitle(), - $editPage->contentModel, - $editPage->contentFormat - ); - $editInfo = $editPage->mArticle->prepareContentForEdit( $content, null, null, $editPage->contentFormat ); - $pout = $editInfo->output; - $links = array_keys( $pout->getExternalLinks() ); - - // HACK: treat the edit summary as a link - $summary = $editPage->summary; - if ( $summary !== '' ) { - $links[] = $summary; - } - - $spamObj = BaseBlacklist::getInstance( 'spam' ); - $matches = $spamObj->filter( $links, $title ); - - if ( $matches !== false ) { - $resultArr['spamblacklist'] = implode( '|', $matches ); - } - - // mark the title, so filterMergedContent can skip it. - $title->spamBlackListFiltered = true; - - // return convention for hooks is the inverse of $wgFilterCallback - return ( $matches === false ); } /** diff --git a/extension.json b/extension.json index 1007511..257fb5a 100644 --- a/extension.json +++ b/extension.json @@ -51,9 +51,6 @@ "EditFilterMergedContent": [ "SpamBlacklistHooks::filterMergedContent" ], - "APIEditBeforeSave": [ - "SpamBlacklistHooks::filterAPIEditBeforeSave" - ], "EditFilter": [ "SpamBlacklistHooks::validate" ], -- To view, visit https://gerrit.wikimedia.org/r/295738 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I97f6a3c20476f1a42e3fadc701df5870a30c790c Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/SpamBlacklist Gerrit-Branch: master Gerrit-Owner: Anomie <bjor...@wikimedia.org> Gerrit-Reviewer: Bartosz DziewoĆski <matma....@gmail.com> Gerrit-Reviewer: Jackmcbarn <jackmcb...@gmail.com> Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits