From afa153ae9dec44ee4670daa2883a846a6fc013c0 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Thu, 14 Aug 2014 16:12:58 -0400 Subject: [PATCH] API: Add a "submodule" param type 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 | 3 +++ includes/api/ApiBase.php | 7 +++++++ includes/api/ApiMain.php | 4 ++-- includes/api/ApiParamInfo.php | 8 +++++++- includes/api/ApiQuery.php | 6 +++--- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES-1.24 b/RELEASE-NOTES-1.24 index d5446ae9f6..ade456c1de 100644 --- a/RELEASE-NOTES-1.24 +++ b/RELEASE-NOTES-1.24 @@ -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 === diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index db62be0a0a..20d99c44c9 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -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 ) ) ) { diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index 115c7b0623..3919c755ae 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -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' diff --git a/includes/api/ApiParamInfo.php b/includes/api/ApiParamInfo.php index 935d5ae275..f81f3d9237 100644 --- a/includes/api/ApiParamInfo.php +++ b/includes/api/ApiParamInfo.php @@ -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'] ); diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index 435920197c..9ffcf0e5d3 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -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, -- 2.20.1