5 * Created on Aug 29, 2014
7 * Copyright © 2014 Wikimedia Foundation and contributors
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
27 use HtmlFormatter\HtmlFormatter
;
28 use MediaWiki\MediaWikiServices
;
31 * Class to output help for an API module
33 * @since 1.25 completely rewritten
36 class ApiHelp
extends ApiBase
{
37 public function execute() {
38 $params = $this->extractRequestParams();
41 foreach ( $params['modules'] as $path ) {
42 $modules[] = $this->getModuleFromPath( $path );
46 $context = new DerivativeContext( $this->getMain()->getContext() );
47 $context->setSkin( SkinFactory
::getDefaultInstance()->makeSkin( 'apioutput' ) );
48 $context->setLanguage( $this->getMain()->getLanguage() );
49 $context->setTitle( SpecialPage
::getTitleFor( 'ApiHelp' ) );
50 $out = new OutputPage( $context );
51 $out->setCopyrightUrl( 'https://www.mediawiki.org/wiki/Special:MyLanguage/Copyright' );
52 $context->setOutput( $out );
54 self
::getHelp( $context, $modules, $params );
56 // Grab the output from the skin
58 $context->getOutput()->output();
59 $html = ob_get_clean();
61 $result = $this->getResult();
62 if ( $params['wrap'] ) {
64 'mime' => 'text/html',
67 ApiResult
::setSubelementsList( $data, 'help' );
68 $result->addValue( null, $this->getModuleName(), $data );
71 $result->addValue( null, 'text', $html, ApiResult
::NO_SIZE_CHECK
);
72 $result->addValue( null, 'mime', 'text/html', ApiResult
::NO_SIZE_CHECK
);
77 * Generate help for the specified modules
79 * Help is placed into the OutputPage object returned by
80 * $context->getOutput().
82 * Recognized options include:
83 * - headerlevel: (int) Header tag level
84 * - nolead: (bool) Skip the inclusion of api-help-lead
85 * - noheader: (bool) Skip the inclusion of the top-level section headers
86 * - submodules: (bool) Include help for submodules of the current module
87 * - recursivesubmodules: (bool) Include help for submodules recursively
88 * - helptitle: (string) Title to link for additional modules' help. Should contain $1.
89 * - toc: (bool) Include a table of contents
91 * @param IContextSource $context
92 * @param ApiBase[]|ApiBase $modules
93 * @param array $options Formatting options (described above)
95 public static function getHelp( IContextSource
$context, $modules, array $options ) {
98 if ( !is_array( $modules ) ) {
99 $modules = [ $modules ];
102 $out = $context->getOutput();
103 $out->addModuleStyles( [
107 if ( !empty( $options['toc'] ) ) {
108 $out->addModules( 'mediawiki.toc' );
110 $out->setPageTitle( $context->msg( 'api-help-title' ) );
112 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
114 if ( count( $modules ) == 1 && $modules[0] instanceof ApiMain
&&
115 $options['recursivesubmodules'] && $context->getLanguage() === $wgContLang
117 $cacheHelpTimeout = $context->getConfig()->get( 'APICacheHelpTimeout' );
118 if ( $cacheHelpTimeout > 0 ) {
119 // Get help text from cache if present
120 $cacheKey = $cache->makeKey( 'apihelp', $modules[0]->getModulePath(),
121 (int)!empty( $options['toc'] ),
122 str_replace( ' ', '_', SpecialVersion
::getVersion( 'nodb' ) ) );
123 $cached = $cache->get( $cacheKey );
125 $out->addHTML( $cached );
130 if ( $out->getHTML() !== '' ) {
131 // Don't save to cache, there's someone else's content in the page
136 $options['recursivesubmodules'] = !empty( $options['recursivesubmodules'] );
137 $options['submodules'] = $options['recursivesubmodules'] ||
!empty( $options['submodules'] );
140 if ( empty( $options['nolead'] ) ) {
141 $msg = $context->msg( 'api-help-lead' );
142 if ( !$msg->isDisabled() ) {
143 $out->addHTML( $msg->parseAsBlock() );
148 $html = self
::getHelpInternal( $context, $modules, $options, $haveModules );
149 if ( !empty( $options['toc'] ) && $haveModules ) {
150 $out->addHTML( Linker
::generateTOC( $haveModules, $context->getLanguage() ) );
152 $out->addHTML( $html );
154 $helptitle = isset( $options['helptitle'] ) ?
$options['helptitle'] : null;
155 $html = self
::fixHelpLinks( $out->getHTML(), $helptitle, $haveModules );
157 $out->addHTML( $html );
159 if ( $cacheKey !== null ) {
160 $cache->set( $cacheKey, $out->getHTML(), $cacheHelpTimeout );
165 * Replace Special:ApiHelp links with links to api.php
167 * @param string $html
168 * @param string|null $helptitle Title to link to rather than api.php, must contain '$1'
169 * @param array $localModules Keys are modules to link within the current page, values are ignored
172 public static function fixHelpLinks( $html, $helptitle = null, $localModules = [] ) {
173 $formatter = new HtmlFormatter( $html );
174 $doc = $formatter->getDoc();
175 $xpath = new DOMXPath( $doc );
176 $nodes = $xpath->query( '//a[@href][not(contains(@class,\'apihelp-linktrail\'))]' );
177 foreach ( $nodes as $node ) {
178 $href = $node->getAttribute( 'href' );
181 $href = rawurldecode( $href );
182 } while ( $old !== $href );
183 if ( preg_match( '!Special:ApiHelp/([^&/|#]+)((?:#.*)?)!', $href, $m ) ) {
184 if ( isset( $localModules[$m[1]] ) ) {
185 $href = $m[2] === '' ?
'#' . $m[1] : $m[2];
186 } elseif ( $helptitle !== null ) {
187 $href = Title
::newFromText( str_replace( '$1', $m[1], $helptitle ) . $m[2] )
190 $href = wfAppendQuery( wfScript( 'api' ), [
195 $node->setAttribute( 'href', $href );
196 $node->removeAttribute( 'title' );
200 return $formatter->getText();
204 * Wrap a message in HTML with a class.
206 * @param Message $msg
207 * @param string $class
211 private static function wrap( Message
$msg, $class, $tag = 'span' ) {
212 return Html
::rawElement( $tag, [ 'class' => $class ],
218 * Recursively-called function to actually construct the help
220 * @param IContextSource $context
221 * @param ApiBase[] $modules
222 * @param array $options
223 * @param array &$haveModules
226 private static function getHelpInternal( IContextSource
$context, array $modules,
227 array $options, &$haveModules
231 $level = empty( $options['headerlevel'] ) ?
2 : $options['headerlevel'];
232 if ( empty( $options['tocnumber'] ) ) {
233 $tocnumber = [ 2 => 0 ];
235 $tocnumber = &$options['tocnumber'];
238 foreach ( $modules as $module ) {
239 $tocnumber[$level]++
;
240 $path = $module->getModulePath();
241 $module->setContext( $context );
252 if ( empty( $options['noheader'] ) ||
!empty( $options['toc'] ) ) {
255 while ( isset( $haveModules[$anchor] ) ) {
256 $anchor = $path . '|' . ++
$i;
259 if ( $module->isMain() ) {
260 $headerContent = $context->msg( 'api-help-main-header' )->parse();
262 'class' => 'apihelp-header',
265 $name = $module->getModuleName();
266 $headerContent = $module->getParent()->getModuleManager()->getModuleGroup( $name ) .
268 if ( $module->getModulePrefix() !== '' ) {
269 $headerContent .= ' ' .
270 $context->msg( 'parentheses', $module->getModulePrefix() )->parse();
272 // Module names are always in English and not localized,
273 // so English language and direction must be set explicitly,
274 // otherwise parentheses will get broken in RTL wikis
276 'class' => 'apihelp-header apihelp-module-name',
282 $headerAttr['id'] = $anchor;
284 $haveModules[$anchor] = [
285 'toclevel' => count( $tocnumber ),
288 'line' => $headerContent,
289 'number' => implode( '.', $tocnumber ),
292 if ( empty( $options['noheader'] ) ) {
293 $help['header'] .= Html
::element(
294 'h' . min( 6, $level ),
300 $haveModules[$path] = true;
305 for ( $m = $module; $m !== null; $m = $m->getParent() ) {
306 $name = $m->getModuleName();
307 if ( $name === 'main_int' ) {
311 if ( count( $modules ) === 1 && $m === $modules[0] &&
312 !( !empty( $options['submodules'] ) && $m->getModuleManager() )
314 $link = Html
::element( 'b', [ 'dir' => 'ltr', 'lang' => 'en' ], $name );
316 $link = SpecialPage
::getTitleFor( 'ApiHelp', $m->getModulePath() )->getLocalURL();
317 $link = Html
::element( 'a',
318 [ 'href' => $link, 'class' => 'apihelp-linktrail', 'dir' => 'ltr', 'lang' => 'en' ],
323 array_unshift( $links, $link );
326 $help['header'] .= self
::wrap(
327 $context->msg( 'parentheses' )
328 ->rawParams( $context->getLanguage()->pipeList( $links ) ),
329 'apihelp-linktrail', 'div'
333 $flags = $module->getHelpFlags();
334 $help['flags'] .= Html
::openElement( 'div',
335 [ 'class' => 'apihelp-block apihelp-flags' ] );
336 $msg = $context->msg( 'api-help-flags' );
337 if ( !$msg->isDisabled() ) {
338 $help['flags'] .= self
::wrap(
339 $msg->numParams( count( $flags ) ), 'apihelp-block-head', 'div'
342 $help['flags'] .= Html
::openElement( 'ul' );
343 foreach ( $flags as $flag ) {
344 $help['flags'] .= Html
::rawElement( 'li', null,
345 self
::wrap( $context->msg( "api-help-flag-$flag" ), "apihelp-flag-$flag" )
348 $sourceInfo = $module->getModuleSourceInfo();
350 if ( isset( $sourceInfo['namemsg'] ) ) {
351 $extname = $context->msg( $sourceInfo['namemsg'] )->text();
353 // Probably English, so wrap it.
354 $extname = Html
::element( 'span', [ 'dir' => 'ltr', 'lang' => 'en' ], $sourceInfo['name'] );
356 $help['flags'] .= Html
::rawElement( 'li', null,
358 $context->msg( 'api-help-source', $extname, $sourceInfo['name'] ),
363 $link = SpecialPage
::getTitleFor( 'Version', 'License/' . $sourceInfo['name'] );
364 if ( isset( $sourceInfo['license-name'] ) ) {
365 $msg = $context->msg( 'api-help-license', $link,
366 Html
::element( 'span', [ 'dir' => 'ltr', 'lang' => 'en' ], $sourceInfo['license-name'] )
368 } elseif ( SpecialVersion
::getExtLicenseFileName( dirname( $sourceInfo['path'] ) ) ) {
369 $msg = $context->msg( 'api-help-license-noname', $link );
371 $msg = $context->msg( 'api-help-license-unknown' );
373 $help['flags'] .= Html
::rawElement( 'li', null,
374 self
::wrap( $msg, 'apihelp-license' )
377 $help['flags'] .= Html
::rawElement( 'li', null,
378 self
::wrap( $context->msg( 'api-help-source-unknown' ), 'apihelp-source' )
380 $help['flags'] .= Html
::rawElement( 'li', null,
381 self
::wrap( $context->msg( 'api-help-license-unknown' ), 'apihelp-license' )
384 $help['flags'] .= Html
::closeElement( 'ul' );
385 $help['flags'] .= Html
::closeElement( 'div' );
387 foreach ( $module->getFinalDescription() as $msg ) {
388 $msg->setContext( $context );
389 $help['description'] .= $msg->parseAsBlock();
392 $urls = $module->getHelpUrls();
394 $help['help-urls'] .= Html
::openElement( 'div',
395 [ 'class' => 'apihelp-block apihelp-help-urls' ]
397 $msg = $context->msg( 'api-help-help-urls' );
398 if ( !$msg->isDisabled() ) {
399 $help['help-urls'] .= self
::wrap(
400 $msg->numParams( count( $urls ) ), 'apihelp-block-head', 'div'
403 if ( !is_array( $urls ) ) {
406 $help['help-urls'] .= Html
::openElement( 'ul' );
407 foreach ( $urls as $url ) {
408 $help['help-urls'] .= Html
::rawElement( 'li', null,
409 Html
::element( 'a', [ 'href' => $url, 'dir' => 'ltr' ], $url )
412 $help['help-urls'] .= Html
::closeElement( 'ul' );
413 $help['help-urls'] .= Html
::closeElement( 'div' );
416 $params = $module->getFinalParams( ApiBase
::GET_VALUES_FOR_HELP
);
417 $dynamicParams = $module->dynamicParameterDocumentation();
419 if ( $params ||
$dynamicParams !== null ) {
420 $help['parameters'] .= Html
::openElement( 'div',
421 [ 'class' => 'apihelp-block apihelp-parameters' ]
423 $msg = $context->msg( 'api-help-parameters' );
424 if ( !$msg->isDisabled() ) {
425 $help['parameters'] .= self
::wrap(
426 $msg->numParams( count( $params ) ), 'apihelp-block-head', 'div'
429 $help['parameters'] .= Html
::openElement( 'dl' );
431 $descriptions = $module->getFinalParamDescription();
433 foreach ( $params as $name => $settings ) {
434 if ( !is_array( $settings ) ) {
435 $settings = [ ApiBase
::PARAM_DFLT
=> $settings ];
438 $help['parameters'] .= Html
::rawElement( 'dt', null,
439 Html
::element( 'span', [ 'dir' => 'ltr', 'lang' => 'en' ], $module->encodeParamName( $name ) )
444 if ( isset( $descriptions[$name] ) ) {
445 foreach ( $descriptions[$name] as $msg ) {
446 $msg->setContext( $context );
447 $description[] = $msg->parseAsBlock();
455 if ( !empty( $settings[ApiBase
::PARAM_REQUIRED
] ) ) {
456 $info[] = $context->msg( 'api-help-param-required' )->parse();
460 if ( !empty( $settings[ApiBase
::PARAM_HELP_MSG_INFO
] ) ) {
461 foreach ( $settings[ApiBase
::PARAM_HELP_MSG_INFO
] as $i ) {
462 $tag = array_shift( $i );
463 $info[] = $context->msg( "apihelp-{$path}-paraminfo-{$tag}" )
464 ->numParams( count( $i ) )
465 ->params( $context->getLanguage()->commaList( $i ) )
466 ->params( $module->getModulePrefix() )
471 // Type documentation
472 if ( !isset( $settings[ApiBase
::PARAM_TYPE
] ) ) {
473 $dflt = isset( $settings[ApiBase
::PARAM_DFLT
] )
474 ?
$settings[ApiBase
::PARAM_DFLT
]
476 if ( is_bool( $dflt ) ) {
477 $settings[ApiBase
::PARAM_TYPE
] = 'boolean';
478 } elseif ( is_string( $dflt ) ||
is_null( $dflt ) ) {
479 $settings[ApiBase
::PARAM_TYPE
] = 'string';
480 } elseif ( is_int( $dflt ) ) {
481 $settings[ApiBase
::PARAM_TYPE
] = 'integer';
484 if ( isset( $settings[ApiBase
::PARAM_TYPE
] ) ) {
485 $type = $settings[ApiBase
::PARAM_TYPE
];
486 $multi = !empty( $settings[ApiBase
::PARAM_ISMULTI
] );
487 $hintPipeSeparated = true;
488 $count = ApiBase
::LIMIT_SML2 +
1;
490 if ( is_array( $type ) ) {
491 $count = count( $type );
492 $deprecatedValues = isset( $settings[ApiBase
::PARAM_DEPRECATED_VALUES
] )
493 ?
$settings[ApiBase
::PARAM_DEPRECATED_VALUES
]
495 $links = isset( $settings[ApiBase
::PARAM_VALUE_LINKS
] )
496 ?
$settings[ApiBase
::PARAM_VALUE_LINKS
]
498 $values = array_map( function ( $v ) use ( $links, $deprecatedValues ) {
501 // We can't know whether this contains LTR or RTL text.
502 $attr['dir'] = 'auto';
504 if ( isset( $deprecatedValues[$v] ) ) {
505 $attr['class'] = 'apihelp-deprecated-value';
507 $ret = $attr ? Html
::element( 'span', $attr, $v ) : $v;
508 if ( isset( $links[$v] ) ) {
509 $ret = "[[{$links[$v]}|$ret]]";
513 $i = array_search( '', $type, true );
514 if ( $i === false ) {
515 $values = $context->getLanguage()->commaList( $values );
517 unset( $values[$i] );
518 $values = $context->msg( 'api-help-param-list-can-be-empty' )
519 ->numParams( count( $values ) )
520 ->params( $context->getLanguage()->commaList( $values ) )
523 $info[] = $context->msg( 'api-help-param-list' )
524 ->params( $multi ?
2 : 1 )
527 $hintPipeSeparated = false;
533 if ( isset( $settings[ApiBase
::PARAM_SUBMODULE_MAP
] ) ) {
534 $map = $settings[ApiBase
::PARAM_SUBMODULE_MAP
];
537 $prefix = $module->isMain() ?
'' : ( $module->getModulePath() . '+' );
539 foreach ( $module->getModuleManager()->getNames( $name ) as $submoduleName ) {
540 $map[$submoduleName] = $prefix . $submoduleName;
542 $defaultAttrs = [ 'dir' => 'ltr', 'lang' => 'en' ];
547 $deprecatedSubmodules = [];
548 foreach ( $map as $v => $m ) {
549 $attrs = $defaultAttrs;
552 $submod = $module->getModuleFromPath( $m );
554 if ( $submod->isDeprecated() ) {
555 $arr = &$deprecatedSubmodules;
556 $attrs['class'] = 'apihelp-deprecated-value';
559 } catch ( ApiUsageException
$ex ) {
563 $v = Html
::element( 'span', $attrs, $v );
565 $arr[] = "[[Special:ApiHelp/{$m}|{$v}]]";
567 $submodules = array_merge( $submodules, $deprecatedSubmodules );
568 $count = count( $submodules );
569 $info[] = $context->msg( 'api-help-param-list' )
570 ->params( $multi ?
2 : 1 )
571 ->params( $context->getLanguage()->commaList( $submodules ) )
573 $hintPipeSeparated = false;
574 // No type message necessary, we have a list of values.
579 $namespaces = MWNamespace
::getValidNamespaces();
580 if ( isset( $settings[ApiBase
::PARAM_EXTRA_NAMESPACES
] ) &&
581 is_array( $settings[ApiBase
::PARAM_EXTRA_NAMESPACES
] )
583 $namespaces = array_merge( $namespaces, $settings[ApiBase
::PARAM_EXTRA_NAMESPACES
] );
586 $count = count( $namespaces );
587 $info[] = $context->msg( 'api-help-param-list' )
588 ->params( $multi ?
2 : 1 )
589 ->params( $context->getLanguage()->commaList( $namespaces ) )
591 $hintPipeSeparated = false;
592 // No type message necessary, we have a list of values.
597 $tags = ChangeTags
::listExplicitlyDefinedTags();
598 $count = count( $tags );
599 $info[] = $context->msg( 'api-help-param-list' )
600 ->params( $multi ?
2 : 1 )
601 ->params( $context->getLanguage()->commaList( $tags ) )
603 $hintPipeSeparated = false;
608 if ( isset( $settings[ApiBase
::PARAM_MAX2
] ) ) {
609 $info[] = $context->msg( 'api-help-param-limit2' )
610 ->numParams( $settings[ApiBase
::PARAM_MAX
] )
611 ->numParams( $settings[ApiBase
::PARAM_MAX2
] )
614 $info[] = $context->msg( 'api-help-param-limit' )
615 ->numParams( $settings[ApiBase
::PARAM_MAX
] )
621 // Possible messages:
622 // api-help-param-integer-min,
623 // api-help-param-integer-max,
624 // api-help-param-integer-minmax
627 if ( isset( $settings[ApiBase
::PARAM_MIN
] ) ) {
629 $min = $settings[ApiBase
::PARAM_MIN
];
631 if ( isset( $settings[ApiBase
::PARAM_MAX
] ) ) {
633 $max = $settings[ApiBase
::PARAM_MAX
];
635 if ( $suffix !== '' ) {
637 $context->msg( "api-help-param-integer-$suffix" )
638 ->params( $multi ?
2 : 1 )
639 ->numParams( $min, $max )
645 $info[] = $context->msg( 'api-help-param-upload' )
647 // No type message necessary, api-help-param-upload should handle it.
653 // Displaying a type message here would be useless.
659 // Add type. Messages for grep: api-help-param-type-limit
660 // api-help-param-type-integer api-help-param-type-boolean
661 // api-help-param-type-timestamp api-help-param-type-user
662 // api-help-param-type-password
663 if ( is_string( $type ) ) {
664 $msg = $context->msg( "api-help-param-type-$type" );
665 if ( !$msg->isDisabled() ) {
666 $info[] = $msg->params( $multi ?
2 : 1 )->parse();
672 if ( $hintPipeSeparated ) {
673 $extra[] = $context->msg( 'api-help-param-multi-separate' )->parse();
675 if ( $count > ApiBase
::LIMIT_SML1
) {
676 $extra[] = $context->msg( 'api-help-param-multi-max' )
677 ->numParams( ApiBase
::LIMIT_SML1
, ApiBase
::LIMIT_SML2
)
681 $info[] = implode( ' ', $extra );
684 $allowAll = isset( $settings[ApiBase
::PARAM_ALL
] )
685 ?
$settings[ApiBase
::PARAM_ALL
]
687 if ( $allowAll ||
$settings[ApiBase
::PARAM_TYPE
] === 'namespace' ) {
688 if ( $settings[ApiBase
::PARAM_TYPE
] === 'namespace' ) {
689 $allSpecifier = ApiBase
::ALL_DEFAULT_STRING
;
691 $allSpecifier = ( is_string( $allowAll ) ?
$allowAll : ApiBase
::ALL_DEFAULT_STRING
);
693 $info[] = $context->msg( 'api-help-param-multi-all' )
694 ->params( $allSpecifier )
701 $default = isset( $settings[ApiBase
::PARAM_DFLT
] )
702 ?
$settings[ApiBase
::PARAM_DFLT
]
704 if ( $default === '' ) {
705 $info[] = $context->msg( 'api-help-param-default-empty' )
707 } elseif ( $default !== null && $default !== false ) {
708 // We can't know whether this contains LTR or RTL text.
709 $info[] = $context->msg( 'api-help-param-default' )
710 ->params( Html
::element( 'span', [ 'dir' => 'auto' ], $default ) )
714 if ( !array_filter( $description ) ) {
715 $description = [ self
::wrap(
716 $context->msg( 'api-help-param-no-description' ),
721 // Add "deprecated" flag
722 if ( !empty( $settings[ApiBase
::PARAM_DEPRECATED
] ) ) {
723 $help['parameters'] .= Html
::openElement( 'dd',
724 [ 'class' => 'info' ] );
725 $help['parameters'] .= self
::wrap(
726 $context->msg( 'api-help-param-deprecated' ),
727 'apihelp-deprecated', 'strong'
729 $help['parameters'] .= Html
::closeElement( 'dd' );
732 if ( $description ) {
733 $description = implode( '', $description );
734 $description = preg_replace( '!\s*</([oud]l)>\s*<\1>\s*!', "\n", $description );
735 $help['parameters'] .= Html
::rawElement( 'dd',
736 [ 'class' => 'description' ], $description );
739 foreach ( $info as $i ) {
740 $help['parameters'] .= Html
::rawElement( 'dd', [ 'class' => 'info' ], $i );
744 if ( $dynamicParams !== null ) {
745 $dynamicParams = ApiBase
::makeMessage( $dynamicParams, $context, [
746 $module->getModulePrefix(),
747 $module->getModuleName(),
748 $module->getModulePath()
750 $help['parameters'] .= Html
::element( 'dt', null, '*' );
751 $help['parameters'] .= Html
::rawElement( 'dd',
752 [ 'class' => 'description' ], $dynamicParams->parse() );
755 $help['parameters'] .= Html
::closeElement( 'dl' );
756 $help['parameters'] .= Html
::closeElement( 'div' );
759 $examples = $module->getExamplesMessages();
761 $help['examples'] .= Html
::openElement( 'div',
762 [ 'class' => 'apihelp-block apihelp-examples' ] );
763 $msg = $context->msg( 'api-help-examples' );
764 if ( !$msg->isDisabled() ) {
765 $help['examples'] .= self
::wrap(
766 $msg->numParams( count( $examples ) ), 'apihelp-block-head', 'div'
770 $help['examples'] .= Html
::openElement( 'dl' );
771 foreach ( $examples as $qs => $msg ) {
772 $msg = ApiBase
::makeMessage( $msg, $context, [
773 $module->getModulePrefix(),
774 $module->getModuleName(),
775 $module->getModulePath()
778 $link = wfAppendQuery( wfScript( 'api' ), $qs );
779 $sandbox = SpecialPage
::getTitleFor( 'ApiSandbox' )->getLocalURL() . '#' . $qs;
780 $help['examples'] .= Html
::rawElement( 'dt', null, $msg->parse() );
781 $help['examples'] .= Html
::rawElement( 'dd', null,
782 Html
::element( 'a', [ 'href' => $link, 'dir' => 'ltr' ], "api.php?$qs" ) . ' ' .
783 Html
::rawElement( 'a', [ 'href' => $sandbox ],
784 $context->msg( 'api-help-open-in-apisandbox' )->parse() )
787 $help['examples'] .= Html
::closeElement( 'dl' );
788 $help['examples'] .= Html
::closeElement( 'div' );
791 $subtocnumber = $tocnumber;
792 $subtocnumber[$level +
1] = 0;
794 'submodules' => $options['recursivesubmodules'],
795 'headerlevel' => $level +
1,
796 'tocnumber' => &$subtocnumber,
800 if ( $options['submodules'] && $module->getModuleManager() ) {
801 $manager = $module->getModuleManager();
803 foreach ( $groups as $group ) {
804 $names = $manager->getNames( $group );
806 foreach ( $names as $name ) {
807 $submodules[] = $manager->getModule( $name );
810 $help['submodules'] .= self
::getHelpInternal(
818 $module->modifyHelp( $help, $suboptions, $haveModules );
820 Hooks
::run( 'APIHelpModifyOutput', [ $module, &$help, $suboptions, &$haveModules ] );
822 $out .= implode( "\n", $help );
828 public function shouldCheckMaxlag() {
832 public function isReadMode() {
836 public function getCustomPrinter() {
837 $params = $this->extractRequestParams();
838 if ( $params['wrap'] ) {
842 $main = $this->getMain();
843 $errorPrinter = $main->createPrinterByName( $main->getParameter( 'format' ) );
844 return new ApiFormatRaw( $main, $errorPrinter );
847 public function getAllowedParams() {
850 ApiBase
::PARAM_DFLT
=> 'main',
851 ApiBase
::PARAM_ISMULTI
=> true,
853 'submodules' => false,
854 'recursivesubmodules' => false,
860 protected function getExamplesMessages() {
863 => 'apihelp-help-example-main',
864 'action=help&modules=query&submodules=1'
865 => 'apihelp-help-example-submodules',
866 'action=help&recursivesubmodules=1'
867 => 'apihelp-help-example-recursive',
868 'action=help&modules=help'
869 => 'apihelp-help-example-help',
870 'action=help&modules=query+info|query+categorymembers'
871 => 'apihelp-help-example-query',
875 public function getHelpUrls() {
877 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Main_page',
878 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:FAQ',
879 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Quick_start_guide',