261 array $options, &$haveModules
265 $level = empty( $options[
'headerlevel'] ) ? 2 : $options[
'headerlevel'];
266 if ( empty( $options[
'tocnumber'] ) ) {
267 $tocnumber = [ 2 => 0 ];
269 $tocnumber = &$options[
'tocnumber'];
273 $paramValidator = $module->getMain()->getParamValidator();
274 $tocnumber[$level]++;
275 $path = $module->getModulePath();
287 if ( empty( $options[
'noheader'] ) || !empty( $options[
'toc'] ) ) {
290 while ( isset( $haveModules[$anchor] ) ) {
291 $anchor =
$path .
'|' . ++$i;
294 if ( $module->isMain() ) {
295 $headerContent =
$context->
msg(
'api-help-main-header' )->parse();
297 'class' =>
'apihelp-header',
300 $name = $module->getModuleName();
301 $headerContent = htmlspecialchars(
302 $module->getParent()->getModuleManager()->getModuleGroup( $name ) .
"=$name"
304 if ( $module->getModulePrefix() !==
'' ) {
305 $headerContent .=
' ' .
306 $context->
msg(
'parentheses', $module->getModulePrefix() )->parse();
312 'class' =>
'apihelp-header apihelp-module-name',
318 $headerAttr[
'id'] = $anchor;
320 $haveModules[$anchor] = [
321 'toclevel' => count( $tocnumber ),
324 'line' => $headerContent,
325 'number' => implode(
'.', $tocnumber ),
328 if ( empty( $options[
'noheader'] ) ) {
329 $help[
'header'] .= Html::rawElement(
330 'h' . min( 6, $level ),
336 $haveModules[
$path] =
true;
341 for ( $m = $module; $m !==
null; $m = $m->getParent() ) {
342 $name = $m->getModuleName();
343 if ( $name ===
'main_int' ) {
348 !( !empty( $options[
'submodules'] ) && $m->getModuleManager() )
350 $link = Html::element(
'b', [
'dir' =>
'ltr',
'lang' =>
'en' ], $name );
353 $link = Html::element(
'a',
354 [
'href' => $link,
'class' =>
'apihelp-linktrail',
'dir' =>
'ltr',
'lang' =>
'en' ],
359 array_unshift( $links, $link );
365 'apihelp-linktrail',
'div'
369 $flags = $module->getHelpFlags();
370 $help[
'flags'] .= Html::openElement(
'div',
371 [
'class' =>
'apihelp-block apihelp-flags' ] );
373 if ( !$msg->isDisabled() ) {
375 $msg->numParams( count( $flags ) ),
'apihelp-block-head',
'div'
378 $help[
'flags'] .= Html::openElement(
'ul' );
379 foreach ( $flags as $flag ) {
380 $help[
'flags'] .= Html::rawElement(
'li',
null,
381 self::wrap(
$context->
msg(
"api-help-flag-$flag" ),
"apihelp-flag-$flag" )
384 $sourceInfo = $module->getModuleSourceInfo();
386 if ( isset( $sourceInfo[
'namemsg'] ) ) {
387 $extname =
$context->
msg( $sourceInfo[
'namemsg'] )->text();
390 $extname = Html::element(
'span', [
'dir' =>
'ltr',
'lang' =>
'en' ], $sourceInfo[
'name'] );
392 $help[
'flags'] .= Html::rawElement(
'li',
null,
394 $context->
msg(
'api-help-source', $extname, $sourceInfo[
'name'] ),
400 if ( isset( $sourceInfo[
'license-name'] ) ) {
402 Html::element(
'span', [
'dir' =>
'ltr',
'lang' =>
'en' ], $sourceInfo[
'license-name'] )
404 } elseif ( ExtensionInfo::getLicenseFileNames( dirname( $sourceInfo[
'path'] ) ) ) {
405 $msg =
$context->
msg(
'api-help-license-noname', $link );
407 $msg =
$context->
msg(
'api-help-license-unknown' );
409 $help[
'flags'] .= Html::rawElement(
'li',
null,
410 self::wrap( $msg,
'apihelp-license' )
413 $help[
'flags'] .= Html::rawElement(
'li',
null,
414 self::wrap(
$context->
msg(
'api-help-source-unknown' ),
'apihelp-source' )
416 $help[
'flags'] .= Html::rawElement(
'li',
null,
417 self::wrap(
$context->
msg(
'api-help-license-unknown' ),
'apihelp-license' )
420 $help[
'flags'] .= Html::closeElement(
'ul' );
421 $help[
'flags'] .= Html::closeElement(
'div' );
423 foreach ( $module->getFinalDescription() as $msg ) {
425 $help[
'description'] .= $msg->parseAsBlock();
428 $urls = $module->getHelpUrls();
430 if ( !is_array( $urls ) ) {
433 $help[
'help-urls'] .= Html::openElement(
'div',
434 [
'class' =>
'apihelp-block apihelp-help-urls' ]
437 if ( !$msg->isDisabled() ) {
439 $msg->numParams( count( $urls ) ),
'apihelp-block-head',
'div'
442 $help[
'help-urls'] .= Html::openElement(
'ul' );
443 foreach ( $urls as $url ) {
444 $help[
'help-urls'] .= Html::rawElement(
'li',
null,
445 Html::element(
'a', [
'href' => $url,
'dir' =>
'ltr' ], $url )
448 $help[
'help-urls'] .= Html::closeElement(
'ul' );
449 $help[
'help-urls'] .= Html::closeElement(
'div' );
453 $dynamicParams = $module->dynamicParameterDocumentation();
455 if ( $params || $dynamicParams !==
null ) {
456 $help[
'parameters'] .= Html::openElement(
'div',
457 [
'class' =>
'apihelp-block apihelp-parameters' ]
460 if ( !$msg->isDisabled() ) {
462 $msg->numParams( count( $params ) ),
'apihelp-block-head',
'div'
465 $help[
'parameters'] .= Html::openElement(
'dl' );
467 $descriptions = $module->getFinalParamDescription();
469 foreach ( $params as $name => $settings ) {
470 $settings = $paramValidator->normalizeSettings( $settings );
476 $help[
'parameters'] .= Html::rawElement(
'dt',
null,
477 Html::element(
'span', [
'dir' =>
'ltr',
'lang' =>
'en' ], $module->encodeParamName( $name ) )
482 if ( isset( $descriptions[$name] ) ) {
483 foreach ( $descriptions[$name] as $msg ) {
485 $description[] = $msg->parseAsBlock();
488 if ( !array_filter( $description ) ) {
497 $help[
'parameters'] .= Html::openElement(
'dd',
498 [
'class' =>
'info' ] );
501 'apihelp-deprecated',
'strong'
503 $help[
'parameters'] .= Html::closeElement(
'dd' );
506 if ( $description ) {
507 $description = implode(
'', $description );
508 $description = preg_replace(
'!\s*</([oud]l)>\s*<\1>\s*!',
"\n", $description );
509 $help[
'parameters'] .= Html::rawElement(
'dd',
510 [
'class' =>
'description' ], $description );
515 $paramHelp = $paramValidator->getHelpInfo( $module, $name, $settings, [] );
517 unset( $paramHelp[ParamValidator::PARAM_DEPRECATED] );
519 if ( isset( $paramHelp[ParamValidator::PARAM_REQUIRED] ) ) {
520 $paramHelp[ParamValidator::PARAM_REQUIRED]->setContext(
$context );
521 $info[] = $paramHelp[ParamValidator::PARAM_REQUIRED];
522 unset( $paramHelp[ParamValidator::PARAM_REQUIRED] );
528 $tag = array_shift( $i );
529 $info[] =
$context->
msg(
"apihelp-{$path}-paraminfo-{$tag}" )
530 ->numParams( count( $i ) )
532 ->params( $module->getModulePrefix() )
540 $msg =
'api-help-param-templated-var-first';
542 $vars[] =
$context->
msg( $msg, $k, $module->encodeParamName( $v ) );
543 $msg =
'api-help-param-templated-var';
545 $info[] =
$context->
msg(
'api-help-param-templated' )
546 ->numParams( count( $vars ) )
552 foreach ( $paramHelp as $m ) {
557 foreach ( $info as $i ) {
558 $help[
'parameters'] .= Html::rawElement(
'dd', [
'class' =>
'info' ], $i );
562 if ( $dynamicParams !==
null ) {
564 $module->getModulePrefix(),
565 $module->getModuleName(),
566 $module->getModulePath()
568 $help[
'parameters'] .= Html::element(
'dt',
null,
'*' );
569 $help[
'parameters'] .= Html::rawElement(
'dd',
570 [
'class' =>
'description' ], $dynamicParams->parse() );
573 $help[
'parameters'] .= Html::closeElement(
'dl' );
574 $help[
'parameters'] .= Html::closeElement(
'div' );
577 $examples = $module->getExamplesMessages();
579 $help[
'examples'] .= Html::openElement(
'div',
580 [
'class' =>
'apihelp-block apihelp-examples' ] );
582 if ( !$msg->isDisabled() ) {
584 $msg->numParams( count( $examples ) ),
'apihelp-block-head',
'div'
588 $help[
'examples'] .= Html::openElement(
'dl' );
589 foreach ( $examples as $qs => $msg ) {
591 $module->getModulePrefix(),
592 $module->getModuleName(),
593 $module->getModulePath()
598 $help[
'examples'] .= Html::rawElement(
'dt',
null, $msg->parse() );
599 $help[
'examples'] .= Html::rawElement(
'dd',
null,
600 Html::element(
'a', [
604 ],
"api.php?$qs" ) .
' ' .
605 Html::rawElement(
'a', [
'href' => $sandbox ],
606 $context->
msg(
'api-help-open-in-apisandbox' )->parse() )
609 $help[
'examples'] .= Html::closeElement(
'dl' );
610 $help[
'examples'] .= Html::closeElement(
'div' );
613 $subtocnumber = $tocnumber;
614 $subtocnumber[$level + 1] = 0;
616 'submodules' => $options[
'recursivesubmodules'],
617 'headerlevel' => $level + 1,
618 'tocnumber' => &$subtocnumber,
622 if ( $options[
'submodules'] && $module->getModuleManager() ) {
623 $manager = $module->getModuleManager();
625 foreach ( $groups as $group ) {
626 $names = $manager->getNames( $group );
628 foreach ( $names as $name ) {
629 $submodules[] = $manager->getModule( $name );
640 $module->modifyHelp(
$help, $suboptions, $haveModules );
642 $module->getHookRunner()->onAPIHelpModifyOutput( $module,
$help,
643 $suboptions, $haveModules );
645 $out .= implode(
"\n",
$help );