r62402 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62401‎ | r62402 | r62403 >
Date:00:09, 13 February 2010
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Start of blanket coverage of dieUsageMsg in getPossibleErrors

Only basic ones done.

Couple of other modules done manually
Modified paths:
  • /trunk/phase3/includes/api/ApiEmailUser.php (modified) (history)
  • /trunk/phase3/includes/api/ApiFormatXml.php (modified) (history)
  • /trunk/phase3/includes/api/ApiLogin.php (modified) (history)
  • /trunk/phase3/includes/api/ApiMain.php (modified) (history)
  • /trunk/phase3/includes/api/ApiPurge.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQuerySiteinfo.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUnblock.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUpload.php (modified) (history)
  • /trunk/phase3/includes/api/ApiUserrights.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQuerySiteinfo.php
@@ -482,6 +482,12 @@
483483 return 'Return general information about the site.';
484484 }
485485
 486+ public function getPossibleErrors() {
 487+ return array_merge( parent::getPossibleErrors(), array(
 488+ array( 'code' => 'includeAllDenied', 'info' => 'Cannot view all servers info unless $wgShowHostnames is true', ),
 489+ ) );
 490+ }
 491+
486492 protected function getExamples() {
487493 return array(
488494 'api.php?action=query&meta=siteinfo&siprop=general|namespaces|namespacealiases|statistics',
Index: trunk/phase3/includes/api/ApiPurge.php
@@ -102,6 +102,13 @@
103103 'Purge the cache for the given titles.'
104104 );
105105 }
 106+
 107+ public function getPossibleErrors() {
 108+ return array_merge( parent::getPossibleErrors(), array(
 109+ array( 'cantpurge' ),
 110+ array( 'missingparam', 'titles' ),
 111+ ) );
 112+ }
106113
107114 protected function getExamples() {
108115 return array(
Index: trunk/phase3/includes/api/ApiUserrights.php
@@ -105,6 +105,14 @@
106106 'Add/remove a user to/from groups',
107107 );
108108 }
 109+
 110+ public function getPossibleErrors() {
 111+ return array_merge( parent::getPossibleErrors(), array(
 112+ array( 'missingparam', 'user' ),
 113+ array( 'missingparam', 'token' ),
 114+ array( 'sessionfailure' ),
 115+ ) );
 116+ }
109117
110118 protected function getExamples() {
111119 return array (
Index: trunk/phase3/includes/api/ApiUnblock.php
@@ -108,6 +108,16 @@
109109 'Unblock a user.'
110110 );
111111 }
 112+
 113+ public function getPossibleErrors() {
 114+ return array_merge( parent::getPossibleErrors(), array(
 115+ array( 'unblock-notarget' ),
 116+ array( 'unblock-idanduser' ),
 117+ array( 'missingparam', 'token' ),
 118+ array( 'sessionfailure' ),
 119+ array( 'cantunblock' ),
 120+ ) );
 121+ }
112122
113123 protected function getExamples() {
114124 return array (
Index: trunk/phase3/includes/api/ApiLogin.php
@@ -167,6 +167,21 @@
168168 'This is to prevent password guessing by automated password crackers.'
169169 );
170170 }
 171+
 172+ public function getPossibleErrors() {
 173+ return array_merge( parent::getPossibleErrors(), array (
 174+ array( 'code' => 'NoName', 'info' => 'You didn\'t set the lgname parameter' ),
 175+ array( 'code' => 'Illegal', 'info' => ' You provided an illegal username' ),
 176+ array( 'code' => 'NotExists', 'info' => ' The username you provided doesn\'t exist' ),
 177+ array( 'code' => 'EmptyPass', 'info' => ' You didn\'t set the lgpassword parameter or you left it empty' ),
 178+ array( 'code' => 'WrongPass', 'info' => ' The password you provided is incorrect' ),
 179+ array( 'code' => 'WrongPluginPass', 'info' => 'Same as `WrongPass", returned when an authentication plugin rather than MediaWiki itself rejected the password' ),
 180+ array( 'code' => 'CreateBlocked', 'info' => 'The wiki tried to automatically create a new account for you, but your IP address has been blocked from account creation' ),
 181+ array( 'code' => 'Throttled', 'info' => 'You\'ve logged in too many times in a short time' ),
 182+ array( 'code' => 'Blocked', 'info' => 'User is blocked' ),
 183+ ) );
 184+;
 185+ }
171186
172187 protected function getExamples() {
173188 return array(
Index: trunk/phase3/includes/api/ApiFormatXml.php
@@ -190,7 +190,6 @@
191191 );
192192 }
193193
194 -
195194 public function getDescription() {
196195 return 'Output data in XML format' . parent :: getDescription();
197196 }
Index: trunk/phase3/includes/api/ApiMain.php
@@ -539,6 +539,12 @@
540540 '',
541541 );
542542 }
 543+
 544+ public function getPossibleErrors() {
 545+ return array_merge( parent::getPossibleErrors(), array(
 546+ array( 'readonlytext' ),
 547+ ) );
 548+ }
543549
544550 /**
545551 * Returns an array of strings with credits for the API
Index: trunk/phase3/includes/api/ApiEmailUser.php
@@ -103,6 +103,15 @@
104104 'Email a user.'
105105 );
106106 }
 107+
 108+ public function getPossibleErrors() {
 109+ return array_merge( parent::getPossibleErrors(), array(
 110+ array( 'usermaildisabled' ),
 111+ array( 'missingparam', 'target' ),
 112+ array( 'missingparam', 'text' ),
 113+ array( 'missingparam', 'token' ),
 114+ ) );
 115+ }
107116
108117 protected function getExamples() {
109118 return array (
Index: trunk/phase3/includes/api/ApiUpload.php
@@ -326,6 +326,21 @@
327327 'log out and then log back in). Also you must get and send an edit token before doing any upload stuff.'
328328 );
329329 }
 330+
 331+ public function getPossibleErrors() {
 332+ return array_merge( parent::getPossibleErrors(), array(
 333+ array( 'uploaddisabled' ),
 334+ array( 'missingparam', 'token' ),
 335+ array( 'sessionfailure' ),
 336+ array( 'invalid-session-key' ),
 337+ array( 'uploaddisabled' ),
 338+ array( 'badaccess-groups' ),
 339+ array( 'missingparam', 'filename' ),
 340+ array( 'mustbeloggedin', 'upload' ),
 341+ array( 'badaccess-groups' ),
 342+ array( 'badaccess-groups' ),
 343+ ) );
 344+ }
330345
331346 protected function getExamples() {
332347 return array(

Follow-up revisions

RevisionCommit summaryAuthorDate
r62460Whitespace fixes for r62402catrope13:37, 14 February 2010

Comments

#Comment by Reedy (talk | contribs)   00:15, 13 February 2010

As a side thought... It might be worth moving the "token requiring" modules down a level or 2.. Having a base (or lower level property - requiresToken, then we can handle the error higher up, and then only have the getPossibleErrors for it lower) property

#Comment by Catrope (talk | contribs)   13:35, 14 February 2010

Would be nice to move token checking down as well, note that there's salts involved though.

#Comment by Reedy (talk | contribs)   15:36, 14 February 2010

Updated bug 21991 to cater for these comments (that's on the same lines, reducing the duplication)

#Comment by Bawolff (talk | contribs)   05:10, 6 March 2011

For the ApiLogin module, none of those error codes are dieUsageMsg errors. (They're all passed as a property of result in the response). Is it intentional that you added them there?

#Comment by Reedy (talk | contribs)   14:31, 6 March 2011

I think it was literally the simplest way (at the time) I could find to express that information...

If you've got any better ideas, I'm open to suggestions

#Comment by Bawolff (talk | contribs)   16:58, 6 March 2011

Not really. I just noticed that r83371 didn't add to the array, but I wasn't sure if it was intentional that the array was there in the first place.

Status & tagging log