32 parent::__construct( $main, $action );
39 $this->helpFormat =
$params[
'helpformat'];
44 if ( is_array(
$params[
'modules'] ) ) {
46 foreach (
$params[
'modules'] as $path ) {
47 if ( $path ===
'*' || $path ===
'**' ) {
50 if ( substr( $path, -2 ) ===
'+*' || substr( $path, -2 ) ===
' *' ) {
52 $path = substr( $path, 0, -2 );
54 } elseif ( substr( $path, -3 ) ===
'+**' || substr( $path, -3 ) ===
' **' ) {
56 $path = substr( $path, 0, -3 );
66 foreach ( $ex->getStatusValue()->getErrors() as $error ) {
75 $this->
addWarning( [
'apierror-badmodule-nosubmodules', $path ],
'badmodule' );
85 if ( is_array(
$params[
'querymodules'] ) ) {
86 $queryModules =
$params[
'querymodules'];
87 foreach ( $queryModules as $m ) {
94 if ( is_array(
$params[
'formatmodules'] ) ) {
95 $formatModules =
$params[
'formatmodules'];
96 foreach ( $formatModules as $m ) {
111 foreach ( $ex->getStatusValue()->getErrors() as $error ) {
120 if ( $module->getParent() && $module->getParent()->getModuleName() ==
'query' &&
121 in_array( $module->getModuleName(), $queryModules )
124 $key =
'querymodules';
126 if ( in_array( $module->getModuleName(), $formatModules ) ) {
127 $key =
'formatmodules';
132 $item[
'querytype'] = $item[
'group'];
134 $res[$key][] = $item;
138 $result->addValue( [ $this->
getModuleName() ],
'helpformat', $this->helpFormat );
140 foreach (
$res as $key => $stuff ) {
148 if (
$params[
'pagesetmodule'] ) {
151 unset(
$res[
'pagesetmodule'][
'name'] );
152 unset(
$res[
'pagesetmodule'][
'path'] );
153 unset(
$res[
'pagesetmodule'][
'group'] );
169 $names = $manager->getNames();
171 foreach ( $names as $name ) {
172 $submodule = $manager->getModule( $name );
173 $paths[] = $submodule->getModulePath();
174 if ( $recursive && $submodule->getModuleManager() ) {
175 $paths = array_merge( $paths, $this->
listAllSubmodules( $submodule, $recursive ) );
189 switch ( $this->helpFormat ) {
195 foreach ( $msgs as $m ) {
196 $ret[] = $m->setContext( $this->context )->text();
198 $res[$key] = implode(
"\n\n",
$ret );
200 $res[$key] = preg_replace(
'!^(([*#:;])[^\n]*)\n\n(?=\2)!m',
"$1\n",
$res[$key] );
206 foreach ( $msgs as $m ) {
207 $ret[] = $m->setContext( $this->context )->parseAsBlock();
211 $ret = preg_replace(
'!\s*</([oud]l)>\s*<\1>\s*!',
"\n",
$ret );
213 $res[$key] = Parser::stripOuterParagraph(
$ret );
218 foreach ( $msgs as $m ) {
220 'key' => $m->getKey(),
221 'params' => $m->getParams(),
225 $a[
'forvalue'] = $m->getParamValue();
240 $path = $module->getModulePath();
242 $ret[
'name'] = $module->getModuleName();
243 $ret[
'classname'] = get_class( $module );
245 if ( !$module->isMain() ) {
246 $ret[
'group'] = $module->getParent()->getModuleManager()->getModuleGroup(
247 $module->getModuleName()
250 $ret[
'prefix'] = $module->getModulePrefix();
252 $sourceInfo = $module->getModuleSourceInfo();
254 $ret[
'source'] = $sourceInfo[
'name'];
255 if ( isset( $sourceInfo[
'namemsg'] ) ) {
256 $ret[
'sourcename'] = $this->context->msg( $sourceInfo[
'namemsg'] )->text();
258 $ret[
'sourcename'] =
$ret[
'source'];
261 $link = SpecialPage::getTitleFor(
'Version',
'License/' . $sourceInfo[
'name'] )->getFullURL();
262 if ( isset( $sourceInfo[
'license-name'] ) ) {
263 $ret[
'licensetag'] = $sourceInfo[
'license-name'];
272 foreach ( $module->getHelpFlags() as $flag ) {
276 $ret[
'helpurls'] = (
array)$module->getHelpUrls();
277 if ( isset(
$ret[
'helpurls'][0] ) &&
$ret[
'helpurls'][0] ===
false ) {
278 $ret[
'helpurls'] = [];
282 if ( $this->helpFormat !==
'none' ) {
283 $ret[
'examples'] = [];
284 $examples = $module->getExamplesMessages();
285 foreach ( $examples as $qs => $msg ) {
290 $module->getModulePrefix(),
291 $module->getModuleName(),
292 $module->getModulePath()
295 if ( isset( $item[
'description'] ) ) {
296 if ( is_array( $item[
'description'] ) ) {
297 $item[
'description'] = $item[
'description'][0];
302 $ret[
'examples'][] = $item;
307 $ret[
'parameters'] = [];
309 $paramDesc = $module->getFinalParamDescription();
310 foreach (
$params as $name => $settings ) {
311 if ( !is_array( $settings ) ) {
318 if ( isset( $paramDesc[$name] ) ) {
325 $item[
'deprecated'] =
true;
328 if ( $name ===
'token' && $module->needsToken() ) {
329 $item[
'tokentype'] = $module->needsToken();
336 if ( is_bool( $dflt ) ) {
338 } elseif ( is_string( $dflt ) || is_null( $dflt ) ) {
340 } elseif ( is_int( $dflt ) ) {
369 if ( $item[
'multi'] ) {
376 $item[
'limit'] = $this->
getMain()->canApiHighLimits()
382 $item[
'allowsduplicates'] =
true;
392 $item[
'type'] = $module->getModuleManager()->getNames( $name );
393 sort( $item[
'type'] );
394 $prefix = $module->isMain()
395 ?
'' : ( $module->getModulePath() .
'+' );
396 $item[
'submodules'] = [];
397 foreach ( $item[
'type'] as $v ) {
398 $item[
'submodules'][$v] = $prefix . $v;
405 $deprecatedSubmodules = [];
406 foreach ( $item[
'submodules'] as $v => $submodulePath ) {
409 if ( $submod && $submod->isDeprecated() ) {
410 $deprecatedSubmodules[] = $v;
416 if ( $deprecatedSubmodules ) {
417 $item[
'type'] = array_merge(
418 array_diff( $item[
'type'], $deprecatedSubmodules ),
419 $deprecatedSubmodules
421 $item[
'deprecatedvalues'] = $deprecatedSubmodules;
428 if ( is_array( $item[
'type'] ) ) {
430 $item[
'type'] = array_values( $item[
'type'] );
435 if ( $item[
'type'] ===
'namespace' ) {
444 if ( $allowAll && $item[
'multi'] &&
445 ( is_array( $item[
'type'] ) || $item[
'type'] ===
'namespace' ) ) {
446 $item[
'allspecifier'] = $allSpecifier;
449 if ( $item[
'type'] ===
'namespace' &&
468 $item[
'enforcerange'] =
true;
470 if ( isset( $settings[self::PARAM_MAX_BYTES] ) ) {
473 if ( isset( $settings[self::PARAM_MAX_CHARS] ) ) {
478 if ( is_array( $item[
'type'] ) ) {
479 $deprecatedValues = array_intersect( $deprecatedValues, $item[
'type'] );
481 if ( $deprecatedValues ) {
482 $item[
'deprecatedvalues'] = array_values( $deprecatedValues );
490 $tag = array_shift( $i );
495 $info[
'values'] = $i;
499 $this->context->msg(
"apihelp-{$path}-paraminfo-{$tag}" )
500 ->numParams( count( $i ) )
501 ->params( $this->context->getLanguage()->commaList( $i ) )
502 ->params( $module->getModulePrefix() )
505 $item[
'info'][] = $info;
510 $ret[
'parameters'][] = $item;
514 $dynamicParams = $module->dynamicParameterDocumentation();
515 if ( $dynamicParams !==
null ) {
516 if ( $this->helpFormat ===
'none' ) {
517 $ret[
'dynamicparameters'] =
true;
520 $module->getModulePrefix(),
521 $module->getModuleName(),
522 $module->getModulePath()
537 $querymodules = $this->
getMain()->getModuleManager()
538 ->getModule(
'query' )->getModuleManager()->getNames();
539 sort( $querymodules );
540 $formatmodules = $this->
getMain()->getModuleManager()->getNames(
'format' );
541 sort( $formatmodules );
573 'action=paraminfo&modules=parse|phpfm|query%2Ballpages|query%2Bsiteinfo'
574 =>
'apihelp-paraminfo-example-1',
575 'action=paraminfo&modules=query%2B*'
576 =>
'apihelp-paraminfo-example-2',
581 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Parameter_information';
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
This abstract class implements many basic API functions, and is the base of all API classes.
const PARAM_REQUIRED
(boolean) Is the parameter required?
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
const PARAM_SUBMODULE_MAP
(string[]) When PARAM_TYPE is 'submodule', map parameter values to submodule paths.
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
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.
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
const PARAM_DEPRECATED_VALUES
(array) When PARAM_TYPE is an array, this indicates which of the values are deprecated.
const PARAM_ISMULTI_LIMIT1
(integer) Maximum number of values, for normal users.
getModuleManager()
Get the module manager, or null if this module has no sub-modules.
getMain()
Get the main module.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
const PARAM_HELP_MSG_INFO
(array) Specify additional information tags for the parameter.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
const PARAM_ALLOW_DUPLICATES
(boolean) Allow the same value to be set more than once when PARAM_ISMULTI is true?
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_ISMULTI_LIMIT2
(integer) Maximum number of values, for users with the apihighimits right.
const PARAM_MAX_CHARS
(integer) Maximum length of a string in characters (unicode codepoints).
const PARAM_SUBMODULE_PARAM_PREFIX
(string) When PARAM_TYPE is 'submodule', used to indicate the 'g' prefix added by ApiQueryGeneratorBa...
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
const LIMIT_SML2
Slow query, apihighlimits limit.
const PARAM_MAX_BYTES
(integer) Maximum length of a string in bytes (in UTF-8 encoding).
getResult()
Get the result object.
const PARAM_RANGE_ENFORCE
(boolean) For PARAM_TYPE 'integer', enforce PARAM_MIN and PARAM_MAX?
const PARAM_EXTRA_NAMESPACES
(int[]) When PARAM_TYPE is 'namespace', include these as additional possible values.
const LIMIT_SML1
Slow query, standard limit.
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
const PARAM_ALL
(boolean|string) When PARAM_TYPE has a defined set of values and PARAM_ISMULTI is true,...
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.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
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.
__construct(ApiMain $main, $action)
getHelpUrls()
Return links to more detailed help pages about the module.
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 setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
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.
Group all the pieces relevant to the context of a request into one instance.
static getExtLicenseFileName( $extDir)
Obtains the full path of an extensions copying or license file if one exists.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
the array() calling protocol came about after MediaWiki 1.4rc1.
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Allows to change the fields on the form that will be generated $name
processing should stop and the error should be shown to the user * false