Merge "Import: Handle uploads with sha1 starting with 0 properly"
[mediawiki.git] / includes / api / ApiHelp.php
blobb1942bc1a1ef600fcf229a79360fbc9af7daf210
1 <?php
2 /**
5 * Created on Aug 29, 2014
7 * Copyright © 2014 Brad Jorsch <bjorsch@wikimedia.org>
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
24 * @file
27 /**
28 * Class to output help for an API module
30 * @since 1.25 completely rewritten
31 * @ingroup API
33 class ApiHelp extends ApiBase {
34 public function execute() {
35 $params = $this->extractRequestParams();
36 $modules = array();
38 foreach ( $params['modules'] as $path ) {
39 $modules[] = $this->getModuleFromPath( $path );
42 // Get the help
43 $context = new DerivativeContext( $this->getMain()->getContext() );
44 $context->setSkin( SkinFactory::getDefaultInstance()->makeSkin( 'apioutput' ) );
45 $context->setLanguage( $this->getMain()->getLanguage() );
46 $context->setTitle( SpecialPage::getTitleFor( 'ApiHelp' ) );
47 $out = new OutputPage( $context );
48 $out->setCopyrightUrl( 'https://www.mediawiki.org/wiki/Special:MyLanguage/Copyright' );
49 $context->setOutput( $out );
51 self::getHelp( $context, $modules, $params );
53 // Grab the output from the skin
54 ob_start();
55 $context->getOutput()->output();
56 $html = ob_get_clean();
58 $result = $this->getResult();
59 if ( $params['wrap'] ) {
60 $data = array(
61 'mime' => 'text/html',
62 'help' => $html,
64 ApiResult::setSubelementsList( $data, 'help' );
65 $result->addValue( null, $this->getModuleName(), $data );
66 } else {
67 $result->reset();
68 $result->addValue( null, 'text', $html, ApiResult::NO_SIZE_CHECK );
69 $result->addValue( null, 'mime', 'text/html', ApiResult::NO_SIZE_CHECK );
73 /**
74 * Generate help for the specified modules
76 * Help is placed into the OutputPage object returned by
77 * $context->getOutput().
79 * Recognized options include:
80 * - headerlevel: (int) Header tag level
81 * - nolead: (bool) Skip the inclusion of api-help-lead
82 * - noheader: (bool) Skip the inclusion of the top-level section headers
83 * - submodules: (bool) Include help for submodules of the current module
84 * - recursivesubmodules: (bool) Include help for submodules recursively
85 * - helptitle: (string) Title to link for additional modules' help. Should contain $1.
86 * - toc: (bool) Include a table of contents
88 * @param IContextSource $context
89 * @param ApiBase[]|ApiBase $modules
90 * @param array $options Formatting options (described above)
91 * @return string
93 public static function getHelp( IContextSource $context, $modules, array $options ) {
94 global $wgContLang;
96 if ( !is_array( $modules ) ) {
97 $modules = array( $modules );
100 $out = $context->getOutput();
101 $out->addModules( 'mediawiki.apihelp' );
102 if ( !empty( $options['toc'] ) ) {
103 $out->addModules( 'mediawiki.toc' );
105 $out->setPageTitle( $context->msg( 'api-help-title' ) );
107 $cache = ObjectCache::getMainWANInstance();
108 $cacheKey = null;
109 if ( count( $modules ) == 1 && $modules[0] instanceof ApiMain &&
110 $options['recursivesubmodules'] && $context->getLanguage() === $wgContLang
112 $cacheHelpTimeout = $context->getConfig()->get( 'APICacheHelpTimeout' );
113 if ( $cacheHelpTimeout > 0 ) {
114 // Get help text from cache if present
115 $cacheKey = wfMemcKey( 'apihelp', $modules[0]->getModulePath(),
116 (int)!empty( $options['toc'] ),
117 str_replace( ' ', '_', SpecialVersion::getVersion( 'nodb' ) ) );
118 $cached = $cache->get( $cacheKey );
119 if ( $cached ) {
120 $out->addHTML( $cached );
121 return;
125 if ( $out->getHTML() !== '' ) {
126 // Don't save to cache, there's someone else's content in the page
127 // already
128 $cacheKey = null;
131 $options['recursivesubmodules'] = !empty( $options['recursivesubmodules'] );
132 $options['submodules'] = $options['recursivesubmodules'] || !empty( $options['submodules'] );
134 // Prepend lead
135 if ( empty( $options['nolead'] ) ) {
136 $msg = $context->msg( 'api-help-lead' );
137 if ( !$msg->isDisabled() ) {
138 $out->addHTML( $msg->parseAsBlock() );
142 $haveModules = array();
143 $html = self::getHelpInternal( $context, $modules, $options, $haveModules );
144 if ( !empty( $options['toc'] ) && $haveModules ) {
145 $out->addHTML( Linker::generateTOC( $haveModules, $context->getLanguage() ) );
147 $out->addHTML( $html );
149 $helptitle = isset( $options['helptitle'] ) ? $options['helptitle'] : null;
150 $html = self::fixHelpLinks( $out->getHTML(), $helptitle, $haveModules );
151 $out->clearHTML();
152 $out->addHTML( $html );
154 if ( $cacheKey !== null ) {
155 $cache->set( $cacheKey, $out->getHTML(), $cacheHelpTimeout );
160 * Replace Special:ApiHelp links with links to api.php
162 * @param string $html
163 * @param string|null $helptitle Title to link to rather than api.php, must contain '$1'
164 * @param array $localModules Keys are modules to link within the current page, values are ignored
165 * @return string
167 public static function fixHelpLinks( $html, $helptitle = null, $localModules = array() ) {
168 $formatter = new HtmlFormatter( $html );
169 $doc = $formatter->getDoc();
170 $xpath = new DOMXPath( $doc );
171 $nodes = $xpath->query( '//a[@href][not(contains(@class,\'apihelp-linktrail\'))]' );
172 foreach ( $nodes as $node ) {
173 $href = $node->getAttribute( 'href' );
174 do {
175 $old = $href;
176 $href = rawurldecode( $href );
177 } while ( $old !== $href );
178 if ( preg_match( '!Special:ApiHelp/([^&/|#]+)((?:#.*)?)!', $href, $m ) ) {
179 if ( isset( $localModules[$m[1]] ) ) {
180 $href = $m[2] === '' ? '#' . $m[1] : $m[2];
181 } elseif ( $helptitle !== null ) {
182 $href = Title::newFromText( str_replace( '$1', $m[1], $helptitle ) . $m[2] )
183 ->getFullURL();
184 } else {
185 $href = wfAppendQuery( wfScript( 'api' ), array(
186 'action' => 'help',
187 'modules' => $m[1],
188 ) ) . $m[2];
190 $node->setAttribute( 'href', $href );
191 $node->removeAttribute( 'title' );
195 return $formatter->getText();
199 * Wrap a message in HTML with a class.
201 * @param Message $msg
202 * @param string $class
203 * @param string $tag
204 * @return string
206 private static function wrap( Message $msg, $class, $tag = 'span' ) {
207 return Html::rawElement( $tag, array( 'class' => $class ),
208 $msg->parse()
213 * Recursively-called function to actually construct the help
215 * @param IContextSource $context
216 * @param ApiBase[] $modules
217 * @param array $options
218 * @param array &$haveModules
219 * @return string
221 private static function getHelpInternal( IContextSource $context, array $modules,
222 array $options, &$haveModules
224 $out = '';
226 $level = empty( $options['headerlevel'] ) ? 2 : $options['headerlevel'];
227 if ( empty( $options['tocnumber'] ) ) {
228 $tocnumber = array( 2 => 0 );
229 } else {
230 $tocnumber = &$options['tocnumber'];
233 foreach ( $modules as $module ) {
234 $tocnumber[$level]++;
235 $path = $module->getModulePath();
236 $module->setContext( $context );
237 $help = array(
238 'header' => '',
239 'flags' => '',
240 'description' => '',
241 'help-urls' => '',
242 'parameters' => '',
243 'examples' => '',
244 'submodules' => '',
247 if ( empty( $options['noheader'] ) || !empty( $options['toc'] ) ) {
248 $anchor = $path;
249 $i = 1;
250 while ( isset( $haveModules[$anchor] ) ) {
251 $anchor = $path . '|' . ++$i;
254 if ( $module->isMain() ) {
255 $header = $context->msg( 'api-help-main-header' )->parse();
256 } else {
257 $name = $module->getModuleName();
258 $header = $module->getParent()->getModuleManager()->getModuleGroup( $name ) .
259 "=$name";
260 if ( $module->getModulePrefix() !== '' ) {
261 $header .= ' ' .
262 $context->msg( 'parentheses', $module->getModulePrefix() )->parse();
265 $haveModules[$anchor] = array(
266 'toclevel' => count( $tocnumber ),
267 'level' => $level,
268 'anchor' => $anchor,
269 'line' => $header,
270 'number' => join( '.', $tocnumber ),
271 'index' => false,
273 if ( empty( $options['noheader'] ) ) {
274 $help['header'] .= Html::element( 'h' . min( 6, $level ),
275 array( 'id' => $anchor, 'class' => 'apihelp-header' ),
276 $header
279 } else {
280 $haveModules[$path] = true;
283 $links = array();
284 $any = false;
285 for ( $m = $module; $m !== null; $m = $m->getParent() ) {
286 $name = $m->getModuleName();
287 if ( $name === 'main_int' ) {
288 $name = 'main';
291 if ( count( $modules ) === 1 && $m === $modules[0] &&
292 !( !empty( $options['submodules'] ) && $m->getModuleManager() )
294 $link = Html::element( 'b', null, $name );
295 } else {
296 $link = SpecialPage::getTitleFor( 'ApiHelp', $m->getModulePath() )->getLocalURL();
297 $link = Html::element( 'a',
298 array( 'href' => $link, 'class' => 'apihelp-linktrail' ),
299 $name
301 $any = true;
303 array_unshift( $links, $link );
305 if ( $any ) {
306 $help['header'] .= self::wrap(
307 $context->msg( 'parentheses' )
308 ->rawParams( $context->getLanguage()->pipeList( $links ) ),
309 'apihelp-linktrail', 'div'
313 $flags = $module->getHelpFlags();
314 $help['flags'] .= Html::openElement( 'div',
315 array( 'class' => 'apihelp-block apihelp-flags' ) );
316 $msg = $context->msg( 'api-help-flags' );
317 if ( !$msg->isDisabled() ) {
318 $help['flags'] .= self::wrap(
319 $msg->numParams( count( $flags ) ), 'apihelp-block-head', 'div'
322 $help['flags'] .= Html::openElement( 'ul' );
323 foreach ( $flags as $flag ) {
324 $help['flags'] .= Html::rawElement( 'li', null,
325 self::wrap( $context->msg( "api-help-flag-$flag" ), "apihelp-flag-$flag" )
328 $sourceInfo = $module->getModuleSourceInfo();
329 if ( $sourceInfo ) {
330 if ( isset( $sourceInfo['namemsg'] ) ) {
331 $extname = $context->msg( $sourceInfo['namemsg'] )->text();
332 } else {
333 $extname = $sourceInfo['name'];
335 $help['flags'] .= Html::rawElement( 'li', null,
336 self::wrap(
337 $context->msg( 'api-help-source', $extname, $sourceInfo['name'] ),
338 'apihelp-source'
342 $link = SpecialPage::getTitleFor( 'Version', 'License/' . $sourceInfo['name'] );
343 if ( isset( $sourceInfo['license-name'] ) ) {
344 $msg = $context->msg( 'api-help-license', $link, $sourceInfo['license-name'] );
345 } elseif ( SpecialVersion::getExtLicenseFileName( dirname( $sourceInfo['path'] ) ) ) {
346 $msg = $context->msg( 'api-help-license-noname', $link );
347 } else {
348 $msg = $context->msg( 'api-help-license-unknown' );
350 $help['flags'] .= Html::rawElement( 'li', null,
351 self::wrap( $msg, 'apihelp-license' )
353 } else {
354 $help['flags'] .= Html::rawElement( 'li', null,
355 self::wrap( $context->msg( 'api-help-source-unknown' ), 'apihelp-source' )
357 $help['flags'] .= Html::rawElement( 'li', null,
358 self::wrap( $context->msg( 'api-help-license-unknown' ), 'apihelp-license' )
361 $help['flags'] .= Html::closeElement( 'ul' );
362 $help['flags'] .= Html::closeElement( 'div' );
364 foreach ( $module->getFinalDescription() as $msg ) {
365 $msg->setContext( $context );
366 $help['description'] .= $msg->parseAsBlock();
369 $urls = $module->getHelpUrls();
370 if ( $urls ) {
371 $help['help-urls'] .= Html::openElement( 'div',
372 array( 'class' => 'apihelp-block apihelp-help-urls' )
374 $msg = $context->msg( 'api-help-help-urls' );
375 if ( !$msg->isDisabled() ) {
376 $help['help-urls'] .= self::wrap(
377 $msg->numParams( count( $urls ) ), 'apihelp-block-head', 'div'
380 if ( !is_array( $urls ) ) {
381 $urls = array( $urls );
383 $help['help-urls'] .= Html::openElement( 'ul' );
384 foreach ( $urls as $url ) {
385 $help['help-urls'] .= Html::rawElement( 'li', null,
386 Html::element( 'a', array( 'href' => $url ), $url )
389 $help['help-urls'] .= Html::closeElement( 'ul' );
390 $help['help-urls'] .= Html::closeElement( 'div' );
393 $params = $module->getFinalParams( ApiBase::GET_VALUES_FOR_HELP );
394 $groups = array();
395 if ( $params ) {
396 $help['parameters'] .= Html::openElement( 'div',
397 array( 'class' => 'apihelp-block apihelp-parameters' )
399 $msg = $context->msg( 'api-help-parameters' );
400 if ( !$msg->isDisabled() ) {
401 $help['parameters'] .= self::wrap(
402 $msg->numParams( count( $params ) ), 'apihelp-block-head', 'div'
405 $help['parameters'] .= Html::openElement( 'dl' );
407 $descriptions = $module->getFinalParamDescription();
409 foreach ( $params as $name => $settings ) {
410 if ( !is_array( $settings ) ) {
411 $settings = array( ApiBase::PARAM_DFLT => $settings );
414 $help['parameters'] .= Html::element( 'dt', null,
415 $module->encodeParamName( $name ) );
417 // Add description
418 $description = array();
419 if ( isset( $descriptions[$name] ) ) {
420 foreach ( $descriptions[$name] as $msg ) {
421 $msg->setContext( $context );
422 $description[] = $msg->parseAsBlock();
426 // Add usage info
427 $info = array();
429 // Required?
430 if ( !empty( $settings[ApiBase::PARAM_REQUIRED] ) ) {
431 $info[] = $context->msg( 'api-help-param-required' )->parse();
434 // Custom info?
435 if ( !empty( $settings[ApiBase::PARAM_HELP_MSG_INFO] ) ) {
436 foreach ( $settings[ApiBase::PARAM_HELP_MSG_INFO] as $i ) {
437 $tag = array_shift( $i );
438 $info[] = $context->msg( "apihelp-{$path}-paraminfo-{$tag}" )
439 ->numParams( count( $i ) )
440 ->params( $context->getLanguage()->commaList( $i ) )
441 ->params( $module->getModulePrefix() )
442 ->parse();
446 // Type documentation
447 if ( !isset( $settings[ApiBase::PARAM_TYPE] ) ) {
448 $dflt = isset( $settings[ApiBase::PARAM_DFLT] )
449 ? $settings[ApiBase::PARAM_DFLT]
450 : null;
451 if ( is_bool( $dflt ) ) {
452 $settings[ApiBase::PARAM_TYPE] = 'boolean';
453 } elseif ( is_string( $dflt ) || is_null( $dflt ) ) {
454 $settings[ApiBase::PARAM_TYPE] = 'string';
455 } elseif ( is_int( $dflt ) ) {
456 $settings[ApiBase::PARAM_TYPE] = 'integer';
459 if ( isset( $settings[ApiBase::PARAM_TYPE] ) ) {
460 $type = $settings[ApiBase::PARAM_TYPE];
461 $multi = !empty( $settings[ApiBase::PARAM_ISMULTI] );
462 $hintPipeSeparated = true;
463 $count = ApiBase::LIMIT_SML2 + 1;
465 if ( is_array( $type ) ) {
466 $count = count( $type );
467 $links = isset( $settings[ApiBase::PARAM_VALUE_LINKS] )
468 ? $settings[ApiBase::PARAM_VALUE_LINKS]
469 : array();
470 $type = array_map( function ( $v ) use ( $links ) {
471 $ret = wfEscapeWikiText( $v );
472 if ( isset( $links[$v] ) ) {
473 $ret = "[[{$links[$v]}|$ret]]";
475 return $ret;
476 }, $type );
477 $i = array_search( '', $type, true );
478 if ( $i === false ) {
479 $type = $context->getLanguage()->commaList( $type );
480 } else {
481 unset( $type[$i] );
482 $type = $context->msg( 'api-help-param-list-can-be-empty' )
483 ->numParams( count( $type ) )
484 ->params( $context->getLanguage()->commaList( $type ) )
485 ->parse();
487 $info[] = $context->msg( 'api-help-param-list' )
488 ->params( $multi ? 2 : 1 )
489 ->params( $type )
490 ->parse();
491 $hintPipeSeparated = false;
492 } else {
493 switch ( $type ) {
494 case 'submodule':
495 $groups[] = $name;
496 if ( isset( $settings[ApiBase::PARAM_SUBMODULE_MAP] ) ) {
497 $map = $settings[ApiBase::PARAM_SUBMODULE_MAP];
498 ksort( $map );
499 $submodules = array();
500 foreach ( $map as $v => $m ) {
501 $submodules[] = "[[Special:ApiHelp/{$m}|{$v}]]";
503 } else {
504 $submodules = $module->getModuleManager()->getNames( $name );
505 sort( $submodules );
506 $prefix = $module->isMain()
507 ? '' : ( $module->getModulePath() . '+' );
508 $submodules = array_map( function ( $name ) use ( $prefix ) {
509 return "[[Special:ApiHelp/{$prefix}{$name}|{$name}]]";
510 }, $submodules );
512 $count = count( $submodules );
513 $info[] = $context->msg( 'api-help-param-list' )
514 ->params( $multi ? 2 : 1 )
515 ->params( $context->getLanguage()->commaList( $submodules ) )
516 ->parse();
517 $hintPipeSeparated = false;
518 // No type message necessary, we have a list of values.
519 $type = null;
520 break;
522 case 'namespace':
523 $namespaces = MWNamespace::getValidNamespaces();
524 $count = count( $namespaces );
525 $info[] = $context->msg( 'api-help-param-list' )
526 ->params( $multi ? 2 : 1 )
527 ->params( $context->getLanguage()->commaList( $namespaces ) )
528 ->parse();
529 $hintPipeSeparated = false;
530 // No type message necessary, we have a list of values.
531 $type = null;
532 break;
534 case 'limit':
535 if ( isset( $settings[ApiBase::PARAM_MAX2] ) ) {
536 $info[] = $context->msg( 'api-help-param-limit2' )
537 ->numParams( $settings[ApiBase::PARAM_MAX] )
538 ->numParams( $settings[ApiBase::PARAM_MAX2] )
539 ->parse();
540 } else {
541 $info[] = $context->msg( 'api-help-param-limit' )
542 ->numParams( $settings[ApiBase::PARAM_MAX] )
543 ->parse();
545 break;
547 case 'integer':
548 // Possible messages:
549 // api-help-param-integer-min,
550 // api-help-param-integer-max,
551 // api-help-param-integer-minmax
552 $suffix = '';
553 $min = $max = 0;
554 if ( isset( $settings[ApiBase::PARAM_MIN] ) ) {
555 $suffix .= 'min';
556 $min = $settings[ApiBase::PARAM_MIN];
558 if ( isset( $settings[ApiBase::PARAM_MAX] ) ) {
559 $suffix .= 'max';
560 $max = $settings[ApiBase::PARAM_MAX];
562 if ( $suffix !== '' ) {
563 $info[] =
564 $context->msg( "api-help-param-integer-$suffix" )
565 ->params( $multi ? 2 : 1 )
566 ->numParams( $min, $max )
567 ->parse();
569 break;
571 case 'upload':
572 $info[] = $context->msg( 'api-help-param-upload' )
573 ->parse();
574 // No type message necessary, api-help-param-upload should handle it.
575 $type = null;
576 break;
578 case 'string':
579 case 'text':
580 // Displaying a type message here would be useless.
581 $type = null;
582 break;
586 // Add type. Messages for grep: api-help-param-type-limit
587 // api-help-param-type-integer api-help-param-type-boolean
588 // api-help-param-type-timestamp api-help-param-type-user
589 // api-help-param-type-password
590 if ( is_string( $type ) ) {
591 $msg = $context->msg( "api-help-param-type-$type" );
592 if ( !$msg->isDisabled() ) {
593 $info[] = $msg->params( $multi ? 2 : 1 )->parse();
597 if ( $multi ) {
598 $extra = array();
599 if ( $hintPipeSeparated ) {
600 $extra[] = $context->msg( 'api-help-param-multi-separate' )->parse();
602 if ( $count > ApiBase::LIMIT_SML1 ) {
603 $extra[] = $context->msg( 'api-help-param-multi-max' )
604 ->numParams( ApiBase::LIMIT_SML1, ApiBase::LIMIT_SML2 )
605 ->parse();
607 if ( $extra ) {
608 $info[] = join( ' ', $extra );
613 // Add default
614 $default = isset( $settings[ApiBase::PARAM_DFLT] )
615 ? $settings[ApiBase::PARAM_DFLT]
616 : null;
617 if ( $default === '' ) {
618 $info[] = $context->msg( 'api-help-param-default-empty' )
619 ->parse();
620 } elseif ( $default !== null && $default !== false ) {
621 $info[] = $context->msg( 'api-help-param-default' )
622 ->params( wfEscapeWikiText( $default ) )
623 ->parse();
626 if ( !array_filter( $description ) ) {
627 $description = array( self::wrap(
628 $context->msg( 'api-help-param-no-description' ),
629 'apihelp-empty'
630 ) );
633 // Add "deprecated" flag
634 if ( !empty( $settings[ApiBase::PARAM_DEPRECATED] ) ) {
635 $help['parameters'] .= Html::openElement( 'dd',
636 array( 'class' => 'info' ) );
637 $help['parameters'] .= self::wrap(
638 $context->msg( 'api-help-param-deprecated' ),
639 'apihelp-deprecated', 'strong'
641 $help['parameters'] .= Html::closeElement( 'dd' );
644 if ( $description ) {
645 $description = join( '', $description );
646 $description = preg_replace( '!\s*</([oud]l)>\s*<\1>\s*!', "\n", $description );
647 $help['parameters'] .= Html::rawElement( 'dd',
648 array( 'class' => 'description' ), $description );
651 foreach ( $info as $i ) {
652 $help['parameters'] .= Html::rawElement( 'dd', array( 'class' => 'info' ), $i );
656 $help['parameters'] .= Html::closeElement( 'dl' );
657 $help['parameters'] .= Html::closeElement( 'div' );
660 $examples = $module->getExamplesMessages();
661 if ( $examples ) {
662 $help['examples'] .= Html::openElement( 'div',
663 array( 'class' => 'apihelp-block apihelp-examples' ) );
664 $msg = $context->msg( 'api-help-examples' );
665 if ( !$msg->isDisabled() ) {
666 $help['examples'] .= self::wrap(
667 $msg->numParams( count( $examples ) ), 'apihelp-block-head', 'div'
671 $help['examples'] .= Html::openElement( 'dl' );
672 foreach ( $examples as $qs => $msg ) {
673 $msg = ApiBase::makeMessage( $msg, $context, array(
674 $module->getModulePrefix(),
675 $module->getModuleName(),
676 $module->getModulePath()
677 ) );
679 $link = wfAppendQuery( wfScript( 'api' ), $qs );
680 $help['examples'] .= Html::rawElement( 'dt', null, $msg->parse() );
681 $help['examples'] .= Html::rawElement( 'dd', null,
682 Html::element( 'a', array( 'href' => $link ), "api.php?$qs" )
685 $help['examples'] .= Html::closeElement( 'dl' );
686 $help['examples'] .= Html::closeElement( 'div' );
689 $subtocnumber = $tocnumber;
690 $subtocnumber[$level + 1] = 0;
691 $suboptions = array(
692 'submodules' => $options['recursivesubmodules'],
693 'headerlevel' => $level + 1,
694 'tocnumber' => &$subtocnumber,
695 'noheader' => false,
696 ) + $options;
698 if ( $options['submodules'] && $module->getModuleManager() ) {
699 $manager = $module->getModuleManager();
700 $submodules = array();
701 foreach ( $groups as $group ) {
702 $names = $manager->getNames( $group );
703 sort( $names );
704 foreach ( $names as $name ) {
705 $submodules[] = $manager->getModule( $name );
708 $help['submodules'] .= self::getHelpInternal(
709 $context,
710 $submodules,
711 $suboptions,
712 $haveModules
716 $module->modifyHelp( $help, $suboptions, $haveModules );
718 Hooks::run( 'APIHelpModifyOutput', array( $module, &$help, $suboptions, &$haveModules ) );
720 $out .= join( "\n", $help );
723 return $out;
726 public function shouldCheckMaxlag() {
727 return false;
730 public function isReadMode() {
731 return false;
734 public function getCustomPrinter() {
735 $params = $this->extractRequestParams();
736 if ( $params['wrap'] ) {
737 return null;
740 $main = $this->getMain();
741 $errorPrinter = $main->createPrinterByName( $main->getParameter( 'format' ) );
742 return new ApiFormatRaw( $main, $errorPrinter );
745 public function getAllowedParams() {
746 return array(
747 'modules' => array(
748 ApiBase::PARAM_DFLT => 'main',
749 ApiBase::PARAM_ISMULTI => true,
751 'submodules' => false,
752 'recursivesubmodules' => false,
753 'wrap' => false,
754 'toc' => false,
758 protected function getExamplesMessages() {
759 return array(
760 'action=help'
761 => 'apihelp-help-example-main',
762 'action=help&modules=query&submodules=1'
763 => 'apihelp-help-example-submodules',
764 'action=help&recursivesubmodules=1'
765 => 'apihelp-help-example-recursive',
766 'action=help&modules=help'
767 => 'apihelp-help-example-help',
768 'action=help&modules=query+info|query+categorymembers'
769 => 'apihelp-help-example-query',
773 public function getHelpUrls() {
774 return array(
775 'https://www.mediawiki.org/wiki/API:Main_page',
776 'https://www.mediawiki.org/wiki/API:FAQ',
777 'https://www.mediawiki.org/wiki/API:Quick_start_guide',