From 1f4ddb930db3298c0f1630f03acb895a3b6971d0 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Fri, 18 Jan 2008 15:52:40 +0000 Subject: [PATCH] Core: * 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() --- includes/Article.php | 12 +------ includes/Title.php | 9 ++--- includes/api/ApiBase.php | 14 +++++++- includes/api/ApiDelete.php | 2 +- includes/api/ApiMove.php | 69 +++++++------------------------------- 5 files changed, 33 insertions(+), 73 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 27a57f350e..824ccacda3 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -2318,14 +2318,7 @@ class Article { * @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; @@ -2340,9 +2333,6 @@ class Article { 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; diff --git a/includes/Title.php b/includes/Title.php index 7ff1db9d9a..99cc6d5c43 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2308,10 +2308,11 @@ class Title { 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; diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index d690603cfe..da633655d4 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -574,20 +574,32 @@ abstract class ApiBase { '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''") ); diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php index 1c40301270..922e58d7ae 100644 --- a/includes/api/ApiDelete.php +++ b/includes/api/ApiDelete.php @@ -62,7 +62,7 @@ class ApiDelete extends ApiBase { 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); diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php index 2fc8fb106d..1ad5d55ed4 100644 --- a/includes/api/ApiMove.php +++ b/includes/api/ApiMove.php @@ -46,55 +46,33 @@ class ApiMove extends ApiBase { $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'] = ''; @@ -111,31 +89,10 @@ class ApiMove extends ApiBase { } // 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); -- 2.20.1