50 parent::__construct( $main, $action );
51 $this->userFactory = $userFactory;
58 $this->helpFormat = $params[
'helpformat'];
60 $this->context->
setUser( $this->userFactory->newAnonymous() );
63 if ( is_array( $params[
'modules'] ) ) {
65 foreach ( $params[
'modules'] as
$path ) {
69 if ( substr(
$path, -2 ) ===
'+*' || substr(
$path, -2 ) ===
' *' ) {
73 } elseif ( substr(
$path, -3 ) ===
'+**' || substr(
$path, -3 ) ===
' **' ) {
92 $submodules = $this->listAllSubmodules( $module, $recursive );
96 $this->
addWarning( [
'apierror-badmodule-nosubmodules', $path ],
'badmodule' );
106 if ( is_array( $params[
'querymodules'] ) ) {
107 $queryModules = $params[
'querymodules'];
108 foreach ( $queryModules as $m ) {
115 if ( is_array( $params[
'formatmodules'] ) ) {
116 $formatModules = $params[
'formatmodules'];
117 foreach ( $formatModules as $m ) {
145 $key =
'querymodules';
147 if ( in_array( $module->
getModuleName(), $formatModules ) ) {
148 $key =
'formatmodules';
151 $item = $this->getModuleInfo( $module );
153 $item[
'querytype'] = $item[
'group'];
155 $res[$key][] = $item;
159 $result->addValue( [ $this->
getModuleName() ],
'helpformat', $this->helpFormat );
161 foreach (
$res as $key => $stuff ) {
162 ApiResult::setIndexedTagName(
$res[$key],
'module' );
165 if ( $params[
'mainmodule'] ) {
166 $res[
'mainmodule'] = $this->getModuleInfo( $this->
getMain() );
169 if ( $params[
'pagesetmodule'] ) {
171 $res[
'pagesetmodule'] = $this->getModuleInfo( $pageSet );
172 unset(
$res[
'pagesetmodule'][
'name'] );
173 unset(
$res[
'pagesetmodule'][
'path'] );
174 unset(
$res[
'pagesetmodule'][
'group'] );
186 private function listAllSubmodules(
ApiBase $module, $recursive ) {
190 $names = $manager->getNames();
192 foreach ( $names as $name ) {
193 $submodule = $manager->getModule( $name );
194 $paths[] = $submodule->getModulePath();
195 if ( $recursive && $submodule->getModuleManager() ) {
196 $paths = array_merge( $paths, $this->listAllSubmodules( $submodule, $recursive ) );
210 switch ( $this->helpFormat ) {
216 foreach ( $msgs as $m ) {
217 $ret[] = $m->setContext( $this->context )->text();
219 $res[$key] = implode(
"\n\n", $ret );
221 $res[$key] = preg_replace(
'!^(([*#:;])[^\n]*)\n\n(?=\2)!m',
"$1\n",
$res[$key] );
227 foreach ( $msgs as $m ) {
228 $ret[] = $m->setContext( $this->context )->parseAsBlock();
230 $ret = implode(
"\n", $ret );
232 $ret = preg_replace(
'!\s*</([oud]l)>\s*<\1>\s*!',
"\n", $ret );
239 foreach ( $msgs as $m ) {
241 'key' => $m->getKey(),
242 'params' => $m->getParams(),
244 ApiResult::setIndexedTagName( $a[
'params'],
'param' );
246 $a[
'forvalue'] = $m->getParamValue();
250 ApiResult::setIndexedTagName(
$res[$key],
'msg' );
259 private function getModuleInfo( $module ) {
262 $paramValidator = $module->
getMain()->getParamValidator();
265 $ret[
'classname'] = get_class( $module );
266 $ret[
'path'] =
$path;
267 if ( !$module->
isMain() ) {
268 $ret[
'group'] = $module->
getParent()->getModuleManager()->getModuleGroup(
276 $ret[
'source'] = $sourceInfo[
'name'];
277 if ( isset( $sourceInfo[
'namemsg'] ) ) {
278 $ret[
'sourcename'] = $this->context->msg( $sourceInfo[
'namemsg'] )->text();
280 $ret[
'sourcename'] = $ret[
'source'];
284 if ( isset( $sourceInfo[
'license-name'] ) ) {
285 $ret[
'licensetag'] = $sourceInfo[
'license-name'];
286 $ret[
'licenselink'] = (string)$link;
287 } elseif ( ExtensionInfo::getLicenseFileNames( dirname( $sourceInfo[
'path'] ) ) ) {
288 $ret[
'licenselink'] = (string)$link;
299 if ( isset( $ret[
'helpurls'][0] ) && $ret[
'helpurls'][0] === false ) {
300 $ret[
'helpurls'] = [];
305 if ( $this->helpFormat !==
'none' ) {
306 $ret[
'examples'] = [];
308 foreach ( $examples as $qs => $msg ) {
318 if ( isset( $item[
'description'] ) ) {
319 if ( is_array( $item[
'description'] ) ) {
320 $item[
'description'] = $item[
'description'][0];
325 $ret[
'examples'][] = $item;
330 $ret[
'parameters'] = [];
331 $ret[
'templatedparameters'] = [];
332 $params = $module->
getFinalParams( ApiBase::GET_VALUES_FOR_HELP );
335 foreach ( $params as $name => $settings ) {
336 $settings = $paramValidator->normalizeSettings( $settings );
343 if ( !empty( $settings[ApiBase::PARAM_TEMPLATE_VARS] ) ) {
348 if ( isset( $paramDesc[$name] ) ) {
352 foreach ( $paramValidator->getParamInfo( $module, $name, $settings, [] ) as $k => $v ) {
356 if ( $name ===
'token' && $module->
needsToken() ) {
360 if ( $item[
'type'] ===
'NULL' ) {
362 $item[
'type'] =
'string';
363 } elseif ( is_array( $item[
'type'] ) ) {
368 if ( !empty( $settings[ApiBase::PARAM_HELP_MSG_INFO] ) ) {
370 foreach ( $settings[ApiBase::PARAM_HELP_MSG_INFO] as $i ) {
371 $tag = array_shift( $i );
376 $info[
'values'] = $i;
380 $this->context->msg(
"apihelp-{$path}-paraminfo-{$tag}" )
381 ->numParams( count( $i ) )
382 ->params( $this->context->getLanguage()->commaList( $i ) )
386 $item[
'info'][] = $info;
391 $key = empty( $settings[ApiBase::PARAM_TEMPLATE_VARS] ) ?
'parameters' :
'templatedparameters';
392 $ret[$key][] = $item;
398 if ( $dynamicParams !==
null ) {
399 if ( $this->helpFormat ===
'none' ) {
400 $ret[
'dynamicparameters'] =
true;
420 $querymodules = $this->
getMain()->getModuleManager()
421 ->getModule(
'query' )->getModuleManager()->getNames();
422 sort( $querymodules );
423 $formatmodules = $this->
getMain()->getModuleManager()->getNames(
'format' );
424 sort( $formatmodules );
428 ParamValidator::PARAM_ISMULTI =>
true,
431 ParamValidator::PARAM_DEFAULT =>
'none',
432 ParamValidator::PARAM_TYPE => [
'html',
'wikitext',
'raw',
'none' ],
436 ParamValidator::PARAM_DEPRECATED =>
true,
437 ParamValidator::PARAM_ISMULTI =>
true,
438 ParamValidator::PARAM_TYPE => $querymodules,
441 ParamValidator::PARAM_DEPRECATED =>
true,
444 ParamValidator::PARAM_DEPRECATED =>
true,
447 ParamValidator::PARAM_DEPRECATED =>
true,
448 ParamValidator::PARAM_ISMULTI =>
true,
449 ParamValidator::PARAM_TYPE => $formatmodules,
456 'action=paraminfo&modules=parse|phpfm|query%2Ballpages|query%2Bsiteinfo'
457 =>
'apihelp-paraminfo-example-1',
458 'action=paraminfo&modules=query%2B*'
459 =>
'apihelp-paraminfo-example-2',
464 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 sub-modules.
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 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 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.
static stripOuterParagraph( $html)
Strip outer.
Group all the pieces relevant to the context of a request into one instance.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...