* Using getUserPermissionsErrors() rather than userCan() in Title::isValidMoveOperation()
* Removing blocked check from Article::doRollback(): Title::getUserPermissionsErrors() checks for that already
API:
* Refactoring ApiMove to use new messages system
* Adding more messages to ApiBase::$messageMap
* Removing unused parameter to 'notanarticle' in ApiDelete::execute()
* @return array of errors, each error formatted as
* array(messagekey, param1, param2, ...).
* On success, the array is empty. This array can also be passed to
- * OutputPage::showPermissionsErrorPage(). NOTE: If the user is blocked,
- * 'blocked' is passed as a message, but it doesn't exist. Be sure to check
- * it before calling showPermissionsErrorPage(). The same is true for
- * 'actionthrottledtext', which is passed if the rate limit is passed; and
- * for 'readonlytext', which is passed if the wiki is read-only.
- *
- * FIXME: This is silly, those messages should be possible to output di-
- * rectly.
+ * OutputPage::showPermissionsErrorPage().
*/
public function doRollback( $fromP, $summary, $token, $bot, &$resultDetails ) {
global $wgUser;
if ( $wgUser->pingLimiter('rollback') || $wgUser->pingLimiter() ) {
$errors[] = array( 'actionthrottledtext' );
}
- if ( $wgUser->isBlocked() )
- $errors[] = array( 'blocked' );
-
# If there were errors, bail out now
if(!empty($errors))
return $errors;
return 'badarticleerror';
}
- if ( $auth && (
- !$this->userCan( 'edit' ) || !$nt->userCan( 'edit' ) ||
- !$this->userCan( 'move' ) || !$nt->userCan( 'move' ) ) ) {
- return 'protectedpage';
+ if ( $auth ) {
+ global $wgUser;
+ $errors = $this->getUserPermissionsErrors('move', $wgUser);
+ if($errors !== array())
+ return $errors[0][0];
}
global $wgUser;
'nocreatetext' => array('code' => 'cantcreate-anon', 'info' => "Anonymous users can't create new pages"),
'movenologintext' => array('code' => 'cantmove-anon', 'info' => "Anonymous users can't move pages"),
'movenotallowed' => array('code' => 'cantmove', 'info' => "You don't have permission to move pages"),
+ 'confirmedittiext' => array('code' => 'confirmemail', 'info' => "You must confirm your e-mail address before you can edit"),
+ 'blockedtext' => array('code' => 'blocked', 'info' => "You have been blocked from editing"),
+ 'autoblockedtext' => array('code' => 'autoblocked', 'info' => "Your IP address has been blocked automatically, because it was used by a blocked user"),
// Miscellaneous interface messages
'alreadyrolled' => array('code' => 'alreadyrolled', 'info' => "The page you tried to rollback was already rolled back"),
'cantrollback' => array('code' => 'onlyauthor', 'info' => "The page you tried to rollback only has one author"),
- 'blocked' => array('code' => 'blocked', 'info' => "You have been blocked from editing"),
'readonlytext' => array('code' => 'readonly', 'info' => "The wiki is currently in read-only mode"),
'sessionfailure' => array('code' => 'badtoken', 'info' => "Invalid token"),
'cannotdelete' => array('code' => 'cantdelete', 'info' => "Couldn't delete ``\$1''. Maybe it was deleted already by someone else"),
'notanarticle' => array('code' => 'missingtitle', 'info' => "The page you requested doesn't exist"),
+ 'selfmove' => array('code' => 'selfmove', 'info' => "Can't move a page to itself"),
+ 'immobile_namespace' => array('code' => 'immobilenamespace', 'info' => "You tried to move pages from or to a namespace that is protected from moving"),
+ 'articleexists' => array('code' => 'articleexists', 'info' => "The destination article already exists and is not a redirect to the source article"),
+ '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"),
+ // 'badarticleerror' => shouldn't happen
+ // 'badtitletext' => shouldn't happen
// API-specific messages
'notitle' => array('code' => 'notitle', 'info' => "The title parameter must be set"),
'notoken' => array('code' => 'notoken', 'info' => "The token parameter must be set"),
'nouser' => array('code' => 'nouser', 'info' => "The user parameter must be set"),
+ 'nofrom' => array('code' => 'nofrom', 'info' => "The from parameter must be set"),
+ 'noto' => array('code' => 'noto', 'info' => "The to parameter must be set"),
'invalidtitle' => array('code' => 'invalidtitle', 'info' => "Bad title ``\$1''"),
'invaliduser' => array('code' => 'invaliduser', 'info' => "Invalid username ``\$1''")
);
if(!$titleObj)
$this->dieUsageMsg(array('invalidtitle', $params['title']));
if(!$titleObj->exists())
- $this->dieUsageMsg(array('notanarticle', $params['title']));
+ $this->dieUsageMsg(array('notanarticle'));
$articleObj = new Article($titleObj);
$reason = (isset($params['reason']) ? $params['reason'] : NULL);
$titleObj = NULL;
if(!isset($params['from']))
- $this->dieUsage('The from parameter must be set', 'nofrom');
+ $this->dieUsageMsg(array('nofrom'));
if(!isset($params['to']))
- $this->dieUsage('The to parameter must be set', 'noto');
+ $this->dieUsageMsg(array('noto'));
if(!isset($params['token']))
- $this->dieUsage('The token parameter must be set', 'notoken');
+ $this->dieUsageMsg(array('notoken'));
if(!$wgUser->matchEditToken($params['token']))
- $this->dieUsage('Invalid token', 'badtoken');
-
- if($wgUser->isBlocked())
- $this->dieUsage('You have been blocked from editing', 'blocked');
- if(wfReadOnly())
- $this->dieUsage('The wiki is in read-only mode', 'readonly');
- if($params['noredirect'] && !$wgUser->isAllowed('suppressredirect'))
- $this->dieUsage("You don't have permission to suppress redirect creation", 'nosuppress');
+ $this->dieUsageMsg(array('sessionfailure'));
$fromTitle = Title::newFromText($params['from']);
if(!$fromTitle)
- $this->dieUsage("Bad title ``{$params['from']}''", 'invalidtitle');
+ $this->dieUsageMsg(array('invalidtitle', $params['from']));
if(!$fromTitle->exists())
- $this->dieUsage("``{$params['from']}'' doesn't exist", 'missingtitle');
+ $this->dieUsageMsg(array('notanarticle'));
$fromTalk = $fromTitle->getTalkPage();
$toTitle = Title::newFromText($params['to']);
if(!$toTitle)
- $this->dieUsage("Bad title ``{$params['to']}''", 'invalidtitle');
+ $this->dieUsageMsg(array('invalidtitle', $params['to']));
$toTalk = $toTitle->getTalkPage();
$dbw = wfGetDB(DB_MASTER);
$dbw->begin();
$retval = $fromTitle->moveTo($toTitle, true, $params['reason'], !$params['noredirect']);
if($retval !== true)
- switch($retval)
- {
- // case 'badtitletext': Can't happen
- // case 'badarticleerror': Can't happen
- case 'selfmove':
- $this->dieUsage("Can't move ``{$params['from']}'' to itself", 'selfmove');
- case 'immobile_namespace':
- if($fromTitle->isMovable())
- $this->dieUsage("Pages in the ``{$fromTitle->getNsText()}'' namespace can't be moved", 'immobilenamespace-from');
- $this->dieUsage("Pages in the ``{$toTitle->getNsText()}'' namespace can't be moved", 'immobilenamespace-to');
- case 'articleexists':
- $this->dieUsage("``{$toTitle->getPrefixedText()}'' already exists and is not a redirect to ``{$fromTitle->getPrefixedText()}''", 'targetexists');
- case 'protectedpage':
- $this->dieUsage("You don't have permission to move ``{$fromTitle->getPrefixedText()}'' to ``{$toTitle->getPrefixedText()}''", 'permissiondenied');
- default:
- throw new MWException( "Title::moveTo: Unknown return value ``{$retval}''" );
- }
+ $this->dieUsageMsg(array($retval));
+
$r = array('from' => $fromTitle->getPrefixedText(), 'to' => $toTitle->getPrefixedText(), 'reason' => $params['reason']);
if(!$params['noredirect'])
$r['redirectcreated'] = '';
}
// We're not gonna dieUsage() on failure, since we already changed something
else
- switch($retval)
- {
- case 'immobile_namespace':
- if($fromTalk->isMovable())
- {
- $r['talkmove-error-code'] = 'immobilenamespace-from';
- $r['talkmove-error-info'] = "Pages in the ``{$fromTalk->getNsText()}'' namespace can't be moved";
- }
- else
- {
- $r['talkmove-error-code'] = 'immobilenamespace-to';
- $r['talkmove-error-info'] = "Pages in the ``{$toTalk->getNsText()}'' namespace can't be moved";
- }
- break;
- case 'articleexists':
- $r['talkmove-error-code'] = 'targetexists';
- $r['talkmove-error-info'] = "``{$toTalk->getPrefixedText()}'' already exists and is not a redirect to ``{$fromTalk->getPrefixedText()}''";
- break;
- case 'protectedpage':
- $r['talkmove-error-code'] = 'permissiondenied';
- $r['talkmove-error-info'] = "You don't have permission to move ``{$fromTalk->getPrefixedText()}'' to ``{$toTalk->getPrefixedText()}''";
- default:
- $r['talkmove-error-code'] = 'unknownerror';
- $r['talkmove-error-info'] = "Unknown error ``$retval''";
- }
+ {
+ $r['talkmove-error-code'] = ApiBase::$messageMap[$retval]['code'];
+ $r['talkmove-error-info'] = ApiBase::$messageMap[$retval]['info'];
+ }
}
$dbw->commit(); // Make sure all changes are really written to the DB
$this->getResult()->addValue(null, $this->getModuleName(), $r);