51 parent::__construct( $main, $action );
52 $this->userFactory = $userFactory;
59 $this->helpFormat = $params[
'helpformat'];
61 $this->context->
setUser( $this->userFactory->newAnonymous() );
64 if ( is_array( $params[
'modules'] ) ) {
66 foreach ( $params[
'modules'] as
$path ) {
70 if ( str_ends_with(
$path,
'+*' ) || str_ends_with(
$path,
' *' ) ) {
74 } elseif ( str_ends_with(
$path,
'+**' ) || str_ends_with(
$path,
' **' ) ) {
93 $submodules = $this->listAllSubmodules( $module, $recursive );
97 $this->
addWarning( [
'apierror-badmodule-nosubmodules', $path ],
'badmodule' );
107 if ( is_array( $params[
'querymodules'] ) ) {
108 $queryModules = $params[
'querymodules'];
109 foreach ( $queryModules as $m ) {
116 if ( is_array( $params[
'formatmodules'] ) ) {
117 $formatModules = $params[
'formatmodules'];
118 foreach ( $formatModules as $m ) {
146 $key =
'querymodules';
148 if ( in_array( $module->
getModuleName(), $formatModules ) ) {
149 $key =
'formatmodules';
152 $item = $this->getModuleInfo( $module );
154 $item[
'querytype'] = $item[
'group'];
156 $res[$key][] = $item;
160 $result->addValue( [ $this->
getModuleName() ],
'helpformat', $this->helpFormat );
162 foreach ( $res as $key => $stuff ) {
163 ApiResult::setIndexedTagName( $res[$key],
'module' );
166 if ( $params[
'mainmodule'] ) {
167 $res[
'mainmodule'] = $this->getModuleInfo( $this->
getMain() );
170 if ( $params[
'pagesetmodule'] ) {
172 $res[
'pagesetmodule'] = $this->getModuleInfo( $pageSet );
173 unset( $res[
'pagesetmodule'][
'name'] );
174 unset( $res[
'pagesetmodule'][
'path'] );
175 unset( $res[
'pagesetmodule'][
'group'] );
187 private function listAllSubmodules(
ApiBase $module, $recursive ) {
191 $names = $manager->getNames();
193 foreach ( $names as $name ) {
194 $submodule = $manager->getModule( $name );
195 $paths[] = $submodule->getModulePath();
196 if ( $recursive && $submodule->getModuleManager() ) {
197 $paths = array_merge( $paths, $this->listAllSubmodules( $submodule, $recursive ) );
211 switch ( $this->helpFormat ) {
217 foreach ( $msgs as $m ) {
218 $ret[] = $m->setContext( $this->context )->text();
220 $res[$key] = implode(
"\n\n", $ret );
222 $res[$key] = preg_replace(
'!^(([*#:;])[^\n]*)\n\n(?=\2)!m',
"$1\n", $res[$key] );
228 foreach ( $msgs as $m ) {
229 $ret[] = $m->setContext( $this->context )->parseAsBlock();
231 $ret = implode(
"\n", $ret );
233 $ret = preg_replace(
'!\s*</([oud]l)>\s*<\1>\s*!',
"\n", $ret );
240 foreach ( $msgs as $m ) {
242 'key' => $m->getKey(),
243 'params' => $m->getParams(),
245 ApiResult::setIndexedTagName( $a[
'params'],
'param' );
247 $a[
'forvalue'] = $m->getParamValue();
251 ApiResult::setIndexedTagName( $res[$key],
'msg' );
260 private function getModuleInfo( $module ) {
263 $paramValidator = $module->
getMain()->getParamValidator();
266 $ret[
'classname'] = get_class( $module );
267 $ret[
'path'] =
$path;
268 if ( !$module->
isMain() ) {
269 $ret[
'group'] = $module->
getParent()->getModuleManager()->getModuleGroup(
277 $ret[
'source'] = $sourceInfo[
'name'];
278 if ( isset( $sourceInfo[
'namemsg'] ) ) {
279 $ret[
'sourcename'] = $this->context->msg( $sourceInfo[
'namemsg'] )->text();
281 $ret[
'sourcename'] = $ret[
'source'];
284 $link = SpecialPage::getTitleFor(
'Version',
'License/' . $sourceInfo[
'name'] )->getFullURL();
285 if ( isset( $sourceInfo[
'license-name'] ) ) {
286 $ret[
'licensetag'] = $sourceInfo[
'license-name'];
287 $ret[
'licenselink'] = (string)$link;
288 } elseif ( ExtensionInfo::getLicenseFileNames( dirname( $sourceInfo[
'path'] ) ) ) {
289 $ret[
'licenselink'] = (string)$link;
300 if ( isset( $ret[
'helpurls'][0] ) && $ret[
'helpurls'][0] === false ) {
301 $ret[
'helpurls'] = [];
306 if ( $this->helpFormat !==
'none' ) {
307 $ret[
'examples'] = [];
309 foreach ( $examples as $qs => $msg ) {
319 if ( isset( $item[
'description'] ) ) {
320 if ( is_array( $item[
'description'] ) ) {
321 $item[
'description'] = $item[
'description'][0];
326 $ret[
'examples'][] = $item;
331 $ret[
'parameters'] = [];
332 $ret[
'templatedparameters'] = [];
333 $params = $module->
getFinalParams( ApiBase::GET_VALUES_FOR_HELP );
336 foreach ( $params as $name => $settings ) {
337 $settings = $paramValidator->normalizeSettings( $settings );
344 if ( !empty( $settings[ApiBase::PARAM_TEMPLATE_VARS] ) ) {
349 if ( isset( $paramDesc[$name] ) ) {
353 foreach ( $paramValidator->getParamInfo( $module, $name, $settings, [] ) as $k => $v ) {
357 if ( $name ===
'token' && $module->
needsToken() ) {
361 if ( $item[
'type'] ===
'NULL' ) {
363 $item[
'type'] =
'string';
364 } elseif ( is_array( $item[
'type'] ) ) {
369 if ( !empty( $settings[ApiBase::PARAM_HELP_MSG_INFO] ) ) {
371 foreach ( $settings[ApiBase::PARAM_HELP_MSG_INFO] as $i ) {
372 $tag = array_shift( $i );
377 $info[
'values'] = $i;
381 $this->context->msg(
"apihelp-{$path}-paraminfo-{$tag}" )
382 ->numParams( count( $i ) )
383 ->params( $this->context->getLanguage()->commaList( $i ) )
387 $item[
'info'][] = $info;
392 $key = empty( $settings[ApiBase::PARAM_TEMPLATE_VARS] ) ?
'parameters' :
'templatedparameters';
393 $ret[$key][] = $item;
399 if ( $dynamicParams !==
null ) {
400 if ( $this->helpFormat ===
'none' ) {
401 $ret[
'dynamicparameters'] =
true;
421 $querymodules = $this->
getMain()->getModuleManager()
422 ->getModule(
'query' )->getModuleManager()->getNames();
423 sort( $querymodules );
424 $formatmodules = $this->
getMain()->getModuleManager()->getNames(
'format' );
425 sort( $formatmodules );
429 ParamValidator::PARAM_ISMULTI =>
true,
432 ParamValidator::PARAM_DEFAULT =>
'none',
433 ParamValidator::PARAM_TYPE => [
'html',
'wikitext',
'raw',
'none' ],
437 ParamValidator::PARAM_DEPRECATED =>
true,
438 ParamValidator::PARAM_ISMULTI =>
true,
439 ParamValidator::PARAM_TYPE => $querymodules,
442 ParamValidator::PARAM_DEPRECATED =>
true,
445 ParamValidator::PARAM_DEPRECATED =>
true,
448 ParamValidator::PARAM_DEPRECATED =>
true,
449 ParamValidator::PARAM_ISMULTI =>
true,
450 ParamValidator::PARAM_TYPE => $formatmodules,
457 'action=paraminfo&modules=parse|phpfm|query%2Ballpages|query%2Bsiteinfo'
458 =>
'apihelp-paraminfo-example-1',
459 'action=paraminfo&modules=query%2B*'
460 =>
'apihelp-paraminfo-example-2',
465 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Parameter_information';
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.
Parent class for all special pages.
static stripOuterParagraph( $html)
Strip outer.
Group all the pieces relevant to the context of a request into one instance.