* (bug 19721) API action=help should have a way to just list for a specific module
authorSam Reed <reedy@users.mediawiki.org>
Sat, 8 May 2010 11:45:41 +0000 (11:45 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Sat, 8 May 2010 11:45:41 +0000 (11:45 +0000)
RELEASE-NOTES
includes/api/ApiHelp.php
includes/api/ApiMain.php
includes/api/ApiQuery.php

index 991df1a..b52a74d 100644 (file)
@@ -163,6 +163,7 @@ in a negative namespace (which is invalid).
 * (bug 22868) don't list infinite block expiry date as "now" in API logevents
 * (bug 22290) prop=revisions now outputs "comment" field even when comment
   is empty, for consistency with list=recentchanges
+* (bug 19721) API action=help should have a way to just list for a specific module
 
 === Languages updated in 1.17 ===
 
index 761143f..d16fd29 100644 (file)
@@ -40,10 +40,67 @@ class ApiHelp extends ApiBase {
        }
 
        /**
-        * Stub module for displaying help when no parameters are given
+        * Module for displaying help
         */
        public function execute() {
-               $this->dieUsage( '', 'help' );
+               // Get parameters
+               $params = $this->extractRequestParams();
+               
+               if ( !isset( $params['modules'] ) && !isset( $params['querymodules'] ) ) {
+                       $this->dieUsage( '', 'help' );
+               }
+               
+               $this->getMain()->setHelp();
+               
+               $result = $this->getResult();
+               $queryObj = new ApiQuery( $this->getMain(), 'query' );
+               $r = array();
+               if ( is_array( $params['modules'] ) ) {
+                       $modArr = $this->getMain()->getModules();
+
+                       foreach ( $params['modules'] as $m ) {
+                               if ( !isset( $modArr[$m] ) ) {
+                                       $r[] = array( 'name' => $m, 'missing' => '' );
+                                       continue;
+                               }
+                               $module = new $modArr[$m]( $this->getMain(), $m );
+
+                               $r[] = $this->buildModuleHelp( $module, 'action' );
+                       }
+               }
+
+               if ( is_array( $params['querymodules'] ) ) {
+                       $qmodArr = $queryObj->getModules();
+
+                       foreach ( $params['querymodules'] as $qm ) {
+                               if ( !isset( $qmodArr[$qm] ) ) {
+                                       $r[] = array( 'name' => $qm, 'missing' => '' );
+                                       continue;
+                               }
+                               $module = new $qmodArr[$qm]( $this, $qm );
+                               $type = $queryObj->getModuleType( $qm );
+                               
+                               if ( $type === null ) {
+                                       $r[] = array( 'name' => $qm, 'missing' => '' );
+                                       continue;
+                               }
+                               
+                               $r[] = $this->buildModuleHelp( $module, $type );
+                       }
+               }
+               $result->setIndexedTagName( $r, 'module' );
+               $result->addValue( null, $this->getModuleName(), $r );
+       }
+       
+       private function buildModuleHelp( $module, $type ) {
+               $msg = ApiMain::makeHelpMsgHeader( $module, $type );
+               
+               $msg2 = $module->makeHelpMsg();
+               if ( $msg2 !== false ) {
+                       $msg .= $msg2;
+               }
+               
+               return $msg;
        }
 
        public function shouldCheckMaxlag() {
@@ -53,10 +110,39 @@ class ApiHelp extends ApiBase {
        public function isReadMode() {
                return false;
        }
+       
+       public function getAllowedParams() {
+               return array(
+                       'modules' => array(
+                               ApiBase::PARAM_ISMULTI => true
+                       ),
+                       'querymodules' => array(
+                               ApiBase::PARAM_ISMULTI => true
+                       ),
+               );
+       }
+
+       public function getParamDescription() {
+               return array(
+                       'modules' => 'List of module names (value of the action= parameter)',
+                       'querymodules' => 'List of query module names (value of prop=, meta= or list= parameter)',
+               );
+       }
 
        public function getDescription() {
                return array(
-                       'Display this help screen.'
+                       'Display this help screen. Or the help screen for the specified module'
+               );
+       }
+       
+       protected function getExamples() {
+               return array(
+                       'Whole help page:',
+                       '  api.php?action=help',
+                       'Module help page:',
+                       '  api.php?action=help&modules=protect',
+                       'Query modules help page:',
+                       '  api.php?action=help&querymodules=categorymembers',
                );
        }
 
index edfd2d3..fb99be9 100644 (file)
@@ -674,13 +674,19 @@ class ApiMain extends ApiBase {
                        'or file a bug report at http://bugzilla.wikimedia.org/'
                );
        }
+       /**
+        * Sets whether the pretty-printer should format *bold* and $italics$
+        */
+       public function setHelp( $help = true ) {
+               $this->mPrinter->setHelp( $help );
+       }
 
        /**
         * Override the parent to generate help messages for all available modules.
         */
        public function makeHelpMsg() {
                global $wgMemc, $wgAPICacheHelp, $wgAPICacheHelpTimeout;
-               $this->mPrinter->setHelp();
+               $this->setHelp();
                // Get help text from cache if present
                $key = wfMemcKey( 'apihelp', $this->getModuleName(),
                        SpecialVersion::getVersion( 'nodb' ) .
@@ -699,7 +705,7 @@ class ApiMain extends ApiBase {
        }
 
        public function reallyMakeHelpMsg() {
-               $this->mPrinter->setHelp();
+               $this->setHelp();
 
                // Use parent to make default message for the main module
                $msg = parent::makeHelpMsg();
@@ -737,7 +743,6 @@ class ApiMain extends ApiBase {
 
                $msg .= "\n*** Credits: ***\n   " . implode( "\n   ", $this->getCredits() ) . "\n";
 
-
                return $msg;
        }
 
index 16e0352..ed84a70 100644 (file)
@@ -171,6 +171,27 @@ class ApiQuery extends ApiBase {
        function getModules() {
                return array_merge( $this->mQueryPropModules, $this->mQueryListModules, $this->mQueryMetaModules );
        }
+       
+       /**
+        * Get whether the specified module is a prop, list or a meta query module
+        * @param $moduleName string Name of the module to find type for
+        * @return mixed string or null
+        */
+       function getModuleType( $moduleName ) {
+               if ( array_key_exists ( $moduleName, $this->mQueryPropModules ) ) {
+                       return 'prop';
+               }
+               
+               if ( array_key_exists ( $moduleName, $this->mQueryListModules ) ) {
+                       return 'list';
+               }
+               
+               if ( array_key_exists ( $moduleName, $this->mQueryMetaModules ) ) {
+                       return 'meta';
+               }
+               
+               return null;
+       }
 
        public function getCustomPrinter() {
                // If &exportnowrap is set, use the raw formatter