33 public function checkSettings(
string $name, $settings, array $options, array $ret ): array {
35 if ( !is_array( $map ) ) {
42 $ret = parent::checkSettings( $name, $settings, $options, $ret );
44 $ret[
'allowedKeys'] = array_merge( $ret[
'allowedKeys'], [
45 self::PARAM_SUBMODULE_MAP, self::PARAM_SUBMODULE_PARAM_PREFIX,
48 if ( is_array( $map ) ) {
49 $module = $options[
'module'];
50 foreach ( $map as $k => $v ) {
51 if ( !is_string( $v ) ) {
52 $ret[
'issues'][] =
'Values for PARAM_SUBMODULE_MAP must be strings, '
53 .
"but value for \"$k\" is " . gettype( $v );
58 $submod = $module->getModuleFromPath( $v );
63 $ret[
'issues'][] =
"PARAM_SUBMODULE_MAP contains \"$v\", which is not a valid module path";
68 if ( !is_string( $settings[self::PARAM_SUBMODULE_PARAM_PREFIX] ??
'' ) ) {
70 .
'a string, got ' . gettype( $settings[self::PARAM_SUBMODULE_PARAM_PREFIX] );
76 public function getEnumValues( $name, array $settings, array $options ) {
77 if ( isset( $settings[self::PARAM_SUBMODULE_MAP] ) ) {
78 $modules = array_keys( $settings[self::PARAM_SUBMODULE_MAP] );
80 $modules = $options[
'module']->getModuleManager()->getNames( $name );
86 public function getParamInfo( $name, array $settings, array $options ) {
87 $info = parent::getParamInfo( $name, $settings, $options );
89 $module = $options[
'module'];
91 if ( isset( $settings[self::PARAM_SUBMODULE_MAP] ) ) {
92 $info[
'type'] = array_keys( $settings[self::PARAM_SUBMODULE_MAP] );
93 $info[
'submodules'] = $settings[self::PARAM_SUBMODULE_MAP];
95 $info[
'type'] = $module->getModuleManager()->getNames( $name );
96 $prefix = $module->isMain() ?
'' : ( $module->getModulePath() .
'+' );
97 $info[
'submodules'] = [];
98 foreach ( $info[
'type'] as $v ) {
99 $info[
'submodules'][$v] = $prefix . $v;
102 if ( isset( $settings[self::PARAM_SUBMODULE_PARAM_PREFIX] ) ) {
103 $info[
'submoduleparamprefix'] = $settings[self::PARAM_SUBMODULE_PARAM_PREFIX];
106 $submoduleFlags = [];
107 $submoduleNames = [];
108 foreach ( $info[
'submodules'] as $v => $submodulePath ) {
110 $submod = $module->getModuleFromPath( $submodulePath );
112 $submoduleFlags[] = 0;
113 $submoduleNames[] = $v;
117 if ( $submod && $submod->isDeprecated() ) {
118 $info[
'deprecatedvalues'][] = $v;
121 if ( $submod && $submod->isInternal() ) {
122 $info[
'internalvalues'][] = $v;
125 $submoduleFlags[] = $flags;
126 $submoduleNames[] = $v;
129 array_multisort( $submoduleFlags, $submoduleNames, $info[
'submodules'], $info[
'type'] );
130 if ( isset( $info[
'deprecatedvalues'] ) ) {
131 sort( $info[
'deprecatedvalues'] );
133 if ( isset( $info[
'internalvalues'] ) ) {
134 sort( $info[
'internalvalues'] );
140 private function getSubmoduleMap(
ApiBase $module,
string $name, array $settings ): array {
141 if ( isset( $settings[self::PARAM_SUBMODULE_MAP] ) ) {
142 $map = $settings[self::PARAM_SUBMODULE_MAP];
144 $prefix = $module->isMain() ?
'' : ( $module->getModulePath() .
'+' );
146 foreach ( $module->getModuleManager()->getNames( $name ) as $submoduleName ) {
147 $map[$submoduleName] = $prefix . $submoduleName;
155 string $name, array $values, array $settings, array $options
157 $module = $options[
'module'];
158 $map = $this->getSubmoduleMap( $module, $name, $settings );
160 $submoduleFlags = [];
161 foreach ( $values as $k => $v ) {
164 $submod = isset( $map[$v] ) ? $module->getModuleFromPath( $map[$v] ) :
null;
165 if ( $submod && $submod->isDeprecated() ) {
168 if ( $submod && $submod->isInternal() ) {
174 $submoduleFlags[$k] = $flags;
176 array_multisort( $submoduleFlags, $values, SORT_NATURAL );
182 $module = $options[
'module'];
183 $map = $this->getSubmoduleMap( $module, $name, $settings );
184 $defaultAttrs = [
'dir' =>
'ltr',
'lang' =>
'en' ];
187 $submoduleFlags = [];
188 $submoduleNames = [];
189 foreach ( $map as $v => $m ) {
190 $attrs = $defaultAttrs;
193 $submod = $module->getModuleFromPath( $m );
194 if ( $submod && $submod->isDeprecated() ) {
195 $attrs[
'class'][] =
'apihelp-deprecated-value';
198 if ( $submod && $submod->isInternal() ) {
199 $attrs[
'class'][] =
'apihelp-internal-value';
205 $v = Html::element(
'span', $attrs, $v );
206 $values[] =
"[[Special:ApiHelp/{$m}|{$v}]]";
207 $submoduleFlags[] = $flags;
208 $submoduleNames[] = $v;
211 array_multisort( $submoduleFlags, $submoduleNames, SORT_NATURAL, $values, SORT_NATURAL );
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
This abstract class implements many basic API functions, and is the base of all API classes.
Exception used to abort API execution with an error.
This class is a collection of static functions that serve two purposes: