diff --git a/TitleBlacklist.hooks.php b/TitleBlacklist.hooks.php index 78379a3d..6050641a 100644 --- a/TitleBlacklist.hooks.php +++ b/TitleBlacklist.hooks.php @@ -68,7 +68,36 @@ class TitleBlacklistHooks { } /** - * AbortMove hook + * MovePageCheckPermissions hook (1.25+) + * + * @param Title $oldTitle + * @param Title $newTitle + * @param User $user + * @param $reason + * @param Status $status + * @return bool + */ + public static function onMovePageCheckPermissions( Title $oldTitle, Title $newTitle, User $user, $reason, Status $status ) { + $titleBlacklist = TitleBlacklist::singleton(); + $blacklisted = $titleBlacklist->userCannot( $newTitle, $user, 'move' ); + if ( !$blacklisted ) { + $blacklisted = $titleBlacklist->userCannot( $oldTitle, $user, 'edit' ); + } + if ( $blacklisted instanceof TitleBlacklistEntry ) { + $status->fatal( $blacklisted->getErrorMessage( 'move' ), + $blacklisted->getRaw(), + $oldTitle->getFullText(), + $newTitle->getFullText() ); + return false; + } + + return true; + } + + /** + * AbortMove hook (<1.24) + * + * @todo: Remove once 1.24 support is dropped * * @param $old Title * @param $nt Title @@ -76,20 +105,19 @@ class TitleBlacklistHooks { * @param $err * @return bool */ - public static function abortMove( $old, $nt, $user, &$err ) { - $titleBlacklist = TitleBlacklist::singleton(); - $blacklisted = $titleBlacklist->userCannot( $nt, $user, 'move' ); - if ( !$blacklisted ) { - $blacklisted = $titleBlacklist->userCannot( $old, $user, 'edit' ); + public static function abortMove( $old, $nt, $user, &$err, $reason ) { + if ( method_exists( 'MovePage', 'checkPermissions' ) ) { + // Don't use this hook, use MovePageCheckPermissions instead + return true; } - if ( $blacklisted instanceof TitleBlacklistEntry ) { - $err = wfMessage( $blacklisted->getErrorMessage( 'move' ), - $blacklisted->getRaw(), - $old->getFullText(), - $nt->getFullText() )->parse(); - return false; + + $status = new Status(); + self::onMovePageCheckPermissions( $old, $nt, $user, $reason, $status ); + if ( !$status->isOK() ) { + $err = $status->getHTML(); } - return true; + + return $status->isOK(); } /** diff --git a/TitleBlacklist.php b/TitleBlacklist.php index 7b5c67d2..f07bb0b0 100644 --- a/TitleBlacklist.php +++ b/TitleBlacklist.php @@ -78,6 +78,7 @@ $wgGroupPermissions['sysop']['tboverride'] = true; $wgHooks['getUserPermissionsErrorsExpensive'][] = 'TitleBlacklistHooks::userCan'; $wgHooks['TitleGetEditNotices'][] = 'TitleBlacklistHooks::displayBlacklistOverrideNotice'; $wgHooks['AbortMove'][] = 'TitleBlacklistHooks::abortMove'; +$wgHooks['MovePageCheckPermissions'][] = 'TitleBlacklistHooks::onMovePageCheckPermissions'; $wgHooks['AbortNewAccount'][] = 'TitleBlacklistHooks::abortNewAccount'; $wgHooks['AbortAutoAccount'][] = 'TitleBlacklistHooks::abortNewAccount'; $wgHooks['EditFilter'][] = 'TitleBlacklistHooks::validateBlacklist';