52 parent::__construct( $main, $action );
53 $this->userFactory = $userFactory;
60 $this->helpFormat =
$params[
'helpformat'];
62 $this->context->
setUser( $this->userFactory->newAnonymous() );
65 if ( is_array(
$params[
'modules'] ) ) {
71 if ( str_ends_with(
$path,
'+*' ) || str_ends_with(
$path,
' *' ) ) {
75 } elseif ( str_ends_with(
$path,
'+**' ) || str_ends_with(
$path,
' **' ) ) {
94 $submodules = $this->listAllSubmodules( $module, $recursive );
96 $modules = array_merge( $modules, $submodules );
98 $this->
addWarning( [
'apierror-badmodule-nosubmodules', $path ],
'badmodule' );
108 if ( is_array(
$params[
'querymodules'] ) ) {
109 $queryModules =
$params[
'querymodules'];
110 foreach ( $queryModules as $m ) {
111 $modules[] =
'query+' . $m;
117 if ( is_array(
$params[
'formatmodules'] ) ) {
118 $formatModules =
$params[
'formatmodules'];
119 foreach ( $formatModules as $m ) {
126 $modules = array_unique( $modules );
130 foreach ( $modules as $m ) {
147 $key =
'querymodules';
149 if ( in_array( $module->
getModuleName(), $formatModules ) ) {
150 $key =
'formatmodules';
153 $item = $this->getModuleInfo( $module );
155 $item[
'querytype'] = $item[
'group'];
157 $res[$key][] = $item;
161 $result->addValue( [ $this->
getModuleName() ],
'helpformat', $this->helpFormat );
163 foreach ( $res as $key => $stuff ) {
168 $res[
'mainmodule'] = $this->getModuleInfo( $this->
getMain() );
171 if (
$params[
'pagesetmodule'] ) {
173 $res[
'pagesetmodule'] = $this->getModuleInfo( $pageSet );
174 unset( $res[
'pagesetmodule'][
'name'] );
175 unset( $res[
'pagesetmodule'][
'path'] );
176 unset( $res[
'pagesetmodule'][
'group'] );
188 private function listAllSubmodules(
ApiBase $module, $recursive ) {
192 $names = $manager->getNames();
194 foreach ( $names as $name ) {
195 $submodule = $manager->getModule( $name );
196 $paths[] = $submodule->getModulePath();
197 if ( $recursive && $submodule->getModuleManager() ) {
198 $paths = array_merge( $paths, $this->listAllSubmodules( $submodule, $recursive ) );
212 switch ( $this->helpFormat ) {
218 foreach ( $msgs as $m ) {
219 $ret[] = $m->setContext( $this->context )->text();
221 $res[$key] = implode(
"\n\n", $ret );
223 $res[$key] = preg_replace(
'!^(([*#:;])[^\n]*)\n\n(?=\2)!m',
"$1\n", $res[$key] );
229 foreach ( $msgs as $m ) {
230 $ret[] = $m->setContext( $this->context )->parseAsBlock();
232 $ret = implode(
"\n", $ret );
234 $ret = preg_replace(
'!\s*</([oud]l)>\s*<\1>\s*!',
"\n", $ret );
236 $res[$key] = Parser::stripOuterParagraph( $ret );
241 foreach ( $msgs as $m ) {
243 'key' => $m->getKey(),
244 'params' => $m->getParams(),
248 $a[
'forvalue'] = $m->getParamValue();
261 private function getModuleInfo( $module ) {
264 $paramValidator = $module->
getMain()->getParamValidator();
267 $ret[
'classname'] = get_class( $module );
268 $ret[
'path'] =
$path;
269 if ( !$module->
isMain() ) {
270 $ret[
'group'] = $module->
getParent()->getModuleManager()->getModuleGroup(
278 $ret[
'source'] = $sourceInfo[
'name'];
279 if ( isset( $sourceInfo[
'namemsg'] ) ) {
280 $ret[
'sourcename'] = $this->context->msg( $sourceInfo[
'namemsg'] )->text();
282 $ret[
'sourcename'] = $ret[
'source'];
286 if ( isset( $sourceInfo[
'license-name'] ) ) {
287 $ret[
'licensetag'] = $sourceInfo[
'license-name'];
288 $ret[
'licenselink'] = (string)$link;
289 } elseif ( ExtensionInfo::getLicenseFileNames( dirname( $sourceInfo[
'path'] ) ) ) {
290 $ret[
'licenselink'] = (string)$link;
301 if ( isset( $ret[
'helpurls'][0] ) && $ret[
'helpurls'][0] === false ) {
302 $ret[
'helpurls'] = [];
307 if ( $this->helpFormat !==
'none' ) {
308 $ret[
'examples'] = [];
310 foreach ( $examples as $qs => $msg ) {
321 if ( isset( $item[
'description'] ) ) {
322 if ( is_array( $item[
'description'] ) ) {
323 $item[
'description'] = $item[
'description'][0];
328 $ret[
'examples'][] = $item;
333 $ret[
'parameters'] = [];
334 $ret[
'templatedparameters'] = [];
338 foreach (
$params as $name => $settings ) {
339 $settings = $paramValidator->normalizeSettings( $settings );
351 if ( isset( $paramDesc[$name] ) ) {
355 foreach ( $paramValidator->getParamInfo( $module, $name, $settings, [] ) as $k => $v ) {
359 if ( $name ===
'token' && $module->
needsToken() ) {
363 if ( $item[
'type'] ===
'NULL' ) {
365 $item[
'type'] =
'string';
366 } elseif ( is_array( $item[
'type'] ) ) {
374 $tag = array_shift( $i );
379 $info[
'values'] = $i;
383 $this->context->msg(
"apihelp-{$path}-paraminfo-{$tag}" )
384 ->numParams( count( $i ) )
385 ->params( $this->context->getLanguage()->commaList( $i ) )
389 $item[
'info'][] = $info;
395 $ret[$key][] = $item;
401 if ( $dynamicParams !==
null ) {
402 if ( $this->helpFormat ===
'none' ) {
403 $ret[
'dynamicparameters'] =
true;
405 $dynamicParams = $this->
msg(
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';
473class_alias( ApiParamInfo::class,
'ApiParamInfo' );
array $params
The job parameters.
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,...