From: Bryan Tong Minh Date: Sun, 12 Jul 2009 12:38:03 +0000 (+0000) Subject: (bug 18533) Add readonly reason to readonly exception X-Git-Tag: 1.31.0-rc.0~40995 X-Git-Url: http://git.cyclocoop.org/url?a=commitdiff_plain;h=31d99476185d9d38e44800274793e8bb7ee1c5f4;p=lhc%2Fweb%2Fwiklou.git (bug 18533) Add readonly reason to readonly exception --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 5ec592fd79..2a9ce51523 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -286,6 +286,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN rather than UI lang * Added snippet field to list=search output * (bug 17809) Add number of users in user groups to meta=siteinfo +* (bug 18533) Add readonly reason to readonly exception === Languages updated in 1.16 === diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 32b800f28a..cdd4c5a546 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -726,9 +726,9 @@ abstract class ApiBase { * @param $errorCode string Error code * @param $httpRespCode int HTTP response code */ - public function dieUsage($description, $errorCode, $httpRespCode = 0) { + public function dieUsage($description, $errorCode, $httpRespCode = 0, $extradata = null) { wfProfileClose(); - throw new UsageException($description, $this->encodeParamName($errorCode), $httpRespCode); + throw new UsageException($description, $this->encodeParamName($errorCode), $httpRespCode, $extradata); } /** @@ -856,6 +856,15 @@ abstract class ApiBase { 'undo-failure' => array('code' => 'undofailure', 'info' => 'Undo failed due to conflicting intermediate edits'), ); + /** + * Helper function for readonly errors + */ + public function dieReadOnly() { + $parsed = $this->parseMsg( array( 'readonlytext' ) ); + $this->dieUsage($parsed['info'], $parsed['code'], /* http error */ 0, + array( 'readonlyreason' => wfReadOnlyReason() ) ); + } + /** * Output the error message related to a certain array * @param $error array Element of a getUserPermissionsErrors()-style array diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 09731e7d8f..f3cf492354 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -231,7 +231,7 @@ class ApiEditPage extends ApiBase { case EditPage::AS_READ_ONLY_PAGE_LOGGED: $this->dieUsageMsg(array('noedit')); case EditPage::AS_READ_ONLY_PAGE: - $this->dieUsageMsg(array('readonlytext')); + $this->dieReadOnly(); case EditPage::AS_RATE_LIMITED: $this->dieUsageMsg(array('actionthrottledtext')); case EditPage::AS_ARTICLE_WAS_DELETED: diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index f39a2fcbb2..5a7d3a280a 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -312,9 +312,7 @@ class ApiMain extends ApiBase { // // User entered incorrect parameters - print usage screen // - $errMessage = array ( - 'code' => $e->getCodeString(), - 'info' => $e->getMessage()); + $errMessage = $e->getMessageArray(); // Only print the help message when this is for the developer, not runtime if ($this->mPrinter->getWantsHelp() || $this->mAction == 'help') @@ -396,7 +394,7 @@ class ApiMain extends ApiBase { if (!$wgUser->isAllowed('writeapi')) $this->dieUsageMsg(array('writerequired')); if (wfReadOnly()) - $this->dieUsageMsg(array('readonlytext')); + $this->dieReadOnly(); } if (!$this->mInternalMode) { @@ -703,14 +701,25 @@ class ApiMain extends ApiBase { class UsageException extends Exception { private $mCodestr; + private $mExtraData; - public function __construct($message, $codestr, $code = 0) { + public function __construct($message, $codestr, $code = 0, $extradata = null) { parent :: __construct($message, $code); $this->mCodestr = $codestr; + $this->mExtraData = $extradata; } public function getCodeString() { return $this->mCodestr; } + public function getMessageArray() { + $result = array ( + 'code' => $this->mCodestr, + 'info' => $this->getMessage() + ); + if ( is_array( $this->mExtraData ) ) + $result = array_merge( $result, $this->mExtraData ); + return $result; + } public function __toString() { return "{$this->getCodeString()}: {$this->getMessage()}"; }