53 parent::__construct( $main, $action );
54 $this->userFactory = $userFactory;
61 $this->helpFormat =
$params[
'helpformat'];
63 $this->context->
setUser( $this->userFactory->newAnonymous() );
66 if ( is_array(
$params[
'modules'] ) ) {
72 if ( str_ends_with(
$path,
'+*' ) || str_ends_with(
$path,
' *' ) ) {
76 } elseif ( str_ends_with(
$path,
'+**' ) || str_ends_with(
$path,
' **' ) ) {
95 $submodules = $this->listAllSubmodules( $module, $recursive );
97 $modules = array_merge( $modules, $submodules );
99 $this->
addWarning( [
'apierror-badmodule-nosubmodules', $path ],
'badmodule' );
109 if ( is_array(
$params[
'querymodules'] ) ) {
110 $queryModules =
$params[
'querymodules'];
111 foreach ( $queryModules as $m ) {
112 $modules[] =
'query+' . $m;
118 if ( is_array(
$params[
'formatmodules'] ) ) {
119 $formatModules =
$params[
'formatmodules'];
120 foreach ( $formatModules as $m ) {
127 $modules = array_unique( $modules );
131 foreach ( $modules as $m ) {
148 $key =
'querymodules';
150 if ( in_array( $module->
getModuleName(), $formatModules ) ) {
151 $key =
'formatmodules';
154 $item = $this->getModuleInfo( $module );
156 $item[
'querytype'] = $item[
'group'];
158 $res[$key][] = $item;
162 $result->addValue( [ $this->
getModuleName() ],
'helpformat', $this->helpFormat );
164 foreach ( $res as $key => $stuff ) {
165 ApiResult::setIndexedTagName( $res[$key],
'module' );
169 $res[
'mainmodule'] = $this->getModuleInfo( $this->
getMain() );
172 if (
$params[
'pagesetmodule'] ) {
174 $res[
'pagesetmodule'] = $this->getModuleInfo( $pageSet );
175 unset( $res[
'pagesetmodule'][
'name'] );
176 unset( $res[
'pagesetmodule'][
'path'] );
177 unset( $res[
'pagesetmodule'][
'group'] );
189 private function listAllSubmodules(
ApiBase $module, $recursive ) {
193 $names = $manager->getNames();
195 foreach ( $names as $name ) {
196 $submodule = $manager->getModule( $name );
197 $paths[] = $submodule->getModulePath();
198 if ( $recursive && $submodule->getModuleManager() ) {
199 $paths = array_merge( $paths, $this->listAllSubmodules( $submodule, $recursive ) );
213 switch ( $this->helpFormat ) {
219 foreach ( $msgs as $m ) {
220 $ret[] = $m->setContext( $this->context )->text();
222 $res[$key] = implode(
"\n\n", $ret );
224 $res[$key] = preg_replace(
'!^(([*#:;])[^\n]*)\n\n(?=\2)!m',
"$1\n", $res[$key] );
230 foreach ( $msgs as $m ) {
231 $ret[] = $m->setContext( $this->context )->parseAsBlock();
233 $ret = implode(
"\n", $ret );
235 $ret = preg_replace(
'!\s*</([oud]l)>\s*<\1>\s*!',
"\n", $ret );
237 $res[$key] = Parser::stripOuterParagraph( $ret );
242 foreach ( $msgs as $m ) {
244 'key' => $m->getKey(),
245 'params' => $m->getParams(),
247 ApiResult::setIndexedTagName( $a[
'params'],
'param' );
249 $a[
'forvalue'] = $m->getParamValue();
253 ApiResult::setIndexedTagName( $res[$key],
'msg' );
262 private function getModuleInfo( $module ) {
265 $paramValidator = $module->
getMain()->getParamValidator();
268 $ret[
'classname'] = get_class( $module );
269 $ret[
'path'] =
$path;
270 if ( !$module->
isMain() ) {
271 $ret[
'group'] = $module->
getParent()->getModuleManager()->getModuleGroup(
279 $ret[
'source'] = $sourceInfo[
'name'];
280 if ( isset( $sourceInfo[
'namemsg'] ) ) {
281 $ret[
'sourcename'] = $this->context->msg( $sourceInfo[
'namemsg'] )->text();
283 $ret[
'sourcename'] = $ret[
'source'];
286 $link = SpecialPage::getTitleFor(
'Version',
'License/' . $sourceInfo[
'name'] )->getFullURL();
287 if ( isset( $sourceInfo[
'license-name'] ) ) {
288 $ret[
'licensetag'] = $sourceInfo[
'license-name'];
289 $ret[
'licenselink'] = (string)$link;
290 } elseif ( ExtensionInfo::getLicenseFileNames( dirname( $sourceInfo[
'path'] ) ) ) {
291 $ret[
'licenselink'] = (string)$link;
302 if ( isset( $ret[
'helpurls'][0] ) && $ret[
'helpurls'][0] === false ) {
303 $ret[
'helpurls'] = [];
308 if ( $this->helpFormat !==
'none' ) {
309 $ret[
'examples'] = [];
311 foreach ( $examples as $qs => $msg ) {
321 if ( isset( $item[
'description'] ) ) {
322 if ( is_array( $item[
'description'] ) ) {
323 $item[
'description'] = $item[
'description'][0];
328 $ret[
'examples'][] = $item;
333 $ret[
'parameters'] = [];
334 $ret[
'templatedparameters'] = [];
338 foreach (
$params as $name => $settings ) {
339 $settings = $paramValidator->normalizeSettings( $settings );
346 if ( !empty( $settings[ApiBase::PARAM_TEMPLATE_VARS] ) ) {
351 if ( isset( $paramDesc[$name] ) ) {
355 foreach ( $paramValidator->getParamInfo( $module, $name, $settings, [] ) as $k => $v ) {
359 if ( $name ===
'token' && $module->
needsToken() ) {
363 if ( $item[
'type'] ===
'NULL' ) {
365 $item[
'type'] =
'string';
366 } elseif ( is_array( $item[
'type'] ) ) {
371 if ( !empty( $settings[ApiBase::PARAM_HELP_MSG_INFO] ) ) {
373 foreach ( $settings[ApiBase::PARAM_HELP_MSG_INFO] as $i ) {
374 $tag = array_shift( $i );
379 $info[
'values'] = $i;
383 $this->context->msg(
"apihelp-{$path}-paraminfo-{$tag}" )
384 ->numParams( count( $i ) )
385 ->params( $this->context->getLanguage()->commaList( $i ) )
389 $item[
'info'][] = $info;
394 $key = empty( $settings[ApiBase::PARAM_TEMPLATE_VARS] ) ?
'parameters' :
'templatedparameters';
395 $ret[$key][] = $item;
401 if ( $dynamicParams !==
null ) {
402 if ( $this->helpFormat ===
'none' ) {
403 $ret[
'dynamicparameters'] =
true;
423 $querymodules = $this->
getMain()->getModuleManager()
424 ->getModule(
'query' )->getModuleManager()->getNames();
425 sort( $querymodules );
426 $formatmodules = $this->
getMain()->getModuleManager()->getNames(
'format' );
427 sort( $formatmodules );
431 ParamValidator::PARAM_ISMULTI =>
true,
434 ParamValidator::PARAM_DEFAULT =>
'none',
435 ParamValidator::PARAM_TYPE => [
'html',
'wikitext',
'raw',
'none' ],
439 ParamValidator::PARAM_DEPRECATED =>
true,
440 ParamValidator::PARAM_ISMULTI =>
true,
441 ParamValidator::PARAM_TYPE => $querymodules,
444 ParamValidator::PARAM_DEPRECATED =>
true,
447 ParamValidator::PARAM_DEPRECATED =>
true,
450 ParamValidator::PARAM_DEPRECATED =>
true,
451 ParamValidator::PARAM_ISMULTI =>
true,
452 ParamValidator::PARAM_TYPE => $formatmodules,
459 'action=paraminfo&modules=parse|phpfm|query%2Ballpages|query%2Bsiteinfo'
460 =>
'apihelp-paraminfo-example-1',
461 'action=paraminfo&modules=query%2B*'
462 =>
'apihelp-paraminfo-example-2',
467 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Parameter_information';
array $params
The job parameters.
This abstract class implements many basic API functions, and is the base of all API classes.
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
getModuleFromPath( $path)
Get a module from its module path.
static makeMessage( $msg, IContextSource $context, array $params=null)
Create a Message from a string or array.
getParent()
Get the parent of this module.
getHelpUrls()
Return links to more detailed help pages about the module.
getModuleManager()
Get the module manager, or null if this module has no submodules.
getMain()
Get the main module.
getExamplesMessages()
Returns usage examples for this module.
getModuleSourceInfo()
Returns information about the source of this module, if known.
isMain()
Returns true if this module is the main module ($this === $this->mMainModule), false otherwise.
getFinalDescription()
Get the final module description, after hooks have had a chance to tweak it as needed.
const PARAM_TEMPLATE_VARS
(array) Indicate that this is a templated parameter, and specify replacements.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
needsToken()
Returns the token type this module requires in order to execute.
getModulePath()
Get the path to this module.
getHelpFlags()
Generates the list of flags for the help screen and for action=paraminfo.
getFinalParams( $flags=0)
Get the final list of parameters, after hooks have had a chance to tweak it as needed.
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
getModuleName()
Get the name of the module being executed by this instance.
getFinalParamDescription()
Get final parameter descriptions, after hooks have had a chance to tweak it as needed.
dynamicParameterDocumentation()
Indicate if the module supports dynamically-determined parameters that cannot be included in self::ge...
Message subclass that prepends wikitext for API help.
This is the main API class, used for both external and internal processing.
This class contains a list of pages that the client has requested.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
isReadMode()
Indicates whether this module requires read rights.
getHelpUrls()
Return links to more detailed help pages about the module.
__construct(ApiMain $main, $action, UserFactory $userFactory)
formatHelpMessages(array &$res, $key, array $msgs, $joinLists=false)
getExamplesMessages()
Returns usage examples for this module.
static setSubelementsList(array &$arr, $names)
Causes the elements with the specified names to be output as subelements rather than attributes.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
Exception used to abort API execution with an error.
getStatusValue()
Fetch the error status.
Group all the pieces relevant to the context of a request into one instance.
Parent class for all special pages.