/**
* Check whether a given move operation would be valid.
- * Returns true if ok, or a message key string for an error message
- * if invalid. (Scarrrrry ugly interface this.)
+ * Returns true if ok, or a getUserPermissionsErrors()-like array otherwise
* @param Title &$nt the new title
* @param bool $auth indicates whether $wgUser's permissions
* should be checked
- * @return mixed true on success, message name on failure
+ * @return mixed True on success, getUserPermissionsErrors()-like array on failure
*/
public function isValidMoveOperation( &$nt, $auth = true ) {
if( !$this or !$nt ) {
- return 'badtitletext';
+ return array(array('badtitletext'));
}
if( $this->equals( $nt ) ) {
- return 'selfmove';
+ return array(array('selfmove'));
}
if( !$this->isMovable() || !$nt->isMovable() ) {
- return 'immobile_namespace';
+ return array(array('immobile_namespace'));
}
$oldid = $this->getArticleID();
$newid = $nt->getArticleID();
if ( strlen( $nt->getDBkey() ) < 1 ) {
- return 'articleexists';
+ return array(array('articleexists'));
}
if ( ( '' == $this->getDBkey() ) ||
( !$oldid ) ||
( '' == $nt->getDBkey() ) ) {
- return 'badarticleerror';
+ return array(array('badarticleerror'));
}
// Image-specific checks
$file = wfLocalFile( $this );
if( $file->exists() ) {
if( $nt->getNamespace() != NS_IMAGE ) {
- return 'imagenocrossnamespace';
+ return array(array('imagenocrossnamespace'));
}
if( !File::checkExtensionCompatibility( $file, $nt->getDbKey() ) ) {
- return 'imagetypemismatch';
+ return array(array('imagetypemismatch'));
}
}
}
$nt->getUserPermissionsErrors('move', $wgUser),
$nt->getUserPermissionsErrors('edit', $wgUser));
if($errors !== array())
- return $errors[0][0];
+ return $errors;
}
global $wgUser;
$err = null;
if( !wfRunHooks( 'AbortMove', array( $this, $nt, $wgUser, &$err ) ) ) {
- return 'hookaborted';
+ return array(array('hookaborted', $err));
}
# The move is allowed only if (1) the target doesn't exist, or
if ( 0 != $newid ) { # Target exists; check for validity
if ( ! $this->isValidMoveTarget( $nt ) ) {
- return 'articleexists';
+ return array(array('articleexists'));
}
} else {
$tp = $nt->getTitleProtection();
$right = ( $tp['pt_create_perm'] == 'sysop' ) ? 'protect' : $tp['pt_create_perm'];
if ( $tp and !$wgUser->isAllowed( $right ) ) {
- return 'cantmove-titleprotected';
+ return array(array('cantmove-titleprotected'));
}
}
return true;
* @param string $reason The reason for the move
* @param bool $createRedirect Whether to create a redirect from the old title to the new title.
* Ignored if the user doesn't have the suppressredirect right.
- * @return mixed true on success, message name on failure
+ * @return mixed true on success, getUserPermissionsErrors()-like array on failure
*/
public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true ) {
$err = $this->isValidMoveOperation( $nt, $auth );
- if( is_string( $err ) ) {
+ if( is_array($err) ) {
return $err;
}
'protectedpage' => array('code' => 'protectedpage', 'info' => "You don't have permission to perform this move"),
'hookaborted' => array('code' => 'hookaborted', 'info' => "The modification you tried to make was aborted by an extension hook"),
'cantmove-titleprotected' => array('code' => 'protectedtitle', 'info' => "The destination article has been protected from creation"),
+ 'imagenocrossnamespace' => array('code' => 'nonfilenamespace', 'info' => "Can't move a file to a non-file namespace"),
+ 'imagetypemismatch' => array('code' => 'filetypemismatch', 'info' => "The new file extension doesn't match its type"),
// 'badarticleerror' => shouldn't happen
// 'badtitletext' => shouldn't happen
'ip_range_invalid' => array('code' => 'invalidrange', 'info' => "Invalid IP range"),
$this->dieUsageMsg(current($errors));
$hookErr = null;
- if( !wfRunHooks( 'AbortMove', array( $fromTitle, $toTitle, $wgUser, &$hookErr ) ) )
- $this->dieUsageMsg(array('hookaborted', $hookErr));
$retval = $fromTitle->moveTo($toTitle, true, $params['reason'], !$params['noredirect']);
if($retval !== true)
- $this->dieUsageMsg(array($retval));
+ $this->dieUsageMsg(reset($retval));
$r = array('from' => $fromTitle->getPrefixedText(), 'to' => $toTitle->getPrefixedText(), 'reason' => $params['reason']);
if(!$params['noredirect'] || !$wgUser->isAllowed('suppressredirect'))
$wgUser->removeWatch($toTitle);
}
$this->getResult()->addValue(null, $this->getModuleName(), $r);
-
- // This one is a problem as we don't have a special page, but some
- // extensions may want to do something when the hook has succeeded.
- //wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
}
public function mustBePosted() { return true; }