35 parent::__construct( $main, $action );
42 $this->helpFormat = $params[
'helpformat'];
44 $this->context->
setUser( $this->userFactory->newAnonymous() );
47 if ( is_array( $params[
'modules'] ) ) {
49 foreach ( $params[
'modules'] as
$path ) {
53 if ( str_ends_with(
$path,
'+*' ) || str_ends_with(
$path,
' *' ) ) {
57 } elseif ( str_ends_with(
$path,
'+**' ) || str_ends_with(
$path,
' **' ) ) {
76 $submodules = $this->listAllSubmodules( $module, $recursive );
78 $modules = array_merge( $modules, $submodules );
80 $this->
addWarning( [
'apierror-badmodule-nosubmodules', $path ],
'badmodule' );
90 if ( is_array( $params[
'querymodules'] ) ) {
91 $queryModules = $params[
'querymodules'];
92 foreach ( $queryModules as $m ) {
93 $modules[] =
'query+' . $m;
99 if ( is_array( $params[
'formatmodules'] ) ) {
100 $formatModules = $params[
'formatmodules'];
101 foreach ( $formatModules as $m ) {
108 $modules = array_unique( $modules );
112 foreach ( $modules as $m ) {
129 $key =
'querymodules';
131 if ( in_array( $module->
getModuleName(), $formatModules ) ) {
132 $key =
'formatmodules';
135 $item = $this->getModuleInfo( $module );
137 $item[
'querytype'] = $item[
'group'];
139 $res[$key][] = $item;
143 $result->addValue( [ $this->
getModuleName() ],
'helpformat', $this->helpFormat );
145 foreach ( $res as $key => $stuff ) {
149 if ( $params[
'mainmodule'] ) {
150 $res[
'mainmodule'] = $this->getModuleInfo( $this->
getMain() );
153 if ( $params[
'pagesetmodule'] ) {
155 $res[
'pagesetmodule'] = $this->getModuleInfo( $pageSet );
156 unset( $res[
'pagesetmodule'][
'name'] );
157 unset( $res[
'pagesetmodule'][
'path'] );
158 unset( $res[
'pagesetmodule'][
'group'] );
170 private function listAllSubmodules(
ApiBase $module, $recursive ) {
174 $names = $manager->getNames();
176 foreach ( $names as $name ) {
177 $submodule = $manager->getModule( $name );
178 $paths[] = $submodule->getModulePath();
179 if ( $recursive && $submodule->getModuleManager() ) {
180 $paths = array_merge( $paths, $this->listAllSubmodules( $submodule, $recursive ) );
194 switch ( $this->helpFormat ) {
200 foreach ( $msgs as $m ) {
201 $ret[] = $m->setContext( $this->context )->text();
203 $res[$key] = implode(
"\n\n", $ret );
205 $res[$key] = preg_replace(
'!^(([*#:;])[^\n]*)\n\n(?=\2)!m',
"$1\n", $res[$key] );
211 foreach ( $msgs as $m ) {
212 $ret[] = $m->setContext( $this->context )->parseAsBlock();
214 $ret = implode(
"\n", $ret );
216 $ret = preg_replace(
'!\s*</([oud]l)>\s*<\1>\s*!',
"\n", $ret );
218 $res[$key] = Parser::stripOuterParagraph( $ret );
223 foreach ( $msgs as $m ) {
225 'key' => $m->getKey(),
226 'params' => $m->getParams(),
230 $a[
'forvalue'] = $m->getParamValue();
243 private function getModuleInfo( $module ) {
246 $paramValidator = $module->
getMain()->getParamValidator();
249 $ret[
'classname'] = get_class( $module );
250 $ret[
'path'] =
$path;
251 if ( !$module->
isMain() ) {
252 $ret[
'group'] = $module->
getParent()->getModuleManager()->getModuleGroup(
260 $ret[
'source'] = $sourceInfo[
'name'];
261 if ( isset( $sourceInfo[
'namemsg'] ) ) {
262 $ret[
'sourcename'] = $this->context->msg( $sourceInfo[
'namemsg'] )->text();
264 $ret[
'sourcename'] = $ret[
'source'];
268 if ( isset( $sourceInfo[
'license-name'] ) ) {
269 $ret[
'licensetag'] = $sourceInfo[
'license-name'];
270 $ret[
'licenselink'] = (string)$link;
271 } elseif ( ExtensionInfo::getLicenseFileNames( dirname( $sourceInfo[
'path'] ) ) ) {
272 $ret[
'licenselink'] = (string)$link;
279 if ( $deprecationMsg !==
null ) {
290 if ( isset( $ret[
'helpurls'][0] ) && $ret[
'helpurls'][0] === false ) {
291 $ret[
'helpurls'] = [];
295 if ( $this->helpFormat !==
'none' ) {
296 $ret[
'examples'] = [];
298 foreach ( $examples as $qs => $msg ) {
309 if ( isset( $item[
'description'] ) ) {
310 if ( is_array( $item[
'description'] ) ) {
311 $item[
'description'] = $item[
'description'][0];
316 $ret[
'examples'][] = $item;
321 $ret[
'parameters'] = [];
322 $ret[
'templatedparameters'] = [];
326 foreach ( $params as $name => $settings ) {
327 $settings = $paramValidator->normalizeSettings( $settings );
339 if ( isset( $paramDesc[$name] ) ) {
343 foreach ( $paramValidator->getParamInfo( $module, $name, $settings, [] ) as $k => $v ) {
347 if ( $name ===
'token' && $module->
needsToken() ) {
351 if ( $item[
'type'] ===
'NULL' ) {
353 $item[
'type'] =
'string';
354 } elseif ( is_array( $item[
'type'] ) ) {
362 $tag = array_shift( $i );
367 $info[
'values'] = $i;
371 $this->context->msg(
"apihelp-{$path}-paraminfo-{$tag}" )
372 ->numParams( count( $i ) )
373 ->params( $this->context->getLanguage()->commaList( $i ) )
377 $item[
'info'][] = $info;
383 $ret[$key][] = $item;
389 if ( $dynamicParams !==
null ) {
390 if ( $this->helpFormat ===
'none' ) {
391 $ret[
'dynamicparameters'] =
true;
393 $dynamicParams = $this->
msg(
414 $querymodules = $this->
getMain()->getModuleManager()
415 ->getModule(
'query' )->getModuleManager()->getNames();
416 sort( $querymodules );
417 $formatmodules = $this->
getMain()->getModuleManager()->getNames(
'format' );
418 sort( $formatmodules );
422 ParamValidator::PARAM_ISMULTI =>
true,
425 ParamValidator::PARAM_DEFAULT =>
'none',
426 ParamValidator::PARAM_TYPE => [
'html',
'wikitext',
'raw',
'none' ],
430 ParamValidator::PARAM_DEPRECATED =>
true,
431 ParamValidator::PARAM_ISMULTI =>
true,
432 ParamValidator::PARAM_TYPE => $querymodules,
435 ParamValidator::PARAM_DEPRECATED =>
true,
438 ParamValidator::PARAM_DEPRECATED =>
true,
441 ParamValidator::PARAM_DEPRECATED =>
true,
442 ParamValidator::PARAM_ISMULTI =>
true,
443 ParamValidator::PARAM_TYPE => $formatmodules,
451 'action=paraminfo&modules=parse|phpfm|query%2Ballpages|query%2Bsiteinfo'
452 =>
'apihelp-paraminfo-example-1',
453 'action=paraminfo&modules=query%2B*'
454 =>
'apihelp-paraminfo-example-2',
460 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Parameter_information';
465class_alias( ApiParamInfo::class,
'ApiParamInfo' );
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.
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Group all the pieces relevant to the context of a request into one instance.
Parent class for all special pages.
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,...