38 parent::__construct( $main, $action );
39 $this->userFactory = $userFactory;
46 $this->helpFormat = $params[
'helpformat'];
48 $this->context->
setUser( $this->userFactory->newAnonymous() );
51 if ( is_array( $params[
'modules'] ) ) {
53 foreach ( $params[
'modules'] as
$path ) {
57 if ( str_ends_with(
$path,
'+*' ) || str_ends_with(
$path,
' *' ) ) {
61 } elseif ( str_ends_with(
$path,
'+**' ) || str_ends_with(
$path,
' **' ) ) {
80 $submodules = $this->listAllSubmodules( $module, $recursive );
82 $modules = array_merge( $modules, $submodules );
84 $this->
addWarning( [
'apierror-badmodule-nosubmodules', $path ],
'badmodule' );
94 if ( is_array( $params[
'querymodules'] ) ) {
95 $queryModules = $params[
'querymodules'];
96 foreach ( $queryModules as $m ) {
97 $modules[] =
'query+' . $m;
103 if ( is_array( $params[
'formatmodules'] ) ) {
104 $formatModules = $params[
'formatmodules'];
105 foreach ( $formatModules as $m ) {
112 $modules = array_unique( $modules );
116 foreach ( $modules as $m ) {
133 $key =
'querymodules';
135 if ( in_array( $module->
getModuleName(), $formatModules ) ) {
136 $key =
'formatmodules';
139 $item = $this->getModuleInfo( $module );
141 $item[
'querytype'] = $item[
'group'];
143 $res[$key][] = $item;
147 $result->addValue( [ $this->
getModuleName() ],
'helpformat', $this->helpFormat );
149 foreach ( $res as $key => $stuff ) {
153 if ( $params[
'mainmodule'] ) {
154 $res[
'mainmodule'] = $this->getModuleInfo( $this->
getMain() );
157 if ( $params[
'pagesetmodule'] ) {
159 $res[
'pagesetmodule'] = $this->getModuleInfo( $pageSet );
160 unset( $res[
'pagesetmodule'][
'name'] );
161 unset( $res[
'pagesetmodule'][
'path'] );
162 unset( $res[
'pagesetmodule'][
'group'] );
174 private function listAllSubmodules(
ApiBase $module, $recursive ) {
178 $names = $manager->getNames();
180 foreach ( $names as $name ) {
181 $submodule = $manager->getModule( $name );
182 $paths[] = $submodule->getModulePath();
183 if ( $recursive && $submodule->getModuleManager() ) {
184 $paths = array_merge( $paths, $this->listAllSubmodules( $submodule, $recursive ) );
198 switch ( $this->helpFormat ) {
204 foreach ( $msgs as $m ) {
205 $ret[] = $m->setContext( $this->context )->text();
207 $res[$key] = implode(
"\n\n", $ret );
209 $res[$key] = preg_replace(
'!^(([*#:;])[^\n]*)\n\n(?=\2)!m',
"$1\n", $res[$key] );
215 foreach ( $msgs as $m ) {
216 $ret[] = $m->setContext( $this->context )->parseAsBlock();
218 $ret = implode(
"\n", $ret );
220 $ret = preg_replace(
'!\s*</([oud]l)>\s*<\1>\s*!',
"\n", $ret );
222 $res[$key] = Parser::stripOuterParagraph( $ret );
227 foreach ( $msgs as $m ) {
229 'key' => $m->getKey(),
230 'params' => $m->getParams(),
234 $a[
'forvalue'] = $m->getParamValue();
247 private function getModuleInfo( $module ) {
250 $paramValidator = $module->
getMain()->getParamValidator();
253 $ret[
'classname'] = get_class( $module );
254 $ret[
'path'] =
$path;
255 if ( !$module->
isMain() ) {
256 $ret[
'group'] = $module->
getParent()->getModuleManager()->getModuleGroup(
264 $ret[
'source'] = $sourceInfo[
'name'];
265 if ( isset( $sourceInfo[
'namemsg'] ) ) {
266 $ret[
'sourcename'] = $this->context->msg( $sourceInfo[
'namemsg'] )->text();
268 $ret[
'sourcename'] = $ret[
'source'];
272 if ( isset( $sourceInfo[
'license-name'] ) ) {
273 $ret[
'licensetag'] = $sourceInfo[
'license-name'];
274 $ret[
'licenselink'] = (string)$link;
275 } elseif ( ExtensionInfo::getLicenseFileNames( dirname( $sourceInfo[
'path'] ) ) ) {
276 $ret[
'licenselink'] = (string)$link;
287 if ( isset( $ret[
'helpurls'][0] ) && $ret[
'helpurls'][0] === false ) {
288 $ret[
'helpurls'] = [];
292 if ( $this->helpFormat !==
'none' ) {
293 $ret[
'examples'] = [];
295 foreach ( $examples as $qs => $msg ) {
306 if ( isset( $item[
'description'] ) ) {
307 if ( is_array( $item[
'description'] ) ) {
308 $item[
'description'] = $item[
'description'][0];
313 $ret[
'examples'][] = $item;
318 $ret[
'parameters'] = [];
319 $ret[
'templatedparameters'] = [];
323 foreach ( $params as $name => $settings ) {
324 $settings = $paramValidator->normalizeSettings( $settings );
336 if ( isset( $paramDesc[$name] ) ) {
340 foreach ( $paramValidator->getParamInfo( $module, $name, $settings, [] ) as $k => $v ) {
344 if ( $name ===
'token' && $module->
needsToken() ) {
348 if ( $item[
'type'] ===
'NULL' ) {
350 $item[
'type'] =
'string';
351 } elseif ( is_array( $item[
'type'] ) ) {
359 $tag = array_shift( $i );
364 $info[
'values'] = $i;
368 $this->context->msg(
"apihelp-{$path}-paraminfo-{$tag}" )
369 ->numParams( count( $i ) )
370 ->params( $this->context->getLanguage()->commaList( $i ) )
374 $item[
'info'][] = $info;
380 $ret[$key][] = $item;
386 if ( $dynamicParams !==
null ) {
387 if ( $this->helpFormat ===
'none' ) {
388 $ret[
'dynamicparameters'] =
true;
390 $dynamicParams = $this->
msg(
411 $querymodules = $this->
getMain()->getModuleManager()
412 ->getModule(
'query' )->getModuleManager()->getNames();
413 sort( $querymodules );
414 $formatmodules = $this->
getMain()->getModuleManager()->getNames(
'format' );
415 sort( $formatmodules );
419 ParamValidator::PARAM_ISMULTI =>
true,
422 ParamValidator::PARAM_DEFAULT =>
'none',
423 ParamValidator::PARAM_TYPE => [
'html',
'wikitext',
'raw',
'none' ],
427 ParamValidator::PARAM_DEPRECATED =>
true,
428 ParamValidator::PARAM_ISMULTI =>
true,
429 ParamValidator::PARAM_TYPE => $querymodules,
432 ParamValidator::PARAM_DEPRECATED =>
true,
435 ParamValidator::PARAM_DEPRECATED =>
true,
438 ParamValidator::PARAM_DEPRECATED =>
true,
439 ParamValidator::PARAM_ISMULTI =>
true,
440 ParamValidator::PARAM_TYPE => $formatmodules,
448 'action=paraminfo&modules=parse|phpfm|query%2Ballpages|query%2Bsiteinfo'
449 =>
'apihelp-paraminfo-example-1',
450 'action=paraminfo&modules=query%2B*'
451 =>
'apihelp-paraminfo-example-2',
457 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Parameter_information';
462class_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,...