247 array $options, &$haveModules
251 $level = empty( $options[
'headerlevel'] ) ? 2 : $options[
'headerlevel'];
252 if ( empty( $options[
'tocnumber'] ) ) {
253 $tocnumber = [ 2 => 0 ];
255 $tocnumber = &$options[
'tocnumber'];
259 $paramValidator = $module->getMain()->getParamValidator();
260 $tocnumber[$level]++;
261 $path = $module->getModulePath();
273 if ( empty( $options[
'noheader'] ) || !empty( $options[
'toc'] ) ) {
276 while ( isset( $haveModules[$anchor] ) ) {
277 $anchor =
$path .
'|' . ++$i;
280 if ( $module->isMain() ) {
281 $headerContent =
$context->
msg(
'api-help-main-header' )->parse();
283 'class' =>
'apihelp-header',
286 $name = $module->getModuleName();
287 $headerContent = $module->getParent()->getModuleManager()->getModuleGroup( $name ) .
289 if ( $module->getModulePrefix() !==
'' ) {
290 $headerContent .=
' ' .
291 $context->
msg(
'parentheses', $module->getModulePrefix() )->parse();
297 'class' =>
'apihelp-header apihelp-module-name',
303 $headerAttr[
'id'] = $anchor;
305 $haveModules[$anchor] = [
306 'toclevel' => count( $tocnumber ),
309 'line' => $headerContent,
310 'number' => implode(
'.', $tocnumber ),
313 if ( empty( $options[
'noheader'] ) ) {
314 $help[
'header'] .= Html::element(
315 'h' . min( 6, $level ),
321 $haveModules[
$path] =
true;
326 for ( $m = $module; $m !==
null; $m = $m->getParent() ) {
327 $name = $m->getModuleName();
328 if ( $name ===
'main_int' ) {
333 !( !empty( $options[
'submodules'] ) && $m->getModuleManager() )
335 $link = Html::element(
'b', [
'dir' =>
'ltr',
'lang' =>
'en' ], $name );
338 $link = Html::element(
'a',
339 [
'href' => $link,
'class' =>
'apihelp-linktrail',
'dir' =>
'ltr',
'lang' =>
'en' ],
344 array_unshift( $links, $link );
350 'apihelp-linktrail',
'div'
354 $flags = $module->getHelpFlags();
355 $help[
'flags'] .= Html::openElement(
'div',
356 [
'class' =>
'apihelp-block apihelp-flags' ] );
358 if ( !$msg->isDisabled() ) {
360 $msg->numParams( count( $flags ) ),
'apihelp-block-head',
'div'
363 $help[
'flags'] .= Html::openElement(
'ul' );
364 foreach ( $flags as $flag ) {
365 $help[
'flags'] .= Html::rawElement(
'li',
null,
366 self::wrap(
$context->
msg(
"api-help-flag-$flag" ),
"apihelp-flag-$flag" )
369 $sourceInfo = $module->getModuleSourceInfo();
371 if ( isset( $sourceInfo[
'namemsg'] ) ) {
372 $extname =
$context->
msg( $sourceInfo[
'namemsg'] )->text();
375 $extname = Html::element(
'span', [
'dir' =>
'ltr',
'lang' =>
'en' ], $sourceInfo[
'name'] );
377 $help[
'flags'] .= Html::rawElement(
'li',
null,
379 $context->
msg(
'api-help-source', $extname, $sourceInfo[
'name'] ),
385 if ( isset( $sourceInfo[
'license-name'] ) ) {
387 Html::element(
'span', [
'dir' =>
'ltr',
'lang' =>
'en' ], $sourceInfo[
'license-name'] )
389 } elseif ( ExtensionInfo::getLicenseFileNames( dirname( $sourceInfo[
'path'] ) ) ) {
390 $msg =
$context->
msg(
'api-help-license-noname', $link );
392 $msg =
$context->
msg(
'api-help-license-unknown' );
394 $help[
'flags'] .= Html::rawElement(
'li',
null,
395 self::wrap( $msg,
'apihelp-license' )
398 $help[
'flags'] .= Html::rawElement(
'li',
null,
399 self::wrap(
$context->
msg(
'api-help-source-unknown' ),
'apihelp-source' )
401 $help[
'flags'] .= Html::rawElement(
'li',
null,
402 self::wrap(
$context->
msg(
'api-help-license-unknown' ),
'apihelp-license' )
405 $help[
'flags'] .= Html::closeElement(
'ul' );
406 $help[
'flags'] .= Html::closeElement(
'div' );
408 foreach ( $module->getFinalDescription() as $msg ) {
410 $help[
'description'] .= $msg->parseAsBlock();
413 $urls = $module->getHelpUrls();
415 $help[
'help-urls'] .= Html::openElement(
'div',
416 [
'class' =>
'apihelp-block apihelp-help-urls' ]
419 if ( !$msg->isDisabled() ) {
421 $msg->numParams( count( $urls ) ),
'apihelp-block-head',
'div'
424 if ( !is_array( $urls ) ) {
427 $help[
'help-urls'] .= Html::openElement(
'ul' );
428 foreach ( $urls as $url ) {
429 $help[
'help-urls'] .= Html::rawElement(
'li',
null,
430 Html::element(
'a', [
'href' => $url,
'dir' =>
'ltr' ], $url )
433 $help[
'help-urls'] .= Html::closeElement(
'ul' );
434 $help[
'help-urls'] .= Html::closeElement(
'div' );
438 $dynamicParams = $module->dynamicParameterDocumentation();
440 if ( $params || $dynamicParams !==
null ) {
441 $help[
'parameters'] .= Html::openElement(
'div',
442 [
'class' =>
'apihelp-block apihelp-parameters' ]
445 if ( !$msg->isDisabled() ) {
447 $msg->numParams( count( $params ) ),
'apihelp-block-head',
'div'
450 $help[
'parameters'] .= Html::openElement(
'dl' );
452 $descriptions = $module->getFinalParamDescription();
454 foreach ( $params as $name => $settings ) {
455 $settings = $paramValidator->normalizeSettings( $settings );
461 $help[
'parameters'] .= Html::rawElement(
'dt',
null,
462 Html::element(
'span', [
'dir' =>
'ltr',
'lang' =>
'en' ], $module->encodeParamName( $name ) )
467 if ( isset( $descriptions[$name] ) ) {
468 foreach ( $descriptions[$name] as $msg ) {
470 $description[] = $msg->parseAsBlock();
473 if ( !array_filter( $description ) ) {
482 $help[
'parameters'] .= Html::openElement(
'dd',
483 [
'class' =>
'info' ] );
486 'apihelp-deprecated',
'strong'
488 $help[
'parameters'] .= Html::closeElement(
'dd' );
491 if ( $description ) {
492 $description = implode(
'', $description );
493 $description = preg_replace(
'!\s*</([oud]l)>\s*<\1>\s*!',
"\n", $description );
494 $help[
'parameters'] .= Html::rawElement(
'dd',
495 [
'class' =>
'description' ], $description );
500 $paramHelp = $paramValidator->getHelpInfo( $module, $name, $settings, [] );
502 unset( $paramHelp[ParamValidator::PARAM_DEPRECATED] );
504 if ( isset( $paramHelp[ParamValidator::PARAM_REQUIRED] ) ) {
505 $paramHelp[ParamValidator::PARAM_REQUIRED]->setContext(
$context );
506 $info[] = $paramHelp[ParamValidator::PARAM_REQUIRED];
507 unset( $paramHelp[ParamValidator::PARAM_REQUIRED] );
513 $tag = array_shift( $i );
514 $info[] =
$context->
msg(
"apihelp-{$path}-paraminfo-{$tag}" )
515 ->numParams( count( $i ) )
517 ->params( $module->getModulePrefix() )
525 $msg =
'api-help-param-templated-var-first';
527 $vars[] =
$context->
msg( $msg, $k, $module->encodeParamName( $v ) );
528 $msg =
'api-help-param-templated-var';
530 $info[] =
$context->
msg(
'api-help-param-templated' )
531 ->numParams( count( $vars ) )
537 foreach ( $paramHelp as $m ) {
542 foreach ( $info as $i ) {
543 $help[
'parameters'] .= Html::rawElement(
'dd', [
'class' =>
'info' ], $i );
547 if ( $dynamicParams !==
null ) {
549 $module->getModulePrefix(),
550 $module->getModuleName(),
551 $module->getModulePath()
553 $help[
'parameters'] .= Html::element(
'dt',
null,
'*' );
554 $help[
'parameters'] .= Html::rawElement(
'dd',
555 [
'class' =>
'description' ], $dynamicParams->parse() );
558 $help[
'parameters'] .= Html::closeElement(
'dl' );
559 $help[
'parameters'] .= Html::closeElement(
'div' );
562 $examples = $module->getExamplesMessages();
564 $help[
'examples'] .= Html::openElement(
'div',
565 [
'class' =>
'apihelp-block apihelp-examples' ] );
567 if ( !$msg->isDisabled() ) {
569 $msg->numParams( count( $examples ) ),
'apihelp-block-head',
'div'
573 $help[
'examples'] .= Html::openElement(
'dl' );
574 foreach ( $examples as $qs => $msg ) {
576 $module->getModulePrefix(),
577 $module->getModuleName(),
578 $module->getModulePath()
583 $help[
'examples'] .= Html::rawElement(
'dt',
null, $msg->parse() );
584 $help[
'examples'] .= Html::rawElement(
'dd',
null,
585 Html::element(
'a', [
589 ],
"api.php?$qs" ) .
' ' .
590 Html::rawElement(
'a', [
'href' => $sandbox ],
591 $context->
msg(
'api-help-open-in-apisandbox' )->parse() )
594 $help[
'examples'] .= Html::closeElement(
'dl' );
595 $help[
'examples'] .= Html::closeElement(
'div' );
598 $subtocnumber = $tocnumber;
599 $subtocnumber[$level + 1] = 0;
601 'submodules' => $options[
'recursivesubmodules'],
602 'headerlevel' => $level + 1,
603 'tocnumber' => &$subtocnumber,
607 if ( $options[
'submodules'] && $module->getModuleManager() ) {
608 $manager = $module->getModuleManager();
610 foreach ( $groups as $group ) {
611 $names = $manager->getNames( $group );
613 foreach ( $names as $name ) {
614 $submodules[] = $manager->getModule( $name );
625 $module->modifyHelp(
$help, $suboptions, $haveModules );
627 $module->getHookRunner()->onAPIHelpModifyOutput( $module,
$help,
628 $suboptions, $haveModules );
630 $out .= implode(
"\n",
$help );