Use MovePageCheckPermissions hook if possible

Change-Id: Ic5026384b92a0d68d628397ffe1de6e5b6183f02
This commit is contained in:
Kunal Mehta 2014-10-27 11:06:03 -07:00 committed by Aaron Schulz
parent 7388eea9f2
commit 8dc6b9ee99
2 changed files with 42 additions and 13 deletions

View file

@ -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,22 +105,21 @@ 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' );
}
if ( $blacklisted instanceof TitleBlacklistEntry ) {
$err = wfMessage( $blacklisted->getErrorMessage( 'move' ),
$blacklisted->getRaw(),
$old->getFullText(),
$nt->getFullText() )->parse();
return false;
}
public static function abortMove( $old, $nt, $user, &$err, $reason ) {
if ( method_exists( 'MovePage', 'checkPermissions' ) ) {
// Don't use this hook, use MovePageCheckPermissions instead
return true;
}
$status = new Status();
self::onMovePageCheckPermissions( $old, $nt, $user, $reason, $status );
if ( !$status->isOK() ) {
$err = $status->getHTML();
}
return $status->isOK();
}
/**
* Check whether a user name is acceptable,
* and set a message if unacceptable.

View file

@ -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';