Merge "Remove zh-tw message "editing""
[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 $result->setSubelements( $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[1];
170 } elseif ( $helptitle !== null ) {
171 $href = Title::newFromText( str_replace( '$1', $m[1], $helptitle ) )
172 ->getFullUrl();
173 } else {
174 $href = wfAppendQuery( wfScript( 'api' ), array(
175 'action' => 'help',
176 'modules' => $m[1],
177 ) );
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 break;
476
477 case 'namespace':
478 $namespaces = MWNamespace::getValidNamespaces();
479 $count = count( $namespaces );
480 $info[] = $context->msg( 'api-help-param-list' )
481 ->params( $multi ? 2 : 1 )
482 ->params( $context->getLanguage()->commaList( $namespaces ) )
483 ->parse();
484 $hintPipeSeparated = false;
485 break;
486
487 case 'limit':
488 if ( isset( $settings[ApiBase::PARAM_MAX2] ) ) {
489 $info[] = $context->msg( 'api-help-param-limit2' )
490 ->numParams( $settings[ApiBase::PARAM_MAX] )
491 ->numParams( $settings[ApiBase::PARAM_MAX2] )
492 ->parse();
493 } else {
494 $info[] = $context->msg( 'api-help-param-limit' )
495 ->numParams( $settings[ApiBase::PARAM_MAX] )
496 ->parse();
497 }
498 break;
499
500 case 'integer':
501 // Possible messages:
502 // api-help-param-integer-min,
503 // api-help-param-integer-max,
504 // api-help-param-integer-minmax
505 $suffix = '';
506 $min = $max = 0;
507 if ( isset( $settings[ApiBase::PARAM_MIN] ) ) {
508 $suffix .= 'min';
509 $min = $settings[ApiBase::PARAM_MIN];
510 }
511 if ( isset( $settings[ApiBase::PARAM_MAX] ) ) {
512 $suffix .= 'max';
513 $max = $settings[ApiBase::PARAM_MAX];
514 }
515 if ( $suffix !== '' ) {
516 $info[] =
517 $context->msg( "api-help-param-integer-$suffix" )
518 ->params( $multi ? 2 : 1 )
519 ->numParams( $min, $max )
520 ->parse();
521 }
522 break;
523
524 case 'upload':
525 $info[] = $context->msg( 'api-help-param-upload' )
526 ->parse();
527 break;
528 }
529 }
530
531 if ( $multi ) {
532 $extra = array();
533 if ( $hintPipeSeparated ) {
534 $extra[] = $context->msg( 'api-help-param-multi-separate' )->parse();
535 }
536 if ( $count > ApiBase::LIMIT_SML1 ) {
537 $extra[] = $context->msg( 'api-help-param-multi-max' )
538 ->numParams( ApiBase::LIMIT_SML1, ApiBase::LIMIT_SML2 )
539 ->parse();
540 }
541 if ( $extra ) {
542 $info[] = join( ' ', $extra );
543 }
544 }
545 }
546
547 // Add default
548 $default = isset( $settings[ApiBase::PARAM_DFLT] )
549 ? $settings[ApiBase::PARAM_DFLT]
550 : null;
551 if ( $default === '' ) {
552 $info[] = $context->msg( 'api-help-param-default-empty' )
553 ->parse();
554 } elseif ( $default !== null && $default !== false ) {
555 $info[] = $context->msg( 'api-help-param-default' )
556 ->params( wfEscapeWikiText( $default ) )
557 ->parse();
558 }
559
560 if ( !array_filter( $description ) ) {
561 $description = array( self::wrap(
562 $context->msg( 'api-help-param-no-description' ),
563 'apihelp-empty'
564 ) );
565 }
566
567 // Add "deprecated" flag
568 if ( !empty( $settings[ApiBase::PARAM_DEPRECATED] ) ) {
569 $help['parameters'] .= Html::openElement( 'dd',
570 array( 'class' => 'info' ) );
571 $help['parameters'] .= self::wrap(
572 $context->msg( 'api-help-param-deprecated' ),
573 'apihelp-deprecated', 'strong'
574 );
575 $help['parameters'] .= Html::closeElement( 'dd' );
576 }
577
578 if ( $description ) {
579 $description = join( '', $description );
580 $description = preg_replace( '!\s*</([oud]l)>\s*<\1>\s*!', "\n", $description );
581 $help['parameters'] .= Html::rawElement( 'dd',
582 array( 'class' => 'description' ), $description );
583 }
584
585 foreach ( $info as $i ) {
586 $help['parameters'] .= Html::rawElement( 'dd', array( 'class' => 'info' ), $i );
587 }
588 }
589
590 $help['parameters'] .= Html::closeElement( 'dl' );
591 $help['parameters'] .= Html::closeElement( 'div' );
592 }
593
594 $examples = $module->getExamplesMessages();
595 if ( $examples ) {
596 $help['examples'] .= Html::openElement( 'div',
597 array( 'class' => 'apihelp-block apihelp-examples' ) );
598 $msg = $context->msg( 'api-help-examples' );
599 if ( !$msg->isDisabled() ) {
600 $help['examples'] .= self::wrap(
601 $msg->numParams( count( $examples ) ), 'apihelp-block-head', 'div'
602 );
603 }
604
605 $help['examples'] .= Html::openElement( 'dl' );
606 foreach ( $examples as $qs => $msg ) {
607 $msg = ApiBase::makeMessage( $msg, $context, array(
608 $module->getModulePrefix(),
609 $module->getModuleName(),
610 $module->getModulePath()
611 ) );
612
613 $link = wfAppendQuery( wfScript( 'api' ), $qs );
614 $help['examples'] .= Html::rawElement( 'dt', null, $msg->parse() );
615 $help['examples'] .= Html::rawElement( 'dd', null,
616 Html::element( 'a', array( 'href' => $link ), "api.php?$qs" )
617 );
618 }
619 $help['examples'] .= Html::closeElement( 'dl' );
620 $help['examples'] .= Html::closeElement( 'div' );
621 }
622
623 if ( $options['submodules'] && $module->getModuleManager() ) {
624 $manager = $module->getModuleManager();
625 $submodules = array();
626 foreach ( $groups as $group ) {
627 $names = $manager->getNames( $group );
628 sort( $names );
629 foreach ( $names as $name ) {
630 $submodules[] = $manager->getModule( $name );
631 }
632 }
633 $help['submodules'] .= self::getHelpInternal( $context, $submodules, array(
634 'submodules' => $options['recursivesubmodules'],
635 'headerlevel' => $level + 1,
636 'noheader' => false,
637 ) + $options, $haveModules );
638 }
639
640 $module->modifyHelp( $help, $options );
641
642 Hooks::run( 'APIHelpModifyOutput', array( $module, &$help, $options ) );
643
644 $out .= join( "\n", $help );
645 }
646
647 return $out;
648 }
649
650 public function shouldCheckMaxlag() {
651 return false;
652 }
653
654 public function isReadMode() {
655 return false;
656 }
657
658 public function getCustomPrinter() {
659 $params = $this->extractRequestParams();
660 if ( $params['wrap'] ) {
661 return null;
662 }
663
664 $main = $this->getMain();
665 $errorPrinter = $main->createPrinterByName( $main->getParameter( 'format' ) );
666 return new ApiFormatRaw( $main, $errorPrinter );
667 }
668
669 public function getAllowedParams() {
670 return array(
671 'modules' => array(
672 ApiBase::PARAM_DFLT => 'main',
673 ApiBase::PARAM_ISMULTI => true,
674 ),
675 'submodules' => false,
676 'recursivesubmodules' => false,
677 'wrap' => false,
678 'toc' => false,
679 );
680 }
681
682 protected function getExamplesMessages() {
683 return array(
684 'action=help'
685 => 'apihelp-help-example-main',
686 'action=help&recursivesubmodules=1'
687 => 'apihelp-help-example-recursive',
688 'action=help&modules=help'
689 => 'apihelp-help-example-help',
690 'action=help&modules=query+info|query+categorymembers'
691 => 'apihelp-help-example-query',
692 );
693 }
694
695 public function getHelpUrls() {
696 return array(
697 'https://www.mediawiki.org/wiki/API:Main_page',
698 'https://www.mediawiki.org/wiki/API:FAQ',
699 'https://www.mediawiki.org/wiki/API:Quick_start_guide',
700 );
701 }
702 }