178 if ( !is_string( $settingName ) ) {
179 wfDeprecated( __METHOD__ .
' with non-string $settingName',
'1.44' );
180 $settingName = (string)$settingName;
182 if ( $wiki ===
null ) {
183 wfDeprecated( __METHOD__ .
' with null $wiki',
'1.44' );
185 if ( !is_string( $wiki ) ) {
186 wfDeprecated( __METHOD__ .
' with non-string $wiki',
'1.44' );
188 $wiki = (string)$wiki;
189 if ( $site !==
null && !is_string( $site ) ) {
190 wfDeprecated( __METHOD__ .
' with non-string $site',
'1.44' );
191 $site = (string)$site;
193 if ( !is_array( $params ) ) {
194 wfDeprecated( __METHOD__ .
' with non-array $params',
'1.44' );
195 $params = (array)$params;
197 if ( !is_array( $wikiTags ) ) {
198 wfDeprecated( __METHOD__ .
' with non-array $wikiTags',
'1.44' );
199 $wikiTags = (array)$wikiTags;
201 $params = $this->
mergeParams( $wiki, $site, $params, $wikiTags );
202 $overrides = $this->settings[$settingName] ??
null;
203 $value = $overrides ? $this->processSetting( $overrides, $wiki, $params[
'tags'] ) :
null;
204 if ( !array_key_exists(
'@replaceableSettings', $this->settings )
205 || in_array( $settingName, $this->settings[
'@replaceableSettings'] )
207 $this->doReplacements( $value, $params[
'replacements'] );
243 private function processSetting( $thisSetting, $wiki, $tags ) {
249 if ( count( $thisSetting ) === 1 && array_key_exists(
'default', $thisSetting ) ) {
250 return $thisSetting[
'default'];
255 if ( array_key_exists( $wiki, $thisSetting ) ) {
257 $retval = $thisSetting[$wiki];
259 if ( array_key_exists(
"+$wiki", $thisSetting ) ) {
262 $retval = $thisSetting[
"+$wiki"];
265 foreach ( $tags as $tag ) {
266 if ( array_key_exists( $tag, $thisSetting ) ) {
267 if ( is_array( $retval ) && is_array( $thisSetting[$tag] ) ) {
270 $retval = self::arrayMerge( $retval, $thisSetting[$tag] );
275 $retval = $thisSetting[$tag];
278 } elseif ( array_key_exists(
"+$tag", $thisSetting ) ) {
282 $retval = self::arrayMerge( $retval ?? [], $thisSetting[
"+$tag"] );
286 if ( array_key_exists(
'default', $thisSetting ) ) {
287 if ( is_array( $retval ) && is_array( $thisSetting[
'default'] ) ) {
290 $retval = self::arrayMerge( $retval, $thisSetting[
'default'] );
296 $retval = $thisSetting[
'default'];
309 private function doReplacements( &$value, $replacements ) {
313 if ( is_string( $value ) ) {
314 $value = strtr( $value, $replacements );
315 } elseif ( is_array( $value ) ) {
316 foreach ( $value as &$val ) {
317 if ( is_string( $val ) ) {
318 $val = strtr( $val, $replacements );
332 public function getAll( $wiki, $site =
null, $params = [], $wikiTags = [] ) {
333 if ( $wiki ===
null ) {
334 wfDeprecated( __METHOD__ .
' with null $wiki',
'1.44' );
336 if ( !is_string( $wiki ) ) {
337 wfDeprecated( __METHOD__ .
' with non-string $wiki',
'1.44' );
339 $wiki = (string)$wiki;
340 if ( $site !==
null && !is_string( $site ) ) {
341 wfDeprecated( __METHOD__ .
' with non-string $site',
'1.44' );
342 $site = (string)$site;
344 if ( !is_array( $params ) ) {
345 wfDeprecated( __METHOD__ .
' with non-array $params',
'1.44' );
346 $params = (array)$params;
348 if ( !is_array( $wikiTags ) ) {
349 wfDeprecated( __METHOD__ .
' with non-array $wikiTags',
'1.44' );
350 $wikiTags = (array)$wikiTags;
352 $params = $this->
mergeParams( $wiki, $site, $params, $wikiTags );
353 $tags = $params[
'tags'];
355 foreach ( $this->settings as $varname => $overrides ) {
356 $value = $this->processSetting( $overrides, $wiki, $tags );
357 if ( $varname[0] ===
'+' ) {
358 $varname = substr( $varname, 1 );
359 if ( is_array( $value ) && is_array( $GLOBALS[$varname] ) ) {
360 $value = self::arrayMerge( $value, $GLOBALS[$varname] );
363 if ( $value !==
null ) {
364 $localSettings[$varname] = $value;
368 $replacements = $params[
'replacements'];
369 if ( array_key_exists(
'@replaceableSettings', $this->settings ) ) {
370 foreach ( $this->settings[
'@replaceableSettings'] as $varname ) {
371 if ( array_key_exists( $varname, $localSettings ) ) {
372 $this->doReplacements( $localSettings[$varname], $replacements );
376 foreach ( $localSettings as &$value ) {
377 $this->doReplacements( $value, $replacements );
380 return $localSettings;
392 public function getBool( $setting, $wiki, $site =
null, $wikiTags = [] ) {
393 if ( !is_string( $setting ) ) {
394 wfDeprecated( __METHOD__ .
' with non-string $setting',
'1.44' );
395 $setting = (string)$setting;
397 if ( $wiki ===
null ) {
398 wfDeprecated( __METHOD__ .
' with null $wiki',
'1.44' );
400 if ( !is_string( $wiki ) ) {
401 wfDeprecated( __METHOD__ .
' with non-string $wiki',
'1.44' );
403 $wiki = (string)$wiki;
404 if ( $site !==
null && !is_string( $site ) ) {
405 wfDeprecated( __METHOD__ .
' with non-string $site',
'1.44' );
406 $site = (string)$site;
408 if ( !is_array( $wikiTags ) ) {
409 wfDeprecated( __METHOD__ .
' with non-array $wikiTags',
'1.44' );
410 $wikiTags = (array)$wikiTags;
412 return (
bool)$this->
get( $setting, $wiki, $site, [], $wikiTags );
429 private function extractGlobalSetting( $setting, $wiki, $params ) {
430 $overrides = $this->settings[$setting] ??
null;
431 $value = $overrides ? $this->processSetting( $overrides, $wiki, $params[
'tags'] ) : null;
432 if ( !array_key_exists(
'@replaceableSettings', $this->settings )
433 || in_array( $setting, $this->settings[
'@replaceableSettings'] )
435 $this->doReplacements( $value, $params[
'replacements'] );
437 if ( $value !==
null ) {
438 if ( substr( $setting, 0, 1 ) ==
'+' && is_array( $value ) ) {
439 $setting = substr( $setting, 1 );
440 if ( is_array( $GLOBALS[$setting] ) ) {
441 $GLOBALS[$setting] = self::arrayMerge( $GLOBALS[$setting], $value );
443 $GLOBALS[$setting] = $value;
446 $GLOBALS[$setting] = $value;
464 if ( $wiki ===
null ) {
465 wfDeprecated( __METHOD__ .
' with null $wiki',
'1.44' );
467 if ( !is_string( $wiki ) ) {
468 wfDeprecated( __METHOD__ .
' with non-string $wiki',
'1.44' );
470 $wiki = (string)$wiki;
471 if ( $site !==
null && !is_string( $site ) ) {
472 wfDeprecated( __METHOD__ .
' with non-string $site',
'1.44' );
473 $site = (string)$site;
475 if ( !is_array( $params ) ) {
476 wfDeprecated( __METHOD__ .
' with non-array $params',
'1.44' );
477 $params = (array)$params;
479 if ( !is_array( $wikiTags ) ) {
480 wfDeprecated( __METHOD__ .
' with non-array $wikiTags',
'1.44' );
481 $wikiTags = (array)$wikiTags;
483 $params = $this->
mergeParams( $wiki, $site, $params, $wikiTags );
484 foreach ( $this->settings as $setting => $overrides ) {
485 $this->extractGlobalSetting( $setting, $wiki, $params );
505 if ( !is_callable( $this->siteParamsCallback ) ) {
510 # Validate the returned value
511 if ( !is_array( $ret ) ) {
515 foreach ( $default as $name => $def ) {
516 if ( !isset( $ret[$name] ) || ( is_array( $def ) && !is_array( $ret[$name] ) ) ) {
536 protected function mergeParams( $wiki, $site, array $params, array $wikiTags ) {
539 $ret[
'suffix'] ??= $site;
544 if ( $ret[
'suffix'] !==
null ) {
545 $wikiTags[] = $ret[
'suffix'];
548 $ret[
'tags'] = array_unique( array_merge( $ret[
'tags'], $wikiTags ) );
550 $ret[
'params'] += $params;
554 if ( !isset( $ret[
'params'][
'lang'] ) && $ret[
'lang'] !==
null ) {
555 $ret[
'params'][
'lang'] = $ret[
'lang'];
557 if ( !isset( $ret[
'params'][
'site'] ) && $ret[
'suffix'] !==
null ) {
558 $ret[
'params'][
'site'] = $ret[
'suffix'];
563 $ret[
'replacements'] = [];
564 foreach ( $ret[
'params'] as $key => $value ) {
565 $ret[
'replacements'][
'$' . $key] = $value;
578 if ( $wiki ===
null ) {
579 wfDeprecated( __METHOD__ .
' with null $wiki',
'1.44' );
581 if ( !is_string( $wiki ) ) {
582 wfDeprecated( __METHOD__ .
' with non-string $wiki',
'1.44' );
584 $wiki = (string)$wiki;
587 if ( $def[
'suffix'] !==
null && $def[
'lang'] !==
null ) {
588 return [ $def[
'suffix'], $def[
'lang'] ];
591 $languageCode = str_replace(
'_',
'-', $wiki );
592 foreach ( $this->suffixes as $altSite => $suffix ) {
593 if ( $suffix ===
'' ) {
594 return [
'', $languageCode ];
595 } elseif ( str_ends_with( $wiki, $suffix ) ) {
596 $site = is_string( $altSite ) ? $altSite : $suffix;
597 $languageCode = substr( $languageCode, 0, -strlen( $suffix ) );
598 return [ $site, $languageCode ];
602 return [
null, null ];
615 private static function arrayMerge( array $array1, array $array2 ) {
617 foreach ( $array2 as $key => $value ) {
618 if ( isset( $out[$key] ) ) {
619 if ( is_array( $out[$key] ) && is_array( $value ) ) {
621 $out[$key] = self::arrayMerge( $out[$key], $value );
622 } elseif ( is_numeric( $key ) ) {
630 } elseif ( $out[$key] ===
false ) {
648 if ( $this->fullLoadCallback && !$this->fullLoadDone ) {
650 $this->fullLoadDone =
true;