Start implementation of bug 18771 - List possible errors in action=paraminfo
authorSam Reed <reedy@users.mediawiki.org>
Thu, 11 Feb 2010 01:13:45 +0000 (01:13 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Thu, 11 Feb 2010 01:13:45 +0000 (01:13 +0000)
Base has empty array() returning method, ApiBlock has implementation of possibleErrors from code above (possibly not complete)

Can be finished incrementally, so serves as a review point for Roan

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

index de5b72c..e11e615 100644 (file)
@@ -964,6 +964,12 @@ abstract class ApiBase {
                return false;
        }
 
+       /**
+       * Returns a list of all possible errors returned by the module
+       */
+       public function possibleErrors() {
+               return array();
+       }
 
        /**
         * Profiling: total module execution time
index c47e179..c061656 100644 (file)
@@ -157,6 +157,17 @@ class ApiBlock extends ApiBase {
                        'Block a user.'
                );
        }
+       
+       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' ) ),
+        );
+       }
 
        protected function getExamples() {
                return array (
index bebc847..719fb55 100644 (file)
@@ -96,6 +96,7 @@ class ApiParamInfo extends ApiBase {
                $retval['description'] = implode( "\n", (array)$obj->getDescription() );
                $retval['version'] = implode( "\n", (array)$obj->getVersion() );
                $retval['prefix'] = $obj->getModulePrefix();
+
                if ( $obj->isReadMode() )
                        $retval['readrights'] = '';
                if ( $obj->isWriteMode() )
@@ -104,9 +105,11 @@ class ApiParamInfo extends ApiBase {
                        $retval['mustbeposted'] = '';
                if ( $obj instanceof ApiQueryGeneratorBase )
                        $retval['generator'] = '';
+
                $allowedParams = $obj->getFinalParams();
                if ( !is_array( $allowedParams ) )
                        return $retval;
+       
                $retval['parameters'] = array();
                $paramDesc = $obj->getFinalParamDescription();
                foreach ( $allowedParams as $n => $p )
@@ -167,6 +170,11 @@ class ApiParamInfo extends ApiBase {
                        $retval['parameters'][] = $a;
                }
                $result->setIndexedTagName( $retval['parameters'], 'param' );
+               
+               // Errors               
+               $retval['errors'] = $obj->possibleErrors();
+               $result->setIndexedTagName( $retval['errors'], 'error' );
+               
                return $retval;
        }