54 parent::__construct( $main, $action );
55 $this->userFactory = $userFactory;
62 $this->helpFormat =
$params[
'helpformat'];
64 $this->context->
setUser( $this->userFactory->newAnonymous() );
67 if ( is_array(
$params[
'modules'] ) ) {
73 if ( str_ends_with(
$path,
'+*' ) || str_ends_with(
$path,
' *' ) ) {
77 } elseif ( str_ends_with(
$path,
'+**' ) || str_ends_with(
$path,
' **' ) ) {
96 $submodules = $this->listAllSubmodules( $module, $recursive );
98 $modules = array_merge( $modules, $submodules );
100 $this->
addWarning( [
'apierror-badmodule-nosubmodules', $path ],
'badmodule' );
110 if ( is_array(
$params[
'querymodules'] ) ) {
111 $queryModules =
$params[
'querymodules'];
112 foreach ( $queryModules as $m ) {
113 $modules[] =
'query+' . $m;
119 if ( is_array(
$params[
'formatmodules'] ) ) {
120 $formatModules =
$params[
'formatmodules'];
121 foreach ( $formatModules as $m ) {
128 $modules = array_unique( $modules );
132 foreach ( $modules as $m ) {
149 $key =
'querymodules';
151 if ( in_array( $module->
getModuleName(), $formatModules ) ) {
152 $key =
'formatmodules';
155 $item = $this->getModuleInfo( $module );
157 $item[
'querytype'] = $item[
'group'];
159 $res[$key][] = $item;
163 $result->addValue( [ $this->
getModuleName() ],
'helpformat', $this->helpFormat );
165 foreach ( $res as $key => $stuff ) {
166 ApiResult::setIndexedTagName( $res[$key],
'module' );
170 $res[
'mainmodule'] = $this->getModuleInfo( $this->
getMain() );
173 if (
$params[
'pagesetmodule'] ) {
175 $res[
'pagesetmodule'] = $this->getModuleInfo( $pageSet );
176 unset( $res[
'pagesetmodule'][
'name'] );
177 unset( $res[
'pagesetmodule'][
'path'] );
178 unset( $res[
'pagesetmodule'][
'group'] );
190 private function listAllSubmodules(
ApiBase $module, $recursive ) {
194 $names = $manager->getNames();
196 foreach ( $names as $name ) {
197 $submodule = $manager->getModule( $name );
198 $paths[] = $submodule->getModulePath();
199 if ( $recursive && $submodule->getModuleManager() ) {
200 $paths = array_merge( $paths, $this->listAllSubmodules( $submodule, $recursive ) );
214 switch ( $this->helpFormat ) {
220 foreach ( $msgs as $m ) {
221 $ret[] = $m->setContext( $this->context )->text();
223 $res[$key] = implode(
"\n\n", $ret );
225 $res[$key] = preg_replace(
'!^(([*#:;])[^\n]*)\n\n(?=\2)!m',
"$1\n", $res[$key] );
231 foreach ( $msgs as $m ) {
232 $ret[] = $m->setContext( $this->context )->parseAsBlock();
234 $ret = implode(
"\n", $ret );
236 $ret = preg_replace(
'!\s*</([oud]l)>\s*<\1>\s*!',
"\n", $ret );
238 $res[$key] = Parser::stripOuterParagraph( $ret );
243 foreach ( $msgs as $m ) {
245 'key' => $m->getKey(),
246 'params' => $m->getParams(),
248 ApiResult::setIndexedTagName( $a[
'params'],
'param' );
250 $a[
'forvalue'] = $m->getParamValue();
254 ApiResult::setIndexedTagName( $res[$key],
'msg' );
263 private function getModuleInfo( $module ) {
266 $paramValidator = $module->
getMain()->getParamValidator();
269 $ret[
'classname'] = get_class( $module );
270 $ret[
'path'] =
$path;
271 if ( !$module->
isMain() ) {
272 $ret[
'group'] = $module->
getParent()->getModuleManager()->getModuleGroup(
280 $ret[
'source'] = $sourceInfo[
'name'];
281 if ( isset( $sourceInfo[
'namemsg'] ) ) {
282 $ret[
'sourcename'] = $this->context->msg( $sourceInfo[
'namemsg'] )->text();
284 $ret[
'sourcename'] = $ret[
'source'];
287 $link = SpecialPage::getTitleFor(
'Version',
'License/' . $sourceInfo[
'name'] )->getFullURL();
288 if ( isset( $sourceInfo[
'license-name'] ) ) {
289 $ret[
'licensetag'] = $sourceInfo[
'license-name'];
290 $ret[
'licenselink'] = (string)$link;
291 } elseif ( ExtensionInfo::getLicenseFileNames( dirname( $sourceInfo[
'path'] ) ) ) {
292 $ret[
'licenselink'] = (string)$link;
303 if ( isset( $ret[
'helpurls'][0] ) && $ret[
'helpurls'][0] === false ) {
304 $ret[
'helpurls'] = [];
309 if ( $this->helpFormat !==
'none' ) {
310 $ret[
'examples'] = [];
312 foreach ( $examples as $qs => $msg ) {
322 if ( isset( $item[
'description'] ) ) {
323 if ( is_array( $item[
'description'] ) ) {
324 $item[
'description'] = $item[
'description'][0];
329 $ret[
'examples'][] = $item;
334 $ret[
'parameters'] = [];
335 $ret[
'templatedparameters'] = [];
339 foreach (
$params as $name => $settings ) {
340 $settings = $paramValidator->normalizeSettings( $settings );
347 if ( !empty( $settings[ApiBase::PARAM_TEMPLATE_VARS] ) ) {
352 if ( isset( $paramDesc[$name] ) ) {
356 foreach ( $paramValidator->getParamInfo( $module, $name, $settings, [] ) as $k => $v ) {
360 if ( $name ===
'token' && $module->
needsToken() ) {
364 if ( $item[
'type'] ===
'NULL' ) {
366 $item[
'type'] =
'string';
367 } elseif ( is_array( $item[
'type'] ) ) {
372 if ( !empty( $settings[ApiBase::PARAM_HELP_MSG_INFO] ) ) {
374 foreach ( $settings[ApiBase::PARAM_HELP_MSG_INFO] as $i ) {
375 $tag = array_shift( $i );
380 $info[
'values'] = $i;
384 $this->context->msg(
"apihelp-{$path}-paraminfo-{$tag}" )
385 ->numParams( count( $i ) )
386 ->params( $this->context->getLanguage()->commaList( $i ) )
390 $item[
'info'][] = $info;
395 $key = empty( $settings[ApiBase::PARAM_TEMPLATE_VARS] ) ?
'parameters' :
'templatedparameters';
396 $ret[$key][] = $item;
402 if ( $dynamicParams !==
null ) {
403 if ( $this->helpFormat ===
'none' ) {
404 $ret[
'dynamicparameters'] =
true;
424 $querymodules = $this->
getMain()->getModuleManager()
425 ->getModule(
'query' )->getModuleManager()->getNames();
426 sort( $querymodules );
427 $formatmodules = $this->
getMain()->getModuleManager()->getNames(
'format' );
428 sort( $formatmodules );
432 ParamValidator::PARAM_ISMULTI =>
true,
435 ParamValidator::PARAM_DEFAULT =>
'none',
436 ParamValidator::PARAM_TYPE => [
'html',
'wikitext',
'raw',
'none' ],
440 ParamValidator::PARAM_DEPRECATED =>
true,
441 ParamValidator::PARAM_ISMULTI =>
true,
442 ParamValidator::PARAM_TYPE => $querymodules,
445 ParamValidator::PARAM_DEPRECATED =>
true,
448 ParamValidator::PARAM_DEPRECATED =>
true,
451 ParamValidator::PARAM_DEPRECATED =>
true,
452 ParamValidator::PARAM_ISMULTI =>
true,
453 ParamValidator::PARAM_TYPE => $formatmodules,
460 'action=paraminfo&modules=parse|phpfm|query%2Ballpages|query%2Bsiteinfo'
461 =>
'apihelp-paraminfo-example-1',
462 'action=paraminfo&modules=query%2B*'
463 =>
'apihelp-paraminfo-example-2',
468 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.