r53132 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53131‎ | r53132 | r53133 >
Date:12:38, 12 July 2009
Author:btongminh
Status:resolved (Comments)
Tags:
Comment:
(bug 18533) Add readonly reason to readonly exception
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiBase.php (modified) (history)
  • /trunk/phase3/includes/api/ApiEditPage.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiEditPage.php
@@ -231,7 +231,7 @@
232232 case EditPage::AS_READ_ONLY_PAGE_LOGGED:
233233 $this->dieUsageMsg(array('noedit'));
234234 case EditPage::AS_READ_ONLY_PAGE:
235 - $this->dieUsageMsg(array('readonlytext'));
 235+ $this->dieReadOnly();
236236 case EditPage::AS_RATE_LIMITED:
237237 $this->dieUsageMsg(array('actionthrottledtext'));
238238 case EditPage::AS_ARTICLE_WAS_DELETED:
Index: trunk/phase3/includes/api/ApiMain.php
@@ -312,9 +312,7 @@
313313 //
314314 // User entered incorrect parameters - print usage screen
315315 //
316 - $errMessage = array (
317 - 'code' => $e->getCodeString(),
318 - 'info' => $e->getMessage());
 316+ $errMessage = $e->getMessageArray();
319317
320318 // Only print the help message when this is for the developer, not runtime
321319 if ($this->mPrinter->getWantsHelp() || $this->mAction == 'help')
@@ -396,7 +394,7 @@
397395 if (!$wgUser->isAllowed('writeapi'))
398396 $this->dieUsageMsg(array('writerequired'));
399397 if (wfReadOnly())
400 - $this->dieUsageMsg(array('readonlytext'));
 398+ $this->dieReadOnly();
401399 }
402400
403401 if (!$this->mInternalMode) {
@@ -703,14 +701,25 @@
704702 class UsageException extends Exception {
705703
706704 private $mCodestr;
 705+ private $mExtraData;
707706
708 - public function __construct($message, $codestr, $code = 0) {
 707+ public function __construct($message, $codestr, $code = 0, $extradata = null) {
709708 parent :: __construct($message, $code);
710709 $this->mCodestr = $codestr;
 710+ $this->mExtraData = $extradata;
711711 }
712712 public function getCodeString() {
713713 return $this->mCodestr;
714714 }
 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+ }
715724 public function __toString() {
716725 return "{$this->getCodeString()}: {$this->getMessage()}";
717726 }
Index: trunk/phase3/includes/api/ApiBase.php
@@ -726,9 +726,9 @@
727727 * @param $errorCode string Error code
728728 * @param $httpRespCode int HTTP response code
729729 */
730 - public function dieUsage($description, $errorCode, $httpRespCode = 0) {
 730+ public function dieUsage($description, $errorCode, $httpRespCode = 0, $extradata = null) {
731731 wfProfileClose();
732 - throw new UsageException($description, $this->encodeParamName($errorCode), $httpRespCode);
 732+ throw new UsageException($description, $this->encodeParamName($errorCode), $httpRespCode, $extradata);
733733 }
734734
735735 /**
@@ -857,6 +857,15 @@
858858 );
859859
860860 /**
 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+ /**
861870 * Output the error message related to a certain array
862871 * @param $error array Element of a getUserPermissionsErrors()-style array
863872 */
Index: trunk/phase3/RELEASE-NOTES
@@ -286,6 +286,7 @@
287287 rather than UI lang
288288 * Added snippet field to list=search output
289289 * (bug 17809) Add number of users in user groups to meta=siteinfo
 290+* (bug 18533) Add readonly reason to readonly exception
290291
291292 === Languages updated in 1.16 ===
292293

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r50130API: (bug 18533) Add readonly message to meta=siteinfo outputcatrope14:24, 2 May 2009

Comments

#Comment by Catrope (talk | contribs)   20:59, 14 July 2009

A problem with this revision is that when 'readonlytext' is returned by getUserPermissionsErrors() or a similar function, the readonly reason isn't added.

#Comment by Bryan (talk | contribs)   21:19, 14 July 2009

A quick grep shows no other readonlytext

#Comment by Catrope (talk | contribs)   21:36, 14 July 2009

A lot of modules do something like

$retval = $title->moveTo($otherTitle); // Or some other function
if($retval !== true)
        $this->dieUsageMsg(current($retval));

Where moveTo() returns array(array('readonlytext')) (coming from Title::getUserPermissionsErrors() or somewhere else)

#Comment by Catrope (talk | contribs)   21:38, 14 July 2009

Argh, I should use the preview button

$retval = $title->moveTo($otherTitle); // Or some other function
if($retval !== true)
        $this->dieUsageMsg(current($retval)); // Or reset(), same effect
#Comment by Bryan (talk | contribs)   21:43, 14 July 2009

The permissions functions do not do readonly checks.

I searched for 'readonlytext' in the entire tree and it only exists in Article::rollback, the API and OutputPage::readOnlyPage.

#Comment by Catrope (talk | contribs)   21:56, 14 July 2009

My bad. Marking OK.

Status & tagging log