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 ===
* @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);
}
/**
'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
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:
//
// 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')
if (!$wgUser->isAllowed('writeapi'))
$this->dieUsageMsg(array('writerequired'));
if (wfReadOnly())
- $this->dieUsageMsg(array('readonlytext'));
+ $this->dieReadOnly();
}
if (!$this->mInternalMode) {
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()}";
}