Merge "Add namespace aliases for Western Baluchi (bgn)"
[lhc/web/wiklou.git] / includes / api / ApiHelp.php
1 <?php
2 /**
3 *
4 *
5 * Created on Aug 29, 2014
6 *
7 * Copyright © 2014 Brad Jorsch <bjorsch@wikimedia.org>
8 *
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.
13 *
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.
18 *
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
23 *
24 * @file
25 */
26
27 /**
28 * Class to output help for an API module
29 *
30 * @since 1.25 completely rewritten
31 * @ingroup API
32 */
33 class ApiHelp extends ApiBase {
34 public function execute() {
35 $params = $this->extractRequestParams();
36 $modules = array();
37
38 foreach ( $params['modules'] as $path ) {
39 $modules[] = $this->getModuleFromPath( $path );
40 }
41
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 $context->setOutput( $out );
49
50 self::getHelp( $context, $modules, $params );
51
52 // Grab the output from the skin
53 ob_start();
54 $context->getOutput()->output();
55 $html = ob_get_clean();
56
57 $result = $this->getResult();
58 if ( $params['wrap'] ) {
59 $data = array(
60 'mime' => 'text/html',
61 'help' => $html,
62 );
63 ApiResult::setSubelementsList( $data, 'help' );
64 $result->addValue( null, $this->getModuleName(), $data );
65 } else {
66 $result->reset();
67 $result->addValue( null, 'text', $html, ApiResult::NO_SIZE_CHECK );
68 $result->addValue( null, 'mime', 'text/html', ApiResult::NO_SIZE_CHECK );
69 }
70 }
71
72 /**
73 * Generate help for the specified modules
74 *
75 * Help is placed into the OutputPage object returned by
76 * $context->getOutput().
77 *
78 * Recognized options include:
79 * - headerlevel: (int) Header tag level
80 * - nolead: (bool) Skip the inclusion of api-help-lead
81 * - noheader: (bool) Skip the inclusion of the top-level section headers
82 * - submodules: (bool) Include help for submodules of the current module
83 * - recursivesubmodules: (bool) Include help for submodules recursively
84 * - helptitle: (string) Title to link for additional modules' help. Should contain $1.
85 *
86 * @param IContextSource $context
87 * @param ApiBase[]|ApiBase $modules
88 * @param array $options Formatting options (described above)
89 * @return string
90 */
91 public static function getHelp( IContextSource $context, $modules, array $options ) {
92 global $wgMemc, $wgContLang;
93
94 if ( !is_array( $modules ) ) {
95 $modules = array( $modules );
96 }
97
98 $out = $context->getOutput();
99 $out->addModules( 'mediawiki.apihelp' );
100 $out->setPageTitle( $context->msg( 'api-help-title' ) );
101
102 $cacheKey = null;
103 if ( count( $modules ) == 1 && $modules[0] instanceof ApiMain &&
104 $options['recursivesubmodules'] && $context->getLanguage() === $wgContLang
105 ) {
106 $cacheHelpTimeout = $context->getConfig()->get( 'APICacheHelpTimeout' );
107 if ( $cacheHelpTimeout > 0 ) {
108 // Get help text from cache if present
109 $cacheKey = wfMemcKey( 'apihelp', $modules[0]->getModulePath(),
110 str_replace( ' ', '_', SpecialVersion::getVersion( 'nodb' ) ) );
111 $cached = $wgMemc->get( $cacheKey );
112 if ( $cached ) {
113 $out->addHTML( $cached );
114 return;
115 }
116 }
117 }
118 if ( $out->getHTML() !== '' ) {
119 // Don't save to cache, there's someone else's content in the page
120 // already
121 $cacheKey = null;
122 }
123
124 $options['recursivesubmodules'] = !empty( $options['recursivesubmodules'] );
125 $options['submodules'] = $options['recursivesubmodules'] || !empty( $options['submodules'] );
126
127 // Prepend lead
128 if ( empty( $options['nolead'] ) ) {
129 $msg = $context->msg( 'api-help-lead' );
130 if ( !$msg->isDisabled() ) {
131 $out->addHTML( $msg->parseAsBlock() );
132 }
133 }
134
135 $haveModules = array();
136 $out->addHTML( self::getHelpInternal( $context, $modules, $options, $haveModules ) );
137
138 $helptitle = isset( $options['helptitle'] ) ? $options['helptitle'] : null;
139 $html = self::fixHelpLinks( $out->getHTML(), $helptitle, $haveModules );
140 $out->clearHTML();
141 $out->addHTML( $html );
142
143 if ( $cacheKey !== null ) {
144 $wgMemc->set( $cacheKey, $out->getHTML(), $cacheHelpTimeout );
145 }
146 }
147
148 /**
149 * Replace Special:ApiHelp links with links to api.php
150 *
151 * @param string $html
152 * @param string|null $helptitle Title to link to rather than api.php, must contain '$1'
153 * @param array $localModules Modules to link within the current page
154 * @return string
155 */
156 public static function fixHelpLinks( $html, $helptitle = null, $localModules = array() ) {
157 $formatter = new HtmlFormatter( $html );
158 $doc = $formatter->getDoc();
159 $xpath = new DOMXPath( $doc );
160 $nodes = $xpath->query( '//a[@href][not(contains(@class,\'apihelp-linktrail\'))]' );
161 foreach ( $nodes as $node ) {
162 $href = $node->getAttribute( 'href' );
163 do {
164 $old = $href;
165 $href = rawurldecode( $href );
166 } while ( $old !== $href );
167 if ( preg_match( '!Special:ApiHelp/([^&/|#]+)((?:#.*)?)!', $href, $m ) ) {
168 if ( isset( $localModules[$m[1]] ) ) {
169 $href = $m[2] === '' ? '#' . $m[1] : $m[2];
170 } elseif ( $helptitle !== null ) {
171 $href = Title::newFromText( str_replace( '$1', $m[1], $helptitle ) . $m[2] )
172 ->getFullUrl();
173 } else {
174 $href = wfAppendQuery( wfScript( 'api' ), array(
175 'action' => 'help',
176 'modules' => $m[1],
177 ) ) . $m[2];
178 }
179 $node->setAttribute( 'href', $href );
180 $node->removeAttribute( 'title' );
181 }
182 }
183
184 return $formatter->getText();
185 }
186
187 /**
188 * Wrap a message in HTML with a class.
189 *
190 * @param Message $msg
191 * @param string $class
192 * @param string $tag
193 * @return string
194 */
195 private static function wrap( Message $msg, $class, $tag = 'span' ) {
196 return Html::rawElement( $tag, array( 'class' => $class ),
197 $msg->parse()
198 );
199 }
200
201 /**
202 * Recursively-called function to actually construct the help
203 *
204 * @param IContextSource $context
205 * @param ApiBase[] $modules
206 * @param array $options
207 * @param array &$haveModules
208 * @return string
209 */
210 private static function getHelpInternal( IContextSource $context, array $modules,
211 array $options, &$haveModules
212 ) {
213 $out = '';
214
215 $level = min( 6, empty( $options['headerlevel'] ) ? 2 : $options['headerlevel'] );
216 $options['headerlevel'] = $level;
217
218 foreach ( $modules as $module ) {
219 $haveModules[$module->getModulePath()] = true;
220 $module->setContext( $context );
221 $help = array(
222 'header' => '',
223 'flags' => '',
224 'description' => '',
225 'help-urls' => '',
226 'parameters' => '',
227 'examples' => '',
228 'submodules' => '',
229 );
230
231 if ( empty( $options['noheader'] ) ) {
232 $path = $module->getModulePath();
233 if ( $module->isMain() ) {
234 $header = $context->msg( 'api-help-main-header' )->parse();
235 } else {
236 $name = $module->getModuleName();
237 $header = $module->getParent()->getModuleManager()->getModuleGroup( $name ) .
238 "=$name";
239 if ( $module->getModulePrefix() !== '' ) {
240 $header .= ' ' .
241 $context->msg( 'parentheses', $module->getModulePrefix() )->parse();
242 }
243 }
244 $help['header'] .= Html::element( "h$level",
245 array( 'id' => $path, 'class' => 'apihelp-header' ),
246 $header
247 );
248 }
249
250 $links = array();
251 $any = false;
252 for ( $m = $module; $m !== null; $m = $m->getParent() ) {
253 $name = $m->getModuleName();
254 if ( $name === 'main_int' ) {
255 $name = 'main';
256 }
257
258 if ( count( $modules ) === 1 && $m === $modules[0] &&
259 !( !empty( $options['submodules'] ) && $m->getModuleManager() )
260 ) {
261 $link = Html::element( 'b', null, $name );
262 } else {
263 $link = SpecialPage::getTitleFor( 'ApiHelp', $m->getModulePath() )->getLocalURL();
264 $link = Html::element( 'a',
265 array( 'href' => $link, 'class' => 'apihelp-linktrail' ),
266 $name
267 );
268 $any = true;
269 }
270 array_unshift( $links, $link );
271 }
272 if ( $any ) {
273 $help['header'] .= self::wrap(
274 $context->msg( 'parentheses' )
275 ->rawParams( $context->getLanguage()->pipeList( $links ) ),
276 'apihelp-linktrail', 'div'
277 );
278 }
279
280 $help['flags'] .= Html::openElement( 'div',
281 array( 'class' => 'apihelp-block apihelp-flags' ) );
282 $msg = $context->msg( 'api-help-flags' );
283 if ( !$msg->isDisabled() ) {
284 $help['flags'] .= self::wrap(
285 $msg->numParams( count( $flags ) ), 'apihelp-block-head', 'div'
286 );
287 }
288 $help['flags'] .= Html::openElement( 'ul' );
289 foreach ( $module->getHelpFlags() as $flag ) {
290 $help['flags'] .= Html::rawElement( 'li', null,
291 self::wrap( $context->msg( "api-help-flag-$flag" ), "apihelp-flag-$flag" )
292 );
293 }
294 $sourceInfo = $module->getModuleSourceInfo();
295 if ( $sourceInfo ) {
296 if ( isset( $sourceInfo['namemsg'] ) ) {
297 $extname = $context->msg( $sourceInfo['namemsg'] )->text();
298 } else {
299 $extname = $sourceInfo['name'];
300 }
301 $help['flags'] .= Html::rawElement( 'li', null,
302 self::wrap(
303 $context->msg( 'api-help-source', $extname, $sourceInfo['name'] ),
304 'apihelp-source'
305 )
306 );
307
308 $link = SpecialPage::getTitleFor( 'Version', 'License/' . $sourceInfo['name'] );
309 if ( isset( $sourceInfo['license-name'] ) ) {
310 $msg = $context->msg( 'api-help-license', $link, $sourceInfo['license-name'] );
311 } elseif ( SpecialVersion::getExtLicenseFileName( dirname( $sourceInfo['path'] ) ) ) {
312 $msg = $context->msg( 'api-help-license-noname', $link );
313 } else {
314 $msg = $context->msg( 'api-help-license-unknown' );
315 }
316 $help['flags'] .= Html::rawElement( 'li', null,
317 self::wrap( $msg, 'apihelp-license' )
318 );
319 } else {
320 $help['flags'] .= Html::rawElement( 'li', null,
321 self::wrap( $context->msg( 'api-help-source-unknown' ), 'apihelp-source' )
322 );
323 $help['flags'] .= Html::rawElement( 'li', null,
324 self::wrap( $context->msg( 'api-help-license-unknown' ), 'apihelp-license' )
325 );
326 }
327 $help['flags'] .= Html::closeElement( 'ul' );
328 $help['flags'] .= Html::closeElement( 'div' );
329
330 foreach ( $module->getFinalDescription() as $msg ) {
331 $msg->setContext( $context );
332 $help['description'] .= $msg->parseAsBlock();
333 }
334
335 $urls = $module->getHelpUrls();
336 if ( $urls ) {
337 $help['help-urls'] .= Html::openElement( 'div',
338 array( 'class' => 'apihelp-block apihelp-help-urls' )
339 );
340 $msg = $context->msg( 'api-help-help-urls' );
341 if ( !$msg->isDisabled() ) {
342 $help['help-urls'] .= self::wrap(
343 $msg->numParams( count( $urls ) ), 'apihelp-block-head', 'div'
344 );
345 }
346 if ( !is_array( $urls ) ) {
347 $urls = array( $urls );
348 }
349 $help['help-urls'] .= Html::openElement( 'ul' );
350 foreach ( $urls as $url ) {
351 $help['help-urls'] .= Html::rawElement( 'li', null,
352 Html::element( 'a', array( 'href' => $url ), $url )
353 );
354 }
355 $help['help-urls'] .= Html::closeElement( 'ul' );
356 $help['help-urls'] .= Html::closeElement( 'div' );
357 }
358
359 $params = $module->getFinalParams( ApiBase::GET_VALUES_FOR_HELP );
360 $groups = array();
361 if ( $params ) {
362 $help['parameters'] .= Html::openElement( 'div',
363 array( 'class' => 'apihelp-block apihelp-parameters' )
364 );
365 $msg = $context->msg( 'api-help-parameters' );
366 if ( !$msg->isDisabled() ) {
367 $help['parameters'] .= self::wrap(
368 $msg->numParams( count( $params ) ), 'apihelp-block-head', 'div'
369 );
370 }
371 $help['parameters'] .= Html::openElement( 'dl' );
372
373 $descriptions = $module->getFinalParamDescription();
374
375 foreach ( $params as $name => $settings ) {
376 if ( !is_array( $settings ) ) {
377 $settings = array( ApiBase::PARAM_DFLT => $settings );
378 }
379
380 $help['parameters'] .= Html::element( 'dt', null,
381 $module->encodeParamName( $name ) );
382
383 // Add description
384 $description = array();
385 if ( isset( $descriptions[$name] ) ) {
386 foreach ( $descriptions[$name] as $msg ) {
387 $msg->setContext( $context );
388 $description[] = $msg->parseAsBlock();
389 }
390 }
391
392 // Add usage info
393 $info = array();
394
395 // Required?
396 if ( !empty( $settings[ApiBase::PARAM_REQUIRED] ) ) {
397 $info[] = $context->msg( 'api-help-param-required' )->parse();
398 }
399
400 // Custom info?
401 if ( !empty( $settings[ApiBase::PARAM_HELP_MSG_INFO] ) ) {
402 foreach ( $settings[ApiBase::PARAM_HELP_MSG_INFO] as $i ) {
403 $tag = array_shift( $i );
404 $info[] = $context->msg( "apihelp-{$path}-paraminfo-{$tag}" )
405 ->numParams( count( $i ) )
406 ->params( $context->getLanguage()->commaList( $i ) )
407 ->params( $module->getModulePrefix() )
408 ->parse();
409 }
410 }
411
412 // Type documentation
413 if ( !isset( $settings[ApiBase::PARAM_TYPE] ) ) {
414 $dflt = isset( $settings[ApiBase::PARAM_DFLT] )
415 ? $settings[ApiBase::PARAM_DFLT]
416 : null;
417 if ( is_bool( $dflt ) ) {
418 $settings[ApiBase::PARAM_TYPE] = 'boolean';
419 } elseif ( is_string( $dflt ) || is_null( $dflt ) ) {
420 $settings[ApiBase::PARAM_TYPE] = 'string';
421 } elseif ( is_int( $dflt ) ) {
422 $settings[ApiBase::PARAM_TYPE] = 'integer';
423 }
424 }
425 if ( isset( $settings[ApiBase::PARAM_TYPE] ) ) {
426 $type = $settings[ApiBase::PARAM_TYPE];
427 $multi = !empty( $settings[ApiBase::PARAM_ISMULTI] );
428 $hintPipeSeparated = true;
429 $count = ApiBase::LIMIT_SML2 + 1;
430
431 if ( is_array( $type ) ) {
432 $count = count( $type );
433 $links = isset( $settings[ApiBase::PARAM_VALUE_LINKS] )
434 ? $settings[ApiBase::PARAM_VALUE_LINKS]
435 : array();
436 $type = array_map( function ( $v ) use ( $links ) {
437 $ret = wfEscapeWikiText( $v );
438 if ( isset( $links[$v] ) ) {
439 $ret = "[[{$links[$v]}|$ret]]";
440 }
441 return $ret;
442 }, $type );
443 $i = array_search( '', $type, true );
444 if ( $i === false ) {
445 $type = $context->getLanguage()->commaList( $type );
446 } else {
447 unset( $type[$i] );
448 $type = $context->msg( 'api-help-param-list-can-be-empty' )
449 ->numParams( count( $type ) )
450 ->params( $context->getLanguage()->commaList( $type ) )
451 ->parse();
452 }
453 $info[] = $context->msg( 'api-help-param-list' )
454 ->params( $multi ? 2 : 1 )
455 ->params( $type )
456 ->parse();
457 $hintPipeSeparated = false;
458 } else {
459 switch ( $type ) {
460 case 'submodule':
461 $groups[] = $name;
462 $submodules = $module->getModuleManager()->getNames( $name );
463 $count = count( $submodules );
464 sort( $submodules );
465 $prefix = $module->isMain()
466 ? '' : ( $module->getModulePath() . '+' );
467 $submodules = array_map( function ( $name ) use ( $prefix ) {
468 return "[[Special:ApiHelp/{$prefix}{$name}|{$name}]]";
469 }, $submodules );
470 $info[] = $context->msg( 'api-help-param-list' )
471 ->params( $multi ? 2 : 1 )
472 ->params( $context->getLanguage()->commaList( $submodules ) )
473 ->parse();
474 $hintPipeSeparated = false;
475 // No type message necessary, we have a list of values.
476 $type = null;
477 break;
478
479 case 'namespace':
480 $namespaces = MWNamespace::getValidNamespaces();
481 $count = count( $namespaces );
482 $info[] = $context->msg( 'api-help-param-list' )
483 ->params( $multi ? 2 : 1 )
484 ->params( $context->getLanguage()->commaList( $namespaces ) )
485 ->parse();
486 $hintPipeSeparated = false;
487 // No type message necessary, we have a list of values.
488 $type = null;
489 break;
490
491 case 'limit':
492 if ( isset( $settings[ApiBase::PARAM_MAX2] ) ) {
493 $info[] = $context->msg( 'api-help-param-limit2' )
494 ->numParams( $settings[ApiBase::PARAM_MAX] )
495 ->numParams( $settings[ApiBase::PARAM_MAX2] )
496 ->parse();
497 } else {
498 $info[] = $context->msg( 'api-help-param-limit' )
499 ->numParams( $settings[ApiBase::PARAM_MAX] )
500 ->parse();
501 }
502 break;
503
504 case 'integer':
505 // Possible messages:
506 // api-help-param-integer-min,
507 // api-help-param-integer-max,
508 // api-help-param-integer-minmax
509 $suffix = '';
510 $min = $max = 0;
511 if ( isset( $settings[ApiBase::PARAM_MIN] ) ) {
512 $suffix .= 'min';
513 $min = $settings[ApiBase::PARAM_MIN];
514 }
515 if ( isset( $settings[ApiBase::PARAM_MAX] ) ) {
516 $suffix .= 'max';
517 $max = $settings[ApiBase::PARAM_MAX];
518 }
519 if ( $suffix !== '' ) {
520 $info[] =
521 $context->msg( "api-help-param-integer-$suffix" )
522 ->params( $multi ? 2 : 1 )
523 ->numParams( $min, $max )
524 ->parse();
525 }
526 break;
527
528 case 'upload':
529 $info[] = $context->msg( 'api-help-param-upload' )
530 ->parse();
531 // No type message necessary, api-help-param-upload should handle it.
532 $type = null;
533 break;
534
535 case 'string':
536 // Displaying a type message here would be useless.
537 $type = null;
538 break;
539 }
540 }
541
542 // Add type. Messages for grep: api-help-param-type-limit
543 // api-help-param-type-integer api-help-param-type-boolean
544 // api-help-param-type-timestamp api-help-param-type-user
545 if ( is_string( $type ) ) {
546 $msg = $context->msg( "api-help-param-type-$type" );
547 if ( !$msg->isDisabled() ) {
548 $info[] = $msg->params( $multi ? 2 : 1 )->parse();
549 }
550 }
551
552 if ( $multi ) {
553 $extra = array();
554 if ( $hintPipeSeparated ) {
555 $extra[] = $context->msg( 'api-help-param-multi-separate' )->parse();
556 }
557 if ( $count > ApiBase::LIMIT_SML1 ) {
558 $extra[] = $context->msg( 'api-help-param-multi-max' )
559 ->numParams( ApiBase::LIMIT_SML1, ApiBase::LIMIT_SML2 )
560 ->parse();
561 }
562 if ( $extra ) {
563 $info[] = join( ' ', $extra );
564 }
565 }
566 }
567
568 // Add default
569 $default = isset( $settings[ApiBase::PARAM_DFLT] )
570 ? $settings[ApiBase::PARAM_DFLT]
571 : null;
572 if ( $default === '' ) {
573 $info[] = $context->msg( 'api-help-param-default-empty' )
574 ->parse();
575 } elseif ( $default !== null && $default !== false ) {
576 $info[] = $context->msg( 'api-help-param-default' )
577 ->params( wfEscapeWikiText( $default ) )
578 ->parse();
579 }
580
581 if ( !array_filter( $description ) ) {
582 $description = array( self::wrap(
583 $context->msg( 'api-help-param-no-description' ),
584 'apihelp-empty'
585 ) );
586 }
587
588 // Add "deprecated" flag
589 if ( !empty( $settings[ApiBase::PARAM_DEPRECATED] ) ) {
590 $help['parameters'] .= Html::openElement( 'dd',
591 array( 'class' => 'info' ) );
592 $help['parameters'] .= self::wrap(
593 $context->msg( 'api-help-param-deprecated' ),
594 'apihelp-deprecated', 'strong'
595 );
596 $help['parameters'] .= Html::closeElement( 'dd' );
597 }
598
599 if ( $description ) {
600 $description = join( '', $description );
601 $description = preg_replace( '!\s*</([oud]l)>\s*<\1>\s*!', "\n", $description );
602 $help['parameters'] .= Html::rawElement( 'dd',
603 array( 'class' => 'description' ), $description );
604 }
605
606 foreach ( $info as $i ) {
607 $help['parameters'] .= Html::rawElement( 'dd', array( 'class' => 'info' ), $i );
608 }
609 }
610
611 $help['parameters'] .= Html::closeElement( 'dl' );
612 $help['parameters'] .= Html::closeElement( 'div' );
613 }
614
615 $examples = $module->getExamplesMessages();
616 if ( $examples ) {
617 $help['examples'] .= Html::openElement( 'div',
618 array( 'class' => 'apihelp-block apihelp-examples' ) );
619 $msg = $context->msg( 'api-help-examples' );
620 if ( !$msg->isDisabled() ) {
621 $help['examples'] .= self::wrap(
622 $msg->numParams( count( $examples ) ), 'apihelp-block-head', 'div'
623 );
624 }
625
626 $help['examples'] .= Html::openElement( 'dl' );
627 foreach ( $examples as $qs => $msg ) {
628 $msg = ApiBase::makeMessage( $msg, $context, array(
629 $module->getModulePrefix(),
630 $module->getModuleName(),
631 $module->getModulePath()
632 ) );
633
634 $link = wfAppendQuery( wfScript( 'api' ), $qs );
635 $help['examples'] .= Html::rawElement( 'dt', null, $msg->parse() );
636 $help['examples'] .= Html::rawElement( 'dd', null,
637 Html::element( 'a', array( 'href' => $link ), "api.php?$qs" )
638 );
639 }
640 $help['examples'] .= Html::closeElement( 'dl' );
641 $help['examples'] .= Html::closeElement( 'div' );
642 }
643
644 if ( $options['submodules'] && $module->getModuleManager() ) {
645 $manager = $module->getModuleManager();
646 $submodules = array();
647 foreach ( $groups as $group ) {
648 $names = $manager->getNames( $group );
649 sort( $names );
650 foreach ( $names as $name ) {
651 $submodules[] = $manager->getModule( $name );
652 }
653 }
654 $help['submodules'] .= self::getHelpInternal( $context, $submodules, array(
655 'submodules' => $options['recursivesubmodules'],
656 'headerlevel' => $level + 1,
657 'noheader' => false,
658 ) + $options, $haveModules );
659 }
660
661 $module->modifyHelp( $help, $options );
662
663 Hooks::run( 'APIHelpModifyOutput', array( $module, &$help, $options ) );
664
665 $out .= join( "\n", $help );
666 }
667
668 return $out;
669 }
670
671 public function shouldCheckMaxlag() {
672 return false;
673 }
674
675 public function isReadMode() {
676 return false;
677 }
678
679 public function getCustomPrinter() {
680 $params = $this->extractRequestParams();
681 if ( $params['wrap'] ) {
682 return null;
683 }
684
685 $main = $this->getMain();
686 $errorPrinter = $main->createPrinterByName( $main->getParameter( 'format' ) );
687 return new ApiFormatRaw( $main, $errorPrinter );
688 }
689
690 public function getAllowedParams() {
691 return array(
692 'modules' => array(
693 ApiBase::PARAM_DFLT => 'main',
694 ApiBase::PARAM_ISMULTI => true,
695 ),
696 'submodules' => false,
697 'recursivesubmodules' => false,
698 'wrap' => false,
699 'toc' => false,
700 );
701 }
702
703 protected function getExamplesMessages() {
704 return array(
705 'action=help'
706 => 'apihelp-help-example-main',
707 'action=help&recursivesubmodules=1'
708 => 'apihelp-help-example-recursive',
709 'action=help&modules=help'
710 => 'apihelp-help-example-help',
711 'action=help&modules=query+info|query+categorymembers'
712 => 'apihelp-help-example-query',
713 );
714 }
715
716 public function getHelpUrls() {
717 return array(
718 'https://www.mediawiki.org/wiki/API:Main_page',
719 'https://www.mediawiki.org/wiki/API:FAQ',
720 'https://www.mediawiki.org/wiki/API:Quick_start_guide',
721 );
722 }
723 }