MediaWiki master
ApiHelp.php
Go to the documentation of this file.
1<?php
8
9namespace MediaWiki\Api;
10
28use Wikimedia\ParamValidator\ParamValidator;
29use Wikimedia\Parsoid\Core\SectionMetadata;
30use Wikimedia\Parsoid\Core\TOCData;
31use Wikimedia\RemexHtml\Serializer\SerializerNode;
32
39class ApiHelp extends ApiBase {
40
41 public function __construct(
42 ApiMain $main,
43 string $action,
44 private readonly SkinFactory $skinFactory,
45 ) {
46 parent::__construct( $main, $action );
47 }
48
49 public function execute() {
50 $params = $this->extractRequestParams();
51 $modules = [];
52
53 foreach ( $params['modules'] as $path ) {
54 $modules[] = $this->getModuleFromPath( $path );
55 }
56
57 // Get the help
58 $context = new DerivativeContext( $this->getMain()->getContext() );
59 $context->setSkin( $this->skinFactory->makeSkin( 'apioutput' ) );
60 $context->setLanguage( $this->getMain()->getLanguage() );
61 $context->setTitle( SpecialPage::getTitleFor( 'ApiHelp' ) );
62 $out = new OutputPage( $context );
63 $out->setRobotPolicy( 'noindex,nofollow' );
64 $out->setCopyrightUrl( 'https://www.mediawiki.org/wiki/Special:MyLanguage/Copyright' );
65 $out->disallowUserJs();
66 $out->reduceAllowedModules( RL\Module::TYPE_SCRIPTS, RL\Module::ORIGIN_NONE );
67 $context->setOutput( $out );
68
69 // If no parameters were passed (not even action=help), display the TOC.
70 // It's a special case for the landing page because it's much nicer with a TOC.
71 if ( !$context->getRequest()->getValues() ) {
72 $params['toc'] = true;
73 }
74
75 self::getHelp( $context, $modules, $params );
76
77 // Grab the output from the skin
78 ob_start();
79 $context->getOutput()->output();
80 $html = ob_get_clean();
81
82 $result = $this->getResult();
83 if ( $params['wrap'] ) {
84 $data = [
85 'mime' => 'text/html',
86 'filename' => 'api-help.html',
87 'help' => $html,
88 ];
89 ApiResult::setSubelementsList( $data, 'help' );
90 $result->addValue( null, $this->getModuleName(), $data );
91 } else {
92 // Show any errors at the top of the HTML
93 $transform = [
94 'Types' => [ 'AssocAsObject' => true ],
95 'Strip' => 'all',
96 ];
97 $errors = array_filter( [
98 'errors' => $this->getResult()->getResultData( [ 'errors' ], $transform ),
99 'warnings' => $this->getResult()->getResultData( [ 'warnings' ], $transform ),
100 ] );
101 if ( $errors ) {
102 $json = FormatJson::encode( $errors, true, FormatJson::UTF8_OK );
103 // Escape any "--", some parsers might interpret that as end-of-comment.
104 // The above already escaped any "<" and ">".
105 $json = str_replace( '--', '-\u002D', $json );
106 $html = "<!-- API warnings and errors:\n$json\n-->\n$html";
107 }
108
109 $result->reset();
110 $result->addValue( null, 'text', $html, ApiResult::NO_SIZE_CHECK );
111 $result->addValue( null, 'mime', 'text/html', ApiResult::NO_SIZE_CHECK );
112 $result->addValue( null, 'filename', 'api-help.html', ApiResult::NO_SIZE_CHECK );
113 }
114 }
115
135 public static function getHelp( IContextSource $context, $modules, array $options ) {
136 if ( !is_array( $modules ) ) {
137 $modules = [ $modules ];
138 }
139
140 $out = $context->getOutput();
141 $out->addModuleStyles( [
142 'mediawiki.hlist',
143 'mediawiki.apipretty',
144 ] );
145 $out->setPageTitleMsg( $context->msg( 'api-help-title' ) );
146
147 $services = MediaWikiServices::getInstance();
148 $cache = $services->getMainWANObjectCache();
149 $cacheKey = null;
150 if ( count( $modules ) == 1 && $modules[0] instanceof ApiMain &&
151 $options['recursivesubmodules'] &&
152 $context->getLanguage()->equals( $services->getContentLanguage() )
153 ) {
154 $cacheHelpTimeout = $context->getConfig()->get( MainConfigNames::APICacheHelpTimeout );
155 if ( $cacheHelpTimeout > 0 ) {
156 // Get help text from cache if present
157 $cacheKey = $cache->makeKey( 'apihelp', $modules[0]->getModulePath(),
158 (int)!empty( $options['toc'] ),
159 str_replace( ' ', '_', SpecialVersion::getVersion( 'nodb' ) ) );
160 $cached = $cache->get( $cacheKey );
161 if ( $cached ) {
162 $out->addHTML( $cached );
163 return;
164 }
165 }
166 }
167 if ( $out->getHTML() !== '' ) {
168 // Don't save to cache, there's someone else's content in the page
169 // already
170 $cacheKey = null;
171 }
172
173 $options['recursivesubmodules'] = !empty( $options['recursivesubmodules'] );
174 $options['submodules'] = $options['recursivesubmodules'] || !empty( $options['submodules'] );
175 $haveModules = [];
176 $html = self::getHelpInternal( $context, $modules, $options, $haveModules );
177
178 if ( !empty( $options['toc'] ) && $haveModules ) {
179 $out->addTOCPlaceholder( new TOCData( ...array_values( $haveModules ) ) );
180 }
181
182 // Prepend lead
183 if ( empty( $options['nolead'] ) ) {
184 $msg = $context->msg( 'api-help-lead' );
185 if ( !$msg->isDisabled() ) {
186 $out->addHTML( $msg->parseAsBlock() );
187 }
188 }
189
190 $out->addHTML( $html );
191
192 $helptitle = $options['helptitle'] ?? null;
193 $html = self::fixHelpLinks( $out->getHTML(), $helptitle, $haveModules );
194 $out->clearHTML();
195 $out->addHTML( $html );
196
197 if ( $cacheKey !== null ) {
198 // @phan-suppress-next-line PhanPossiblyUndeclaredVariable $cacheHelpTimeout declared when $cacheKey is set
199 $cache->set( $cacheKey, $out->getHTML(), $cacheHelpTimeout );
200 }
201 }
202
211 public static function fixHelpLinks( $html, $helptitle = null, $localModules = [] ) {
213 $html,
214 static function ( SerializerNode $node ): bool {
215 return $node->name === 'a'
216 && isset( $node->attrs['href'] )
217 && !str_contains( $node->attrs['class'] ?? '', 'apihelp-linktrail' );
218 },
219 static function ( SerializerNode $node ) use ( $helptitle, $localModules ): SerializerNode {
220 $href = $node->attrs['href'];
221 // FIXME This can't be right to do this in a loop
222 do {
223 $old = $href;
224 $href = rawurldecode( $href );
225 } while ( $old !== $href );
226 if ( preg_match( '!Special:ApiHelp/([^&/|#]+)((?:#.*)?)!', $href, $m ) ) {
227 if ( isset( $localModules[$m[1]] ) ) {
228 $href = $m[2] === '' ? '#' . $m[1] : $m[2];
229 } elseif ( $helptitle !== null ) {
230 $href = Title::newFromText( str_replace( '$1', $m[1], $helptitle ) . $m[2] )
231 ->getFullURL();
232 } else {
233 $href = wfAppendQuery( wfScript( 'api' ), [
234 'action' => 'help',
235 'modules' => $m[1],
236 ] ) . $m[2];
237 }
238 $node->attrs['href'] = $href;
239 unset( $node->attrs['title'] );
240 }
241
242 return $node;
243 }
244 );
245 }
246
255 private static function wrap( Message $msg, $class, $tag = 'span' ) {
256 return Html::rawElement( $tag, [ 'class' => $class ],
257 $msg->parse()
258 );
259 }
260
270 private static function getHelpInternal( IContextSource $context, array $modules,
271 array $options, &$haveModules
272 ) {
273 $out = '';
274
275 $level = empty( $options['headerlevel'] ) ? 2 : $options['headerlevel'];
276 if ( empty( $options['tocnumber'] ) ) {
277 $tocnumber = [ 2 => 0 ];
278 } else {
279 $tocnumber = &$options['tocnumber'];
280 }
281
282 foreach ( $modules as $module ) {
283 $paramValidator = $module->getMain()->getParamValidator();
284 $tocnumber[$level]++;
285 $path = $module->getModulePath();
286 $module->setContext( $context );
287 $help = [
288 'header' => '',
289 'flags' => '',
290 'description' => '',
291 'help-urls' => '',
292 'parameters' => '',
293 'examples' => '',
294 'submodules' => '',
295 ];
296
297 if ( empty( $options['noheader'] ) || !empty( $options['toc'] ) ) {
298 $anchor = $path;
299 $i = 1;
300 while ( isset( $haveModules[$anchor] ) ) {
301 $anchor = $path . '|' . ++$i;
302 }
303
304 if ( $module->isMain() ) {
305 $headerContent = $context->msg( 'api-help-main-header' )->parse();
306 $headerAttr = [
307 'class' => 'apihelp-header',
308 ];
309 } else {
310 $name = $module->getModuleName();
311 $headerContent = htmlspecialchars(
312 $module->getParent()->getModuleManager()->getModuleGroup( $name ) . "=$name"
313 );
314 if ( $module->getModulePrefix() !== '' ) {
315 $headerContent .= ' ' .
316 $context->msg( 'parentheses', $module->getModulePrefix() )->parse();
317 }
318 // Module names are always in English and not localized,
319 // so English language and direction must be set explicitly,
320 // otherwise parentheses will get broken in RTL wikis
321 $headerAttr = [
322 'class' => [ 'apihelp-header', 'apihelp-module-name' ],
323 'dir' => 'ltr',
324 'lang' => 'en',
325 ];
326 }
327
328 $headerAttr['id'] = $anchor;
329
330 $haveModules[$anchor] = new SectionMetadata(
331 tocLevel: count( $tocnumber ),
332 hLevel: $level,
333 line: $headerContent,
334 number: implode( '.', $tocnumber ),
335 index: (string)( 1 + count( $haveModules ) ),
336 anchor: $anchor,
337 linkAnchor: Sanitizer::escapeIdForLink( $anchor ),
338 );
339 if ( empty( $options['noheader'] ) ) {
340 $help['header'] .= Html::rawElement(
341 'h' . min( 6, $level ),
342 $headerAttr,
343 $headerContent
344 );
345 }
346 } else {
347 $haveModules[$path] = true;
348 }
349
350 $links = [];
351 $any = false;
352 for ( $m = $module; $m !== null; $m = $m->getParent() ) {
353 $name = $m->getModuleName();
354 if ( $name === 'main_int' ) {
355 $name = 'main';
356 }
357
358 if ( count( $modules ) === 1 && $m === $modules[0] &&
359 !( !empty( $options['submodules'] ) && $m->getModuleManager() )
360 ) {
361 $link = Html::element( 'b', [ 'dir' => 'ltr', 'lang' => 'en' ], $name );
362 } else {
363 $link = SpecialPage::getTitleFor( 'ApiHelp', $m->getModulePath() )->getLocalURL();
364 $link = Html::element( 'a',
365 [ 'href' => $link, 'class' => 'apihelp-linktrail', 'dir' => 'ltr', 'lang' => 'en' ],
366 $name
367 );
368 $any = true;
369 }
370 array_unshift( $links, $link );
371 }
372 if ( $any ) {
373 $help['header'] .= self::wrap(
374 $context->msg( 'parentheses' )
375 ->rawParams( $context->getLanguage()->pipeList( $links ) ),
376 'apihelp-linktrail', 'div'
377 );
378 }
379
380 $flags = $module->getHelpFlags();
381 $help['flags'] .= Html::openElement( 'div',
382 [ 'class' => [ 'apihelp-block', 'apihelp-flags' ] ] );
383 $msg = $context->msg( 'api-help-flags' );
384 if ( !$msg->isDisabled() ) {
385 $help['flags'] .= self::wrap(
386 $msg->numParams( count( $flags ) ), 'apihelp-block-head', 'div'
387 );
388 }
389 $help['flags'] .= Html::openElement( 'ul' );
390 foreach ( $flags as $flag ) {
391 $help['flags'] .= Html::rawElement( 'li', [],
392 // The follow classes are used here:
393 // * apihelp-flag-generator
394 // * apihelp-flag-internal
395 // * apihelp-flag-mustbeposted
396 // * apihelp-flag-readrights
397 // * apihelp-flag-writerights
398 self::wrap( $context->msg( "api-help-flag-$flag" ), "apihelp-flag-$flag" )
399 );
400 }
401 $sourceInfo = $module->getModuleSourceInfo();
402 if ( $sourceInfo ) {
403 if ( isset( $sourceInfo['namemsg'] ) ) {
404 $extname = $context->msg( $sourceInfo['namemsg'] )->text();
405 } else {
406 // Probably English, so wrap it.
407 $extname = Html::element( 'span', [ 'dir' => 'ltr', 'lang' => 'en' ], $sourceInfo['name'] );
408 }
409 $help['flags'] .= Html::rawElement( 'li', [],
410 self::wrap(
411 $context->msg( 'api-help-source', $extname, $sourceInfo['name'] ),
412 'apihelp-source'
413 )
414 );
415
416 $linkText = SpecialPage::getTitleFor( 'Version', 'License/' . $sourceInfo['name'] )
417 ->getPrefixedText();
418 if ( isset( $sourceInfo['license-name'] ) ) {
419 $msg = $context->msg( 'api-help-license', $linkText,
420 Html::element( 'span', [ 'dir' => 'ltr', 'lang' => 'en' ], $sourceInfo['license-name'] )
421 );
422 } elseif ( ExtensionInfo::getLicenseFileNames( dirname( $sourceInfo['path'] ) ) ) {
423 $msg = $context->msg( 'api-help-license-noname', $linkText );
424 } else {
425 $msg = $context->msg( 'api-help-license-unknown' );
426 }
427 $help['flags'] .= Html::rawElement( 'li', [],
428 self::wrap( $msg, 'apihelp-license' )
429 );
430 } else {
431 $help['flags'] .= Html::rawElement( 'li', [],
432 self::wrap( $context->msg( 'api-help-source-unknown' ), 'apihelp-source' )
433 );
434 $help['flags'] .= Html::rawElement( 'li', [],
435 self::wrap( $context->msg( 'api-help-license-unknown' ), 'apihelp-license' )
436 );
437 }
438 $help['flags'] .= Html::closeElement( 'ul' );
439 $help['flags'] .= Html::closeElement( 'div' );
440
441 foreach ( $module->getFinalDescription() as $msg ) {
442 $msg->setContext( $context );
443 $help['description'] .= $msg->parseAsBlock();
444 }
445
446 $urls = $module->getHelpUrls();
447 if ( $urls ) {
448 if ( !is_array( $urls ) ) {
449 $urls = [ $urls ];
450 }
451 $help['help-urls'] .= Html::openElement( 'div',
452 [ 'class' => [ 'apihelp-block', 'apihelp-help-urls' ] ]
453 );
454 $msg = $context->msg( 'api-help-help-urls' );
455 if ( !$msg->isDisabled() ) {
456 $help['help-urls'] .= self::wrap(
457 $msg->numParams( count( $urls ) ), 'apihelp-block-head', 'div'
458 );
459 }
460 $help['help-urls'] .= Html::openElement( 'ul' );
461 foreach ( $urls as $url ) {
462 $help['help-urls'] .= Html::rawElement( 'li', [],
463 Html::element( 'a', [ 'href' => $url, 'dir' => 'ltr' ], $url )
464 );
465 }
466 $help['help-urls'] .= Html::closeElement( 'ul' );
467 $help['help-urls'] .= Html::closeElement( 'div' );
468 }
469
470 $params = $module->getFinalParams( ApiBase::GET_VALUES_FOR_HELP );
471 $dynamicParams = $module->dynamicParameterDocumentation();
472 $groups = [];
473 if ( $params || $dynamicParams !== null ) {
474 $help['parameters'] .= Html::openElement( 'div',
475 [ 'class' => [ 'apihelp-block', 'apihelp-parameters' ] ]
476 );
477 $msg = $context->msg( 'api-help-parameters' );
478 if ( !$msg->isDisabled() ) {
479 $help['parameters'] .= self::wrap(
480 $msg->numParams( count( $params ) ), 'apihelp-block-head', 'div'
481 );
482 if ( !$module->isMain() ) {
483 // Add a note explaining that other parameters may exist.
484 $help['parameters'] .= self::wrap(
485 $context->msg( 'api-help-parameters-note' ), 'apihelp-block-header', 'div'
486 );
487 }
488 }
489 $help['parameters'] .= Html::openElement( 'dl' );
490
491 $descriptions = $module->getFinalParamDescription();
492
493 foreach ( $params as $name => $settings ) {
494 $settings = $paramValidator->normalizeSettings( $settings );
495
496 if ( $settings[ParamValidator::PARAM_TYPE] === 'submodule' ) {
497 $groups[] = $name;
498 }
499
500 $encodedParamName = $module->encodeParamName( $name );
501 $paramNameAttribs = [ 'dir' => 'ltr', 'lang' => 'en' ];
502 if ( isset( $anchor ) ) {
503 $paramNameAttribs['id'] = "$anchor:$encodedParamName";
504 }
505 $help['parameters'] .= Html::rawElement( 'dt', [],
506 Html::element( 'span', $paramNameAttribs, $encodedParamName )
507 );
508
509 // Add description
510 $description = [];
511 if ( isset( $descriptions[$name] ) ) {
512 foreach ( $descriptions[$name] as $msg ) {
513 $msg->setContext( $context );
514 $description[] = $msg->parseAsBlock();
515 }
516 }
517 if ( !array_filter( $description ) ) {
518 $description = [ self::wrap(
519 $context->msg( 'api-help-param-no-description' ),
520 'apihelp-empty'
521 ) ];
522 }
523
524 // Add "deprecated" flag
525 if ( !empty( $settings[ParamValidator::PARAM_DEPRECATED] ) ) {
526 $help['parameters'] .= Html::openElement( 'dd',
527 [ 'class' => 'info' ] );
528 $help['parameters'] .= self::wrap(
529 $context->msg( 'api-help-param-deprecated' ),
530 'apihelp-deprecated', 'strong'
531 );
532 $help['parameters'] .= Html::closeElement( 'dd' );
533 }
534
535 if ( $description ) {
536 $description = implode( '', $description );
537 $description = preg_replace( '!\s*</([oud]l)>\s*<\1>\s*!', "\n", $description );
538 $help['parameters'] .= Html::rawElement( 'dd',
539 [ 'class' => 'description' ], $description );
540 }
541
542 // Add usage info
543 $info = [];
544 $paramHelp = $paramValidator->getHelpInfo( $module, $name, $settings, [] );
545
546 unset( $paramHelp[ParamValidator::PARAM_DEPRECATED] );
547
548 if ( isset( $paramHelp[ParamValidator::PARAM_REQUIRED] ) ) {
549 $paramHelp[ParamValidator::PARAM_REQUIRED]->setContext( $context );
550 $info[] = $paramHelp[ParamValidator::PARAM_REQUIRED];
551 unset( $paramHelp[ParamValidator::PARAM_REQUIRED] );
552 }
553
554 // Custom info?
555 if ( !empty( $settings[ApiBase::PARAM_HELP_MSG_INFO] ) ) {
556 foreach ( $settings[ApiBase::PARAM_HELP_MSG_INFO] as $i ) {
557 $tag = array_shift( $i );
558 $info[] = $context->msg( "apihelp-{$path}-paraminfo-{$tag}" )
559 ->numParams( count( $i ) )
560 ->params( $context->getLanguage()->commaList( $i ) )
561 ->params( $module->getModulePrefix() )
562 ->parse();
563 }
564 }
565
566 // Templated?
567 if ( !empty( $settings[ApiBase::PARAM_TEMPLATE_VARS] ) ) {
568 $vars = [];
569 $msg = 'api-help-param-templated-var-first';
570 foreach ( $settings[ApiBase::PARAM_TEMPLATE_VARS] as $k => $v ) {
571 $vars[] = $context->msg( $msg, $k, $module->encodeParamName( $v ) );
572 $msg = 'api-help-param-templated-var';
573 }
574 $info[] = $context->msg( 'api-help-param-templated' )
575 ->numParams( count( $vars ) )
576 ->params( Message::listParam( $vars ) )
577 ->parse();
578 }
579
580 // Type documentation
581 foreach ( $paramHelp as $m ) {
582 $m->setContext( $context );
583 $info[] = $m->parse();
584 }
585
586 foreach ( $info as $i ) {
587 $help['parameters'] .= Html::rawElement( 'dd', [ 'class' => 'info' ], $i );
588 }
589 }
590
591 if ( $dynamicParams !== null ) {
592 $dynamicParams = $context->msg(
593 Message::newFromSpecifier( $dynamicParams ),
594 $module->getModulePrefix(),
595 $module->getModuleName(),
596 $module->getModulePath()
597 );
598 $help['parameters'] .= Html::element( 'dt', [], '*' );
599 $help['parameters'] .= Html::rawElement( 'dd',
600 [ 'class' => 'description' ], $dynamicParams->parse() );
601 }
602
603 $help['parameters'] .= Html::closeElement( 'dl' );
604 $help['parameters'] .= Html::closeElement( 'div' );
605 }
606
607 $examples = $module->getExamplesMessages();
608 if ( $examples ) {
609 $help['examples'] .= Html::openElement( 'div',
610 [ 'class' => [ 'apihelp-block', 'apihelp-examples' ] ] );
611 $msg = $context->msg( 'api-help-examples' );
612 if ( !$msg->isDisabled() ) {
613 $help['examples'] .= self::wrap(
614 $msg->numParams( count( $examples ) ), 'apihelp-block-head', 'div'
615 );
616 }
617
618 $help['examples'] .= Html::openElement( 'dl' );
619 foreach ( $examples as $qs => $msg ) {
620 $msg = $context->msg(
622 $module->getModulePrefix(),
623 $module->getModuleName(),
624 $module->getModulePath()
625 );
626
627 $link = wfAppendQuery( wfScript( 'api' ), $qs );
628 $sandbox = SpecialPage::getTitleFor( 'ApiSandbox' )->getLocalURL() . '#' . $qs;
629 $help['examples'] .= Html::rawElement( 'dt', [], $msg->parse() );
630 $help['examples'] .= Html::rawElement( 'dd', [],
631 Html::element( 'a', [
632 'href' => $link,
633 'dir' => 'ltr',
634 'rel' => 'nofollow',
635 ], "api.php?$qs" ) . ' ' .
636 Html::rawElement( 'a', [ 'href' => $sandbox ],
637 $context->msg( 'api-help-open-in-apisandbox' )->parse() )
638 );
639 }
640 $help['examples'] .= Html::closeElement( 'dl' );
641 $help['examples'] .= Html::closeElement( 'div' );
642 }
643
644 $subtocnumber = $tocnumber;
645 $subtocnumber[$level + 1] = 0;
646 $suboptions = [
647 'submodules' => $options['recursivesubmodules'],
648 'headerlevel' => $level + 1,
649 'tocnumber' => &$subtocnumber,
650 'noheader' => false,
651 ] + $options;
652
653 if ( $options['submodules'] && $module->getModuleManager() ) {
654 $manager = $module->getModuleManager();
655 $submodules = [];
656 foreach ( $groups as $group ) {
657 $names = $manager->getNames( $group );
658 sort( $names );
659 foreach ( $names as $name ) {
660 $submodules[] = $manager->getModule( $name );
661 }
662 }
663 $help['submodules'] .= self::getHelpInternal(
664 $context,
665 $submodules,
666 $suboptions,
667 $haveModules
668 );
669 }
670
671 if (
672 $module instanceof ApiMain ||
673 MWDebug::detectDeprecatedOverride( $module, ApiBase::class, 'modifyHelp', '1.47' )
674 ) {
675 $module->modifyHelp( $help, $suboptions, $haveModules );
676 }
677
678 if ( $module->getHookContainer()->isRegistered( 'APIHelpModifyOutput' ) ) {
679 // Hook is also deprecated since 1.47
680 if ( !empty( $suboptions['toc'] ) ) {
681 $haveModules = array_map(
682 static fn ( $s )=>$s->toLegacy(), $haveModules
683 );
684 }
685 $module->getHookRunner()->onAPIHelpModifyOutput(
686 $module, $help, $suboptions, $haveModules
687 );
688 if ( !empty( $suboptions['toc'] ) ) {
689 $haveModules = array_map(
690 static fn ( $s )=>SectionMetadata::fromLegacy( $s ), $haveModules
691 );
692 }
693 }
694
695 $out .= implode( "\n", $help );
696 }
697
698 return $out;
699 }
700
702 public function shouldCheckMaxlag() {
703 return false;
704 }
705
707 public function isReadMode() {
708 return false;
709 }
710
712 public function getCustomPrinter() {
713 $params = $this->extractRequestParams();
714 if ( $params['wrap'] ) {
715 return null;
716 }
717
718 $main = $this->getMain();
719 $errorPrinter = $main->createPrinterByName( $main->getParameter( 'format' ) );
720 return new ApiFormatRaw( $main, $errorPrinter );
721 }
722
724 public function getAllowedParams() {
725 return [
726 'modules' => [
727 ParamValidator::PARAM_DEFAULT => 'main',
728 ParamValidator::PARAM_ISMULTI => true,
729 ],
730 'submodules' => false,
731 'recursivesubmodules' => false,
732 'wrap' => false,
733 'toc' => false,
734 ];
735 }
736
738 protected function getExamplesMessages() {
739 return [
740 'action=help'
741 => 'apihelp-help-example-main',
742 'action=help&modules=query&submodules=1'
743 => 'apihelp-help-example-submodules',
744 'action=help&recursivesubmodules=1&toc'
745 => 'apihelp-help-example-recursive',
746 'action=help&modules=help'
747 => 'apihelp-help-example-help',
748 'action=help&modules=query+info|query+categorymembers'
749 => 'apihelp-help-example-query',
750 ];
751 }
752
754 public function getHelpUrls() {
755 return [
756 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Main_page',
757 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:FAQ',
758 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Quick_start_guide',
759 ];
760 }
761}
762
764class_alias( ApiHelp::class, 'ApiHelp' );
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
wfScript( $script='index')
Get the URL path to a MediaWiki entry point.
This abstract class implements many basic API functions, and is the base of all API classes.
Definition ApiBase.php:59
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:556
const PARAM_HELP_MSG_INFO
(array) Specify additional information tags for the parameter.
Definition ApiBase.php:183
getMain()
Get the main module.
Definition ApiBase.php:574
getModulePath()
Get the path to this module.
Definition ApiBase.php:635
getResult()
Get the result object.
Definition ApiBase.php:695
const PARAM_TEMPLATE_VARS
(array) Indicate that this is a templated parameter, and specify replacements.
Definition ApiBase.php:223
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:830
getModuleFromPath( $path)
Get a module from its module path.
Definition ApiBase.php:655
const GET_VALUES_FOR_HELP
getAllowedParams() flag: When this is set, the result could take longer to generate,...
Definition ApiBase.php:243
Formatter that spits out anything you like with any desired MIME type.
Class to output help for an API module.
Definition ApiHelp.php:39
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition ApiHelp.php:724
shouldCheckMaxlag()
Indicates if this module needs maxlag to be checked.to override bool
Definition ApiHelp.php:702
__construct(ApiMain $main, string $action, private readonly SkinFactory $skinFactory,)
Definition ApiHelp.php:41
static getHelp(IContextSource $context, $modules, array $options)
Generate help for the specified modules.
Definition ApiHelp.php:135
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition ApiHelp.php:49
isReadMode()
Indicates whether this module requires read rights.to override bool
Definition ApiHelp.php:707
getHelpUrls()
Return links to more detailed help pages about the module.1.25, returning boolean false is deprecated...
Definition ApiHelp.php:754
static fixHelpLinks( $html, $helptitle=null, $localModules=[])
Replace Special:ApiHelp links with links to api.php.
Definition ApiHelp.php:211
getExamplesMessages()
Returns usage examples for this module.Return value has query strings as keys, with values being eith...
Definition ApiHelp.php:738
getCustomPrinter()
If the module may only be used with a certain format module, it should override this method to return...
Definition ApiHelp.php:712
This is the main API class, used for both external and internal processing.
Definition ApiMain.php:66
const NO_SIZE_CHECK
For addValue() and similar functions, do not check size while adding a value Don't use this unless yo...
Definition ApiResult.php:57
static setSubelementsList(array &$arr, $names)
Causes the elements with the specified names to be output as subelements rather than attributes.
An IContextSource implementation which will inherit context from another source but allow individual ...
Debug toolbar.
Definition MWDebug.php:35
Static utilities for manipulating HTML strings.
static modifyElements(string $htmlFragment, callable $shouldModifyCallback, callable $modifyCallback, bool $html5format=true)
Modify elements of an HTML fragment via a user-provided callback.
This class is a collection of static functions that serve two purposes:
Definition Html.php:44
JSON formatter wrapper class.
A class containing constants representing the names of configuration variables.
const APICacheHelpTimeout
Name constant for the APICacheHelpTimeout setting, for use with Config\get().
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:144
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition Message.php:492
parse()
Fully parse the text from wikitext to HTML.
Definition Message.php:1125
static listParam(array $list, $type=ListType::AND)
Definition Message.php:1355
This is one of the Core classes and should be read at least once by any new developers.
HTML sanitizer for MediaWiki.
Definition Sanitizer.php:34
Factory class to create Skin objects.
Parent class for all special pages.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Version information about MediaWiki (core, extensions, libs), PHP, and the database.
Represents a title within MediaWiki.
Definition Title.php:69
Interface for objects which can provide a MediaWiki context on request.
element(SerializerNode $parent, SerializerNode $node, $contents)
array $params
The job parameters.