Index: trunk/phase3/includes/api/ApiEditPage.php |
— | — | @@ -231,7 +231,7 @@ |
232 | 232 | case EditPage::AS_READ_ONLY_PAGE_LOGGED: |
233 | 233 | $this->dieUsageMsg(array('noedit')); |
234 | 234 | case EditPage::AS_READ_ONLY_PAGE: |
235 | | - $this->dieUsageMsg(array('readonlytext')); |
| 235 | + $this->dieReadOnly(); |
236 | 236 | case EditPage::AS_RATE_LIMITED: |
237 | 237 | $this->dieUsageMsg(array('actionthrottledtext')); |
238 | 238 | case EditPage::AS_ARTICLE_WAS_DELETED: |
Index: trunk/phase3/includes/api/ApiMain.php |
— | — | @@ -312,9 +312,7 @@ |
313 | 313 | // |
314 | 314 | // User entered incorrect parameters - print usage screen |
315 | 315 | // |
316 | | - $errMessage = array ( |
317 | | - 'code' => $e->getCodeString(), |
318 | | - 'info' => $e->getMessage()); |
| 316 | + $errMessage = $e->getMessageArray(); |
319 | 317 | |
320 | 318 | // Only print the help message when this is for the developer, not runtime |
321 | 319 | if ($this->mPrinter->getWantsHelp() || $this->mAction == 'help') |
— | — | @@ -396,7 +394,7 @@ |
397 | 395 | if (!$wgUser->isAllowed('writeapi')) |
398 | 396 | $this->dieUsageMsg(array('writerequired')); |
399 | 397 | if (wfReadOnly()) |
400 | | - $this->dieUsageMsg(array('readonlytext')); |
| 398 | + $this->dieReadOnly(); |
401 | 399 | } |
402 | 400 | |
403 | 401 | if (!$this->mInternalMode) { |
— | — | @@ -703,14 +701,25 @@ |
704 | 702 | class UsageException extends Exception { |
705 | 703 | |
706 | 704 | private $mCodestr; |
| 705 | + private $mExtraData; |
707 | 706 | |
708 | | - public function __construct($message, $codestr, $code = 0) { |
| 707 | + public function __construct($message, $codestr, $code = 0, $extradata = null) { |
709 | 708 | parent :: __construct($message, $code); |
710 | 709 | $this->mCodestr = $codestr; |
| 710 | + $this->mExtraData = $extradata; |
711 | 711 | } |
712 | 712 | public function getCodeString() { |
713 | 713 | return $this->mCodestr; |
714 | 714 | } |
| 715 | + public function getMessageArray() { |
| 716 | + $result = array ( |
| 717 | + 'code' => $this->mCodestr, |
| 718 | + 'info' => $this->getMessage() |
| 719 | + ); |
| 720 | + if ( is_array( $this->mExtraData ) ) |
| 721 | + $result = array_merge( $result, $this->mExtraData ); |
| 722 | + return $result; |
| 723 | + } |
715 | 724 | public function __toString() { |
716 | 725 | return "{$this->getCodeString()}: {$this->getMessage()}"; |
717 | 726 | } |
Index: trunk/phase3/includes/api/ApiBase.php |
— | — | @@ -726,9 +726,9 @@ |
727 | 727 | * @param $errorCode string Error code |
728 | 728 | * @param $httpRespCode int HTTP response code |
729 | 729 | */ |
730 | | - public function dieUsage($description, $errorCode, $httpRespCode = 0) { |
| 730 | + public function dieUsage($description, $errorCode, $httpRespCode = 0, $extradata = null) { |
731 | 731 | wfProfileClose(); |
732 | | - throw new UsageException($description, $this->encodeParamName($errorCode), $httpRespCode); |
| 732 | + throw new UsageException($description, $this->encodeParamName($errorCode), $httpRespCode, $extradata); |
733 | 733 | } |
734 | 734 | |
735 | 735 | /** |
— | — | @@ -857,6 +857,15 @@ |
858 | 858 | ); |
859 | 859 | |
860 | 860 | /** |
| 861 | + * Helper function for readonly errors |
| 862 | + */ |
| 863 | + public function dieReadOnly() { |
| 864 | + $parsed = $this->parseMsg( array( 'readonlytext' ) ); |
| 865 | + $this->dieUsage($parsed['info'], $parsed['code'], /* http error */ 0, |
| 866 | + array( 'readonlyreason' => wfReadOnlyReason() ) ); |
| 867 | + } |
| 868 | + |
| 869 | + /** |
861 | 870 | * Output the error message related to a certain array |
862 | 871 | * @param $error array Element of a getUserPermissionsErrors()-style array |
863 | 872 | */ |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -286,6 +286,7 @@ |
287 | 287 | rather than UI lang |
288 | 288 | * Added snippet field to list=search output |
289 | 289 | * (bug 17809) Add number of users in user groups to meta=siteinfo |
| 290 | +* (bug 18533) Add readonly reason to readonly exception |
290 | 291 | |
291 | 292 | === Languages updated in 1.16 === |
292 | 293 | |