Jack Phoenix has uploaded a new change for review. https://gerrit.wikimedia.org/r/324859
Change subject: Use the EditFilterMergedContent hook to run page creations through SpamRegex ...................................................................... Use the EditFilterMergedContent hook to run page creations through SpamRegex The errorbox stuff is slightly ugly-ish, but whatever, I copied that from ConfirmEdit. Bug: T152178 Change-Id: I48f6fcbf5642d2c27866a03ea32e4af96b95c902 --- M backend/SpamRegexHooks.php M extension.json 2 files changed, 44 insertions(+), 21 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SpamRegex refs/changes/59/324859/1 diff --git a/backend/SpamRegexHooks.php b/backend/SpamRegexHooks.php index c15501f..90231aa 100644 --- a/backend/SpamRegexHooks.php +++ b/backend/SpamRegexHooks.php @@ -9,17 +9,16 @@ /** * Main hook handler for edits * - * @param EditPage $editPage - * @param string $text Page text - * @param $section - * @param string $error Error message, if any - * @param string $editSummary User-supplied edit summary + * @param Context $Context + * @param Content $content A content object representing the page text + * @param Status $status Status object for errors etc. + * @param string $editSummary User-supplied summary for this edit + * @param User $user The User obejct representing the person who made this edit * @return bool True if the edit went through, false if it hit the spam filters */ - public static function onEditFilter( $editPage, $text, $section, &$error, $editSummary ) { - global $wgOut; + public static function onEditFilterMergedContent( $context, $content, $status, $editSummary, $user ) { + $title = $context->getTitle(); - $title = $editPage->getTitle(); // allow blocked words to be added to whitelist if ( $title->inNamespace( NS_MEDIAWIKI ) && @@ -32,22 +31,35 @@ // here we get only the phrases for blocking in summaries... $s_phrases = self::fetchRegexData( 0 ); - if ( $s_phrases && ( $editPage->summary != '' ) ) { + if ( $s_phrases && ( $editSummary != '' ) ) { // ...so let's rock with our custom spamPage to indicate that // (since some phrases can be safely in the text and not in a summary // and we do not want to confuse the good users, right?) foreach ( $s_phrases as $s_phrase ) { - if ( preg_match( $s_phrase, $editPage->summary, $s_matches ) ) { - $wgOut->setPageTitle( wfMessage( 'spamprotectiontitle' ) ); - $wgOut->setRobotPolicy( 'noindex,nofollow' ); - $wgOut->setArticleRelated( false ); + if ( preg_match( $s_phrase, $editSummary, $s_matches ) ) { + $status->value = EditPage::AS_HOOK_ERROR_EXPECTED; + $status->fatal( + new RawMessage( + $context->msg( 'spamprotectiontext' ) . + '<br />' . + Html::element( + 'div', + [ 'class' => 'errorbox' ], + $context->msg( 'spamprotectionmatch', "<nowiki>{$s_matches[0]}</nowiki>" )->parse() + ) . + '<br />' . + $context->msg( 'spamregex-summary' ) + ) + ); - $wgOut->addWikiMsg( 'spamprotectiontext' ); - $wgOut->addWikiMsg( 'spamprotectionmatch', "<nowiki>{$s_matches[0]}</nowiki>" ); - $wgOut->addWikiMsg( 'spamregex-summary' ); + $out = $context->getOutput(); + // These two (maybe three?) lines appear not to be working + // anymore; remove? + $out->setPageTitle( wfMessage( 'spamprotectiontitle' ) ); + $out->setRobotPolicy( 'noindex,nofollow' ); + $out->setArticleRelated( false ); - $wgOut->returnToMain( false, $title ); return false; } } @@ -58,8 +70,19 @@ $t_phrases = self::fetchRegexData( 1 ); if ( $t_phrases && is_array( $t_phrases ) ) { foreach ( $t_phrases as $t_phrase ) { - if ( preg_match( $t_phrase, $editPage->textbox1, $t_matches ) ) { - $editPage->spamPageWithContent( $t_matches[0] ); + if ( preg_match( $t_phrase, $content->getNativeData(), $t_matches ) ) { + $status->value = EditPage::AS_HOOK_ERROR_EXPECTED; + $status->fatal( + new RawMessage( + $context->msg( 'spamprotectiontext' ) . + '<br />' . + Html::element( + 'div', + [ 'class' => 'errorbox' ], + $context->msg( 'spamprotectionmatch', "<nowiki>{$t_matches[0]}</nowiki>" )->parse() + ) + ) + ); return false; } } diff --git a/extension.json b/extension.json index 298406c..9cf4125 100644 --- a/extension.json +++ b/extension.json @@ -29,8 +29,8 @@ "SpamRegexHooks": "/backend/SpamRegexHooks.php" }, "Hooks": { - "EditFilter": [ - "SpamRegexHooks::onEditFilter" + "EditFilterMergedContent": [ + "SpamRegexHooks::onEditFilterMergedContent" ], "MovePageCheckPermissions": [ "SpamRegexHooks::onMovePageCheckPermissions" -- To view, visit https://gerrit.wikimedia.org/r/324859 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I48f6fcbf5642d2c27866a03ea32e4af96b95c902 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/SpamRegex Gerrit-Branch: master Gerrit-Owner: Jack Phoenix <j...@countervandalism.net> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits