X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiParamInfo.php;h=67983e7a3aa080340cd9551f1dfd2fa5d3d7b1e2;hb=47e2bec3611dd78fe8e4b47d2b69452c7ea77f96;hp=c3c9e2176cccf22106a68a49083279545b08d081;hpb=c2c14bb18f6e2f8192e9ac6508ef40f74e69f2bc;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiParamInfo.php b/includes/api/ApiParamInfo.php index c3c9e2176c..67983e7a3a 100644 --- a/includes/api/ApiParamInfo.php +++ b/includes/api/ApiParamInfo.php @@ -46,7 +46,42 @@ class ApiParamInfo extends ApiBase { $this->context->setLanguage( $this->getMain()->getLanguage() ); if ( is_array( $params['modules'] ) ) { - $modules = $params['modules']; + $modules = []; + foreach ( $params['modules'] as $path ) { + if ( $path === '*' || $path === '**' ) { + $path = "main+$path"; + } + if ( substr( $path, -2 ) === '+*' || substr( $path, -2 ) === ' *' ) { + $submodules = true; + $path = substr( $path, 0, -2 ); + $recursive = false; + } elseif ( substr( $path, -3 ) === '+**' || substr( $path, -3 ) === ' **' ) { + $submodules = true; + $path = substr( $path, 0, -3 ); + $recursive = true; + } else { + $submodules = false; + } + + if ( $submodules ) { + try { + $module = $this->getModuleFromPath( $path ); + } catch ( ApiUsageException $ex ) { + foreach ( $ex->getStatusValue()->getErrors() as $error ) { + $this->addWarning( $error ); + } + continue; + } + $submodules = $this->listAllSubmodules( $module, $recursive ); + if ( $submodules ) { + $modules = array_merge( $modules, $submodules ); + } else { + $this->addWarning( [ 'apierror-badmodule-nosubmodules', $path ], 'badmodule' ); + } + } else { + $modules[] = $path; + } + } } else { $modules = []; } @@ -69,13 +104,17 @@ class ApiParamInfo extends ApiBase { $formatModules = []; } + $modules = array_unique( $modules ); + $res = []; foreach ( $modules as $m ) { try { $module = $this->getModuleFromPath( $m ); - } catch ( UsageException $ex ) { - $this->setWarning( $ex->getMessage() ); + } catch ( ApiUsageException $ex ) { + foreach ( $ex->getStatusValue()->getErrors() as $error ) { + $this->addWarning( $error ); + } continue; } $key = 'modules'; @@ -121,6 +160,29 @@ class ApiParamInfo extends ApiBase { $result->addValue( null, $this->getModuleName(), $res ); } + /** + * List all submodules of a module + * @param ApiBase $module + * @param boolean $recursive + * @return string[] + */ + private function listAllSubmodules( ApiBase $module, $recursive ) { + $manager = $module->getModuleManager(); + if ( $manager ) { + $paths = []; + $names = $manager->getNames(); + sort( $names ); + foreach ( $names as $name ) { + $submodule = $manager->getModule( $name ); + $paths[] = $submodule->getModulePath(); + if ( $recursive && $submodule->getModuleManager() ) { + $paths = array_merge( $paths, $this->listAllSubmodules( $submodule, $recursive ) ); + } + } + } + return $paths; + } + /** * @param array $res Result array * @param string $key Result key @@ -162,6 +224,7 @@ class ApiParamInfo extends ApiBase { 'key' => $m->getKey(), 'params' => $m->getParams(), ]; + ApiResult::setIndexedTagName( $a['params'], 'param' ); if ( $m instanceof ApiHelpParamValueMessage ) { $a['forvalue'] = $m->getParamValue(); } @@ -174,7 +237,7 @@ class ApiParamInfo extends ApiBase { /** * @param ApiBase $module - * @return ApiResult + * @return array */ private function getModuleInfo( $module ) { $ret = []; @@ -348,6 +411,30 @@ class ApiParamInfo extends ApiBase { $item['type'] = array_values( $item['type'] ); ApiResult::setIndexedTagName( $item['type'], 't' ); } + + // Add 'allspecifier' if applicable + if ( $item['type'] === 'namespace' ) { + $allowAll = true; + $allSpecifier = ApiBase::ALL_DEFAULT_STRING; + } else { + $allowAll = isset( $settings[ApiBase::PARAM_ALL] ) + ? $settings[ApiBase::PARAM_ALL] + : false; + $allSpecifier = ( is_string( $allowAll ) ? $allowAll : ApiBase::ALL_DEFAULT_STRING ); + } + if ( $allowAll && $item['multi'] && + ( is_array( $item['type'] ) || $item['type'] === 'namespace' ) ) { + $item['allspecifier'] = $allSpecifier; + } + + if ( $item['type'] === 'namespace' && + isset( $settings[ApiBase::PARAM_EXTRA_NAMESPACES] ) && + is_array( $settings[ApiBase::PARAM_EXTRA_NAMESPACES] ) + ) { + $item['extranamespaces'] = $settings[ApiBase::PARAM_EXTRA_NAMESPACES]; + ApiResult::setArrayType( $item['extranamespaces'], 'array' ); + ApiResult::setIndexedTagName( $item['extranamespaces'], 'ns' ); + } } if ( isset( $settings[ApiBase::PARAM_MAX] ) ) { $item['max'] = $settings[ApiBase::PARAM_MAX]; @@ -448,8 +535,10 @@ class ApiParamInfo extends ApiBase { protected function getExamplesMessages() { return [ - 'action=paraminfo&modules=parse|phpfm|query+allpages|query+siteinfo' + 'action=paraminfo&modules=parse|phpfm|query%2Ballpages|query%2Bsiteinfo' => 'apihelp-paraminfo-example-1', + 'action=paraminfo&modules=query%2B*' + => 'apihelp-paraminfo-example-2', ]; }