The module's summary will be used as the description of the value.
Since these are often very long lists, this also changes ApiSandbox to
collapse <dl> lists in parameter descriptions by default.
Bug: T123930
Change-Id: I205b68a52a94cae4c1cdf7ec9fd3e8a04d565919
}
$msgs[$param] = [ $msg ];
- if ( isset( $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE] ) ) {
+ if ( isset( $settings[ApiBase::PARAM_TYPE] ) &&
+ $settings[ApiBase::PARAM_TYPE] === 'submodule'
+ ) {
+ if ( isset( $settings[ApiBase::PARAM_SUBMODULE_MAP] ) ) {
+ $map = $settings[ApiBase::PARAM_SUBMODULE_MAP];
+ } else {
+ $prefix = $this->isMain() ? '' : ( $this->getModulePath() . '+' );
+ $map = [];
+ foreach ( $this->getModuleManager()->getNames( $param ) as $submoduleName ) {
+ $map[$submoduleName] = $prefix . $submoduleName;
+ }
+ }
+ ksort( $map );
+ $submodules = [];
+ $deprecatedSubmodules = [];
+ foreach ( $map as $v => $m ) {
+ $arr = &$submodules;
+ $isDeprecated = false;
+ $summary = null;
+ try {
+ $submod = $this->getModuleFromPath( $m );
+ if ( $submod ) {
+ $summary = $submod->getFinalSummary();
+ $isDeprecated = $submod->isDeprecated();
+ if ( $isDeprecated ) {
+ $arr = &$deprecatedSubmodules;
+ }
+ }
+ } catch ( ApiUsageException $ex ) {
+ // Ignore
+ }
+ if ( $summary ) {
+ $key = $summary->getKey();
+ $params = $summary->getParams();
+ } else {
+ $key = 'api-help-undocumented-module';
+ $params = [ $m ];
+ }
+ $m = new ApiHelpParamValueMessage( "[[Special:ApiHelp/$m|$v]]", $key, $params, $isDeprecated );
+ $arr[] = $m->setContext( $this->getContext() );
+ }
+ $msgs[$param] = array_merge( $msgs[$param], $submodules, $deprecatedSubmodules );
+ } elseif ( isset( $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE] ) ) {
if ( !is_array( $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE] ) ) {
self::dieDebug( __METHOD__,
'ApiBase::PARAM_HELP_MSG_PER_VALUE is not valid' );
switch ( $type ) {
case 'submodule':
$groups[] = $name;
+
if ( isset( $settings[ApiBase::PARAM_SUBMODULE_MAP] ) ) {
$map = $settings[ApiBase::PARAM_SUBMODULE_MAP];
- ksort( $map );
- $submodules = [];
- foreach ( $map as $v => $m ) {
- $submodules[] = "[[Special:ApiHelp/{$m}|{$v}]]";
- }
+ $defaultAttrs = [];
} else {
- $submodules = $module->getModuleManager()->getNames( $name );
- sort( $submodules );
- $prefix = $module->isMain()
- ? '' : ( $module->getModulePath() . '+' );
- $submodules = array_map( function ( $name ) use ( $prefix ) {
- $text = Html::element( 'span', [ 'dir' => 'ltr', 'lang' => 'en' ], $name );
- return "[[Special:ApiHelp/{$prefix}{$name}|{$text}]]";
- }, $submodules );
+ $prefix = $module->isMain() ? '' : ( $module->getModulePath() . '+' );
+ $map = [];
+ foreach ( $module->getModuleManager()->getNames( $name ) as $submoduleName ) {
+ $map[$submoduleName] = $prefix . $submoduleName;
+ }
+ $defaultAttrs = [ 'dir' => 'ltr', 'lang' => 'en' ];
+ }
+ ksort( $map );
+
+ $submodules = [];
+ $deprecatedSubmodules = [];
+ foreach ( $map as $v => $m ) {
+ $attrs = $defaultAttrs;
+ $arr = &$submodules;
+ try {
+ $submod = $module->getModuleFromPath( $m );
+ if ( $submod ) {
+ if ( $submod->isDeprecated() ) {
+ $arr = &$deprecatedSubmodules;
+ $attrs['class'] = 'apihelp-deprecated-value';
+ }
+ }
+ } catch ( ApiUsageException $ex ) {
+ // Ignore
+ }
+ if ( $attrs ) {
+ $v = Html::element( 'span', $attrs, $v );
+ }
+ $arr[] = "[[Special:ApiHelp/{$m}|{$v}]]";
}
+ $submodules = array_merge( $submodules, $deprecatedSubmodules );
$count = count( $submodules );
$info[] = $context->msg( 'api-help-param-list' )
->params( $multi ? 2 : 1 )
if ( isset( $settings[ApiBase::PARAM_SUBMODULE_PARAM_PREFIX] ) ) {
$item['submoduleparamprefix'] = $settings[ApiBase::PARAM_SUBMODULE_PARAM_PREFIX];
}
+
+ $deprecatedSubmodules = [];
+ foreach ( $item['submodules'] as $v => $submodulePath ) {
+ try {
+ $submod = $this->getModuleFromPath( $submodulePath );
+ if ( $submod && $submod->isDeprecated() ) {
+ $deprecatedSubmodules[] = $v;
+ }
+ } catch ( ApiUsageException $ex ) {
+ // Ignore
+ }
+ }
+ if ( $deprecatedSubmodules ) {
+ $item['type'] = array_merge(
+ array_diff( $item['type'], $deprecatedSubmodules ),
+ $deprecatedSubmodules
+ );
+ $item['deprecatedvalues'] = $deprecatedSubmodules;
+ }
} elseif ( $settings[ApiBase::PARAM_TYPE] === 'tags' ) {
$item['type'] = ChangeTags::listExplicitlyDefinedTags();
} else {
"api-help-title": "MediaWiki API help",
"api-help-lead": "This is an auto-generated MediaWiki API documentation page.\n\nDocumentation and examples: https://www.mediawiki.org/wiki/API",
"api-help-main-header": "Main module",
+ "api-help-undocumented-module": "No documentation for module $1.",
"api-help-fallback-description": "$1",
"api-help-fallback-parameter": "$1",
"api-help-fallback-example": "$1",
"api-help-title": "Page title for the auto-generated help output",
"api-help-lead": "Text displayed at the top of the API help page",
"api-help-main-header": "Text for the header of the main module",
+ "api-help-undocumented-module": "Text displayed for the summary of a submodule parameter when the module can't be loaded.\n\nParameters:\n* $1 - The module path.",
"api-help-fallback-description": "{{notranslate}}",
"api-help-fallback-parameter": "{{notranslate}}",
"api-help-fallback-example": "{{notranslate}}",
'oojs-ui.styles.icons-interactions',
'oojs-ui.styles.icons-moderation',
'mediawiki.widgets.datetime',
+ 'jquery.makeCollapsible',
],
'messages' => [
'apisandbox-intro',
}
descriptionContainer = $( '<div>' );
- descriptionContainer.append( $( '<div>', {
- addClass: 'description',
- append: Util.parseHTML( pi.parameters[ i ].description )
- } ) );
+
+ tmp = Util.parseHTML( pi.parameters[ i ].description );
+ tmp.filter( 'dl' ).makeCollapsible( {
+ collapsed: true
+ } ).children( '.mw-collapsible-toggle' ).each( function () {
+ var $this = $( this );
+ $this.parent().prev( 'p' ).append( $this );
+ } );
+ descriptionContainer.append( $( '<div>', { addClass: 'description', append: tmp } ) );
+
if ( pi.parameters[ i ].info && pi.parameters[ i ].info.length ) {
for ( j = 0; j < pi.parameters[ i ].info.length; j++ ) {
descriptionContainer.append( $( '<div>', {