49 parent::__construct( $main, $action );
57 $this->helpFormat = $params[
'helpformat'];
59 $this->context->
setUser( $this->userFactory->newAnonymous() );
62 if ( is_array( $params[
'modules'] ) ) {
64 foreach ( $params[
'modules'] as
$path ) {
68 if ( substr(
$path, -2 ) ===
'+*' || substr(
$path, -2 ) ===
' *' ) {
72 } elseif ( substr(
$path, -3 ) ===
'+**' || substr(
$path, -3 ) ===
' **' ) {
95 $this->
addWarning( [
'apierror-badmodule-nosubmodules', $path ],
'badmodule' );
105 if ( is_array( $params[
'querymodules'] ) ) {
106 $queryModules = $params[
'querymodules'];
107 foreach ( $queryModules as $m ) {
114 if ( is_array( $params[
'formatmodules'] ) ) {
115 $formatModules = $params[
'formatmodules'];
116 foreach ( $formatModules as $m ) {
140 if ( $module->getParent() && $module->getParent()->getModuleName() ==
'query' &&
141 in_array( $module->getModuleName(), $queryModules )
144 $key =
'querymodules';
146 if ( in_array( $module->getModuleName(), $formatModules ) ) {
147 $key =
'formatmodules';
152 $item[
'querytype'] = $item[
'group'];
154 $res[$key][] = $item;
158 $result->addValue( [ $this->
getModuleName() ],
'helpformat', $this->helpFormat );
160 foreach (
$res as $key => $stuff ) {
164 if ( $params[
'mainmodule'] ) {
168 if ( $params[
'pagesetmodule'] ) {
171 unset(
$res[
'pagesetmodule'][
'name'] );
172 unset(
$res[
'pagesetmodule'][
'path'] );
173 unset(
$res[
'pagesetmodule'][
'group'] );
189 $names = $manager->getNames();
191 foreach ( $names as $name ) {
192 $submodule = $manager->getModule( $name );
193 $paths[] = $submodule->getModulePath();
194 if ( $recursive && $submodule->getModuleManager() ) {
195 $paths = array_merge( $paths, $this->
listAllSubmodules( $submodule, $recursive ) );
209 switch ( $this->helpFormat ) {
215 foreach ( $msgs as $m ) {
216 $ret[] = $m->setContext( $this->context )->text();
218 $res[$key] = implode(
"\n\n", $ret );
220 $res[$key] = preg_replace(
'!^(([*#:;])[^\n]*)\n\n(?=\2)!m',
"$1\n",
$res[$key] );
226 foreach ( $msgs as $m ) {
227 $ret[] = $m->setContext( $this->context )->parseAsBlock();
229 $ret = implode(
"\n", $ret );
231 $ret = preg_replace(
'!\s*</([oud]l)>\s*<\1>\s*!',
"\n", $ret );
238 foreach ( $msgs as $m ) {
240 'key' => $m->getKey(),
241 'params' => $m->getParams(),
245 $a[
'forvalue'] = $m->getParamValue();
260 $path = $module->getModulePath();
261 $paramValidator = $module->getMain()->getParamValidator();
263 $ret[
'name'] = $module->getModuleName();
264 $ret[
'classname'] = get_class( $module );
265 $ret[
'path'] =
$path;
266 if ( !$module->isMain() ) {
267 $ret[
'group'] = $module->getParent()->getModuleManager()->getModuleGroup(
268 $module->getModuleName()
271 $ret[
'prefix'] = $module->getModulePrefix();
273 $sourceInfo = $module->getModuleSourceInfo();
275 $ret[
'source'] = $sourceInfo[
'name'];
276 if ( isset( $sourceInfo[
'namemsg'] ) ) {
277 $ret[
'sourcename'] = $this->context->msg( $sourceInfo[
'namemsg'] )->text();
279 $ret[
'sourcename'] = $ret[
'source'];
283 if ( isset( $sourceInfo[
'license-name'] ) ) {
284 $ret[
'licensetag'] = $sourceInfo[
'license-name'];
285 $ret[
'licenselink'] = (string)$link;
286 } elseif ( ExtensionInfo::getLicenseFileNames( dirname( $sourceInfo[
'path'] ) ) ) {
287 $ret[
'licenselink'] = (string)$link;
293 foreach ( $module->getHelpFlags() as $flag ) {
297 $ret[
'helpurls'] = (array)$module->getHelpUrls();
298 if ( isset( $ret[
'helpurls'][0] ) && $ret[
'helpurls'][0] === false ) {
299 $ret[
'helpurls'] = [];
304 if ( $this->helpFormat !==
'none' ) {
305 $ret[
'examples'] = [];
306 $examples = $module->getExamplesMessages();
307 foreach ( $examples as $qs => $msg ) {
312 $module->getModulePrefix(),
313 $module->getModuleName(),
314 $module->getModulePath()
317 if ( isset( $item[
'description'] ) ) {
318 if ( is_array( $item[
'description'] ) ) {
319 $item[
'description'] = $item[
'description'][0];
324 $ret[
'examples'][] = $item;
329 $ret[
'parameters'] = [];
330 $ret[
'templatedparameters'] = [];
332 $paramDesc = $module->getFinalParamDescription();
334 foreach ( $params as $name => $settings ) {
335 $settings = $paramValidator->normalizeSettings( $settings );
347 if ( isset( $paramDesc[$name] ) ) {
351 foreach ( $paramValidator->getParamInfo( $module, $name, $settings, [] ) as $k => $v ) {
355 if ( $name ===
'token' && $module->needsToken() ) {
356 $item[
'tokentype'] = $module->needsToken();
359 if ( $item[
'type'] ===
'NULL' ) {
361 $item[
'type'] =
'string';
362 } elseif ( is_array( $item[
'type'] ) ) {
370 $tag = array_shift( $i );
375 $info[
'values'] = $i;
379 $this->context->msg(
"apihelp-{$path}-paraminfo-{$tag}" )
380 ->numParams( count( $i ) )
381 ->params( $this->context->getLanguage()->commaList( $i ) )
382 ->params( $module->getModulePrefix() )
385 $item[
'info'][] = $info;
391 $ret[$key][] = $item;
396 $dynamicParams = $module->dynamicParameterDocumentation();
397 if ( $dynamicParams !==
null ) {
398 if ( $this->helpFormat ===
'none' ) {
399 $ret[
'dynamicparameters'] =
true;
402 $module->getModulePrefix(),
403 $module->getModuleName(),
404 $module->getModulePath()
419 $querymodules = $this->
getMain()->getModuleManager()
420 ->getModule(
'query' )->getModuleManager()->getNames();
421 sort( $querymodules );
422 $formatmodules = $this->
getMain()->getModuleManager()->getNames(
'format' );
423 sort( $formatmodules );
455 'action=paraminfo&modules=parse|phpfm|query%2Ballpages|query%2Bsiteinfo'
456 =>
'apihelp-paraminfo-example-1',
457 'action=paraminfo&modules=query%2B*'
458 =>
'apihelp-paraminfo-example-2',
463 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.
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.
getModuleManager()
Get the module manager, or null if this module has no sub-modules.
getMain()
Get the main module.
const PARAM_HELP_MSG_INFO
(array) Specify additional information tags for the parameter.
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,...
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
const GET_VALUES_FOR_HELP
getAllowedParams() flag: When set, the result could take longer to generate, but should be more thoro...
getModuleName()
Get the name of the module being executed by this instance.
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)
listAllSubmodules(ApiBase $module, $recursive)
List all submodules of a module.
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,...