More of bug 18771 - List possible errors in action=paraminfo
authorSam Reed <reedy@users.mediawiki.org>
Thu, 11 Feb 2010 21:34:35 +0000 (21:34 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Thu, 11 Feb 2010 21:34:35 +0000 (21:34 +0000)
Followup to comments of r62282

includes/api/ApiBase.php
includes/api/ApiBlock.php
includes/api/ApiParamInfo.php

index e11e615..224fecf 100644 (file)
@@ -968,7 +968,31 @@ abstract class ApiBase {
        * Returns a list of all possible errors returned by the module
        */
        public function possibleErrors() {
-               return array();
+               $ret = array( array( 'readrequired' ) );
+               
+               if ( $this->mustBePosted() ) {
+                       $ret = array_merge( $ret, array( array( 'code' => 'mustbeposted', 'info' => 'The {$this->mAction} module requires a POST request' ) ) );
+               }
+                       
+               return $ret;
+       }
+       
+       /**
+       * 
+       */
+       public function parseErrors( $errors ) {
+               $ret = array();
+               
+               foreach ( $errors as $row )
+               {       
+                       if ( isset( $row['code'] ) && isset( $row['info'] ) ) {
+                               $ret[] = $row;
+                       }
+                       else {
+                               $ret[] = $this->parseMsg( $row );
+                       }
+               }
+               return $ret;
        }
 
        /**
index c061656..962f3b5 100644 (file)
@@ -159,14 +159,14 @@ class ApiBlock extends ApiBase {
        }
        
        public function possibleErrors() {
-               return array (
-                       $this->parseMsg( array( 'missingparam', 'user' ) ),
-                       $this->parseMsg( array( 'missingparam', 'token' ) ),
-                       $this->parseMsg( array( 'sessionfailure' ) ),
-                       $this->parseMsg( array( 'cantblock' ) ),
-                       $this->parseMsg( array( 'canthide' ) ),
-                       $this->parseMsg( array( 'cantblock-email' ) ),
-        );
+               return array_merge( parent::possibleErrors(), array(
+                       array( 'missingparam', 'user' ),
+                       array( 'missingparam', 'token' ),
+                       array( 'sessionfailure' ),
+                       array( 'cantblock' ),
+                       array( 'canthide' ),
+                       array( 'cantblock-email' ),
+        ) );
        }
 
        protected function getExamples() {
index 719fb55..1dcd918 100644 (file)
@@ -171,8 +171,9 @@ class ApiParamInfo extends ApiBase {
                }
                $result->setIndexedTagName( $retval['parameters'], 'param' );
                
-               // Errors               
-               $retval['errors'] = $obj->possibleErrors();
+               // Errors
+               $retval['errors'] = $this->parseErrors( $obj->possibleErrors() );
+               
                $result->setIndexedTagName( $retval['errors'], 'error' );
                
                return $retval;