From 8ed29d19b6142e335ca60fcefe7d028ab30d9225 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Mon, 27 Oct 2014 10:55:33 -0700 Subject: [PATCH] Use MovePageCheckPermissions hook if possible Change-Id: Ic5026384b92a0d68d628397ffe1de6e5b6183f02 --- AbuseFilter.hooks.php | 35 ++++++++++++++++++++++------------- AbuseFilter.php | 1 + 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/AbuseFilter.hooks.php b/AbuseFilter.hooks.php index 25ab40051..bd0c4eaf7 100644 --- a/AbuseFilter.hooks.php +++ b/AbuseFilter.hooks.php @@ -288,6 +288,22 @@ class AbuseFilterHooks { return true; } + public static function onMovePageCheckPermissions( Title $oldTitle, Title $newTitle, User $user, $reason, Status $status ) { + $vars = new AbuseFilterVariableHolder; + $vars->addHolders( + AbuseFilter::generateUserVars( $user ), + AbuseFilter::generateTitleVars( $oldTitle, 'MOVED_FROM' ), + AbuseFilter::generateTitleVars( $newTitle, 'MOVED_TO' ) + ); + $vars->setVar( 'SUMMARY', $reason ); + $vars->setVar( 'ACTION', 'move' ); + + $result = AbuseFilter::filterAction( $vars, $oldTitle ); + $status->merge( $result ); + + return $result->isOK(); + } + /** * @param $oldTitle Title * @param $newTitle Title @@ -297,8 +313,6 @@ class AbuseFilterHooks { * @return bool */ public static function onAbortMove( $oldTitle, $newTitle, $user, &$error, $reason ) { - $vars = new AbuseFilterVariableHolder; - global $wgUser; // HACK: This is a secret userright so system actions // can bypass AbuseFilter. Should not be assigned to @@ -308,18 +322,13 @@ class AbuseFilterHooks { return true; } - $vars->addHolders( - AbuseFilter::generateUserVars( $wgUser ), - AbuseFilter::generateTitleVars( $oldTitle, 'MOVED_FROM' ), - AbuseFilter::generateTitleVars( $newTitle, 'MOVED_TO' ) - ); - $vars->setVar( 'SUMMARY', $reason ); - $vars->setVar( 'ACTION', 'move' ); + $status = new Status(); + self::onMovePageCheckPermissions( $oldTitle, $newTitle, $wgUser, $reason, $status ); + if ( !$status->isOK() ) { + $error = $status->getHTML(); + } - $filter_result = AbuseFilter::filterAction( $vars, $oldTitle ); - - $error = $filter_result->isOK() ? '' : $filter_result->getWikiText(); - return $filter_result->isOK(); + return $status->isOK(); } /** diff --git a/AbuseFilter.php b/AbuseFilter.php index 252cea01b..7a81392f1 100644 --- a/AbuseFilter.php +++ b/AbuseFilter.php @@ -78,6 +78,7 @@ if ( defined( 'MW_SUPPORTS_CONTENTHANDLER' ) ) { $wgHooks['GetAutoPromoteGroups'][] = 'AbuseFilterHooks::onGetAutoPromoteGroups'; $wgHooks['AbortMove'][] = 'AbuseFilterHooks::onAbortMove'; +$wgHooks['MovePageCheckPermissions'][] = 'AbuseFilterHooks::onMovePageCheckPermissions'; $wgHooks['AbortNewAccount'][] = 'AbuseFilterHooks::onAbortNewAccount'; $wgHooks['AbortAutoAccount'][] = 'AbuseFilterHooks::onAbortAutoAccount'; $wgHooks['ArticleDelete'][] = 'AbuseFilterHooks::onArticleDelete';