API: Add a "submodule" param type
authorBrad Jorsch <bjorsch@wikimedia.org>
Thu, 14 Aug 2014 20:12:58 +0000 (16:12 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Tue, 19 Aug 2014 15:25:07 +0000 (11:25 -0400)
This allows action=paraminfo to indicate when a parameter is specifying
a submodule (so clients can detect what the submodule names are). This
will also allow the future action=help HTMLization to easily auto-link
to submodule docs, and will allow ApiSandbox to handle submodules more
generically.

For BC, rather than directly specifying "type": "submodule", it lists
the names of all the submodules as the type and adds an additional
"submodules" indicator on the param info object.

Change-Id: Id31babdc81d970ac781ec11daa3cdafef18ecd5d

RELEASE-NOTES-1.24
includes/api/ApiBase.php
includes/api/ApiMain.php
includes/api/ApiParamInfo.php
includes/api/ApiQuery.php

index d5446ae..ade456c 100644 (file)
@@ -229,6 +229,9 @@ production.
   properly maintain. Also removed the corresponding methods from ApiBase and
   the 'APIGetPossibleErrors' and 'APIGetResultProperties' hooks.
 * Formats dbg, dump, txt, wddx, and yaml are now deprecated.
+* action=paraminfo now indicates when a parameter is specifying a submodule.
+  Internally, a new param type 'submodule' is available to indicate this which
+  automatically queries the list of submodule names from the ApiModuleManager.
 
 === Languages updated in 1.24 ===
 
index db62be0..20d99c4 100644 (file)
@@ -435,6 +435,10 @@ abstract class ApiBase extends ContextSource {
                                                $prompt = 'One value: ';
                                        }
 
+                                       if ( $type === 'submodule' ) {
+                                               $type = $this->getModuleManager()->getNames( $paramName );
+                                               sort( $type );
+                                       }
                                        if ( is_array( $type ) ) {
                                                $choices = array();
                                                $nothingPrompt = '';
@@ -998,6 +1002,9 @@ abstract class ApiBase extends ContextSource {
                        if ( isset( $value ) && $type == 'namespace' ) {
                                $type = MWNamespace::getValidNamespaces();
                        }
+                       if ( isset( $value ) && $type == 'submodule' ) {
+                               $type = $this->getModuleManager()->getNames( $paramName );
+                       }
                }
 
                if ( isset( $value ) && ( $multi || is_array( $type ) ) ) {
index 115c7b0..3919c75 100644 (file)
@@ -1090,11 +1090,11 @@ class ApiMain extends ApiBase {
                return array(
                        'format' => array(
                                ApiBase::PARAM_DFLT => ApiMain::API_DEFAULT_FORMAT,
-                               ApiBase::PARAM_TYPE => $this->mModuleMgr->getNames( 'format' )
+                               ApiBase::PARAM_TYPE => 'submodule',
                        ),
                        'action' => array(
                                ApiBase::PARAM_DFLT => 'help',
-                               ApiBase::PARAM_TYPE => $this->mModuleMgr->getNames( 'action' )
+                               ApiBase::PARAM_TYPE => 'submodule',
                        ),
                        'maxlag' => array(
                                ApiBase::PARAM_TYPE => 'integer'
index 935d5ae..f81f3d9 100644 (file)
@@ -224,7 +224,13 @@ class ApiParamInfo extends ApiBase {
                        }
 
                        if ( isset( $p[ApiBase::PARAM_TYPE] ) ) {
-                               $a['type'] = $p[ApiBase::PARAM_TYPE];
+                               if ( $p[ApiBase::PARAM_TYPE] === 'submodule' ) {
+                                       $a['type'] = $obj->getModuleManager()->getNames( $n );
+                                       sort( $a['type'] );
+                                       $a['submodules'] = '';
+                               } else {
+                                       $a['type'] = $p[ApiBase::PARAM_TYPE];
+                               }
                                if ( is_array( $a['type'] ) ) {
                                        // To prevent sparse arrays from being serialized to JSON as objects
                                        $a['type'] = array_values( $a['type'] );
index 4359201..9ffcf0e 100644 (file)
@@ -510,15 +510,15 @@ class ApiQuery extends ApiBase {
                $result = array(
                        'prop' => array(
                                ApiBase::PARAM_ISMULTI => true,
-                               ApiBase::PARAM_TYPE => $this->mModuleMgr->getNames( 'prop' )
+                               ApiBase::PARAM_TYPE => 'submodule',
                        ),
                        'list' => array(
                                ApiBase::PARAM_ISMULTI => true,
-                               ApiBase::PARAM_TYPE => $this->mModuleMgr->getNames( 'list' )
+                               ApiBase::PARAM_TYPE => 'submodule',
                        ),
                        'meta' => array(
                                ApiBase::PARAM_ISMULTI => true,
-                               ApiBase::PARAM_TYPE => $this->mModuleMgr->getNames( 'meta' )
+                               ApiBase::PARAM_TYPE => 'submodule',
                        ),
                        'indexpageids' => false,
                        'export' => false,