190 if ( !is_string( $settingName ) ) {
191 wfDeprecated( __METHOD__ .
' with non-string $settingName',
'1.44' );
192 $settingName = (string)$settingName;
194 if ( $wiki ===
null ) {
195 wfDeprecated( __METHOD__ .
' with null $wiki',
'1.44' );
197 if ( !is_string( $wiki ) ) {
198 wfDeprecated( __METHOD__ .
' with non-string $wiki',
'1.44' );
200 $wiki = (string)$wiki;
201 if ( $site !==
null && !is_string( $site ) ) {
202 wfDeprecated( __METHOD__ .
' with non-string $site',
'1.44' );
203 $site = (string)$site;
205 if ( !is_array( $params ) ) {
206 wfDeprecated( __METHOD__ .
' with non-array $params',
'1.44' );
207 $params = (array)$params;
209 if ( !is_array( $wikiTags ) ) {
210 wfDeprecated( __METHOD__ .
' with non-array $wikiTags',
'1.44' );
211 $wikiTags = (array)$wikiTags;
213 $params = $this->
mergeParams( $wiki, $site, $params, $wikiTags );
214 $overrides = $this->settings[$settingName] ??
null;
215 $value = $overrides ? $this->processSetting( $overrides, $wiki, $params[
'tags'] ) :
null;
216 if ( !array_key_exists(
'@replaceableSettings', $this->settings )
217 || in_array( $settingName, $this->settings[
'@replaceableSettings'] )
219 $this->doReplacements( $value, $params[
'replacements'] );
255 private function processSetting( $thisSetting, $wiki, $tags ) {
261 if ( array_key_exists( $wiki, $thisSetting ) ) {
263 $retval = $thisSetting[$wiki];
265 if ( array_key_exists(
"+$wiki", $thisSetting ) ) {
268 $retval = $thisSetting[
"+$wiki"];
271 foreach ( $tags as $tag ) {
272 if ( array_key_exists( $tag, $thisSetting ) ) {
273 if ( is_array( $retval ) && is_array( $thisSetting[$tag] ) ) {
276 $retval = self::arrayMerge( $retval, $thisSetting[$tag] );
281 $retval = $thisSetting[$tag];
284 } elseif ( array_key_exists(
"+$tag", $thisSetting ) ) {
288 $retval = self::arrayMerge( $retval ?? [], $thisSetting[
"+$tag"] );
292 if ( array_key_exists(
'default', $thisSetting ) ) {
293 if ( is_array( $retval ) && is_array( $thisSetting[
'default'] ) ) {
296 $retval = self::arrayMerge( $retval, $thisSetting[
'default'] );
302 $retval = $thisSetting[
'default'];
315 private function doReplacements( &$value, $replacements ) {
319 if ( is_string( $value ) ) {
320 $value = strtr( $value, $replacements );
321 } elseif ( is_array( $value ) ) {
322 foreach ( $value as &$val ) {
323 if ( is_string( $val ) ) {
324 $val = strtr( $val, $replacements );
338 public function getAll( $wiki, $site =
null, $params = [], $wikiTags = [] ) {
339 if ( $wiki ===
null ) {
340 wfDeprecated( __METHOD__ .
' with null $wiki',
'1.44' );
342 if ( !is_string( $wiki ) ) {
343 wfDeprecated( __METHOD__ .
' with non-string $wiki',
'1.44' );
345 $wiki = (string)$wiki;
346 if ( $site !==
null && !is_string( $site ) ) {
347 wfDeprecated( __METHOD__ .
' with non-string $site',
'1.44' );
348 $site = (string)$site;
350 if ( !is_array( $params ) ) {
351 wfDeprecated( __METHOD__ .
' with non-array $params',
'1.44' );
352 $params = (array)$params;
354 if ( !is_array( $wikiTags ) ) {
355 wfDeprecated( __METHOD__ .
' with non-array $wikiTags',
'1.44' );
356 $wikiTags = (array)$wikiTags;
358 $params = $this->
mergeParams( $wiki, $site, $params, $wikiTags );
359 $tags = $params[
'tags'];
361 foreach ( $this->settings as $varname => $overrides ) {
362 $value = $this->processSetting( $overrides, $wiki, $tags );
363 if ( $varname[0] ===
'+' ) {
364 $varname = substr( $varname, 1 );
365 if ( is_array( $value ) && is_array( $GLOBALS[$varname] ) ) {
366 $value = self::arrayMerge( $value, $GLOBALS[$varname] );
369 if ( $value !==
null ) {
370 $localSettings[$varname] = $value;
374 $replacements = $params[
'replacements'];
375 if ( array_key_exists(
'@replaceableSettings', $this->settings ) ) {
376 foreach ( $this->settings[
'@replaceableSettings'] as $varname ) {
377 if ( array_key_exists( $varname, $localSettings ) ) {
378 $this->doReplacements( $localSettings[$varname], $replacements );
382 foreach ( $localSettings as &$value ) {
383 $this->doReplacements( $value, $replacements );
386 return $localSettings;
398 public function getBool( $setting, $wiki, $site =
null, $wikiTags = [] ) {
399 if ( !is_string( $setting ) ) {
400 wfDeprecated( __METHOD__ .
' with non-string $setting',
'1.44' );
401 $setting = (string)$setting;
403 if ( $wiki ===
null ) {
404 wfDeprecated( __METHOD__ .
' with null $wiki',
'1.44' );
406 if ( !is_string( $wiki ) ) {
407 wfDeprecated( __METHOD__ .
' with non-string $wiki',
'1.44' );
409 $wiki = (string)$wiki;
410 if ( $site !==
null && !is_string( $site ) ) {
411 wfDeprecated( __METHOD__ .
' with non-string $site',
'1.44' );
412 $site = (string)$site;
414 if ( !is_array( $wikiTags ) ) {
415 wfDeprecated( __METHOD__ .
' with non-array $wikiTags',
'1.44' );
416 $wikiTags = (array)$wikiTags;
418 return (
bool)$this->
get( $setting, $wiki, $site, [], $wikiTags );
436 if ( !is_string( $setting ) ) {
437 wfDeprecated( __METHOD__ .
' with non-string $setting',
'1.44' );
438 $setting = (string)$setting;
440 if ( $wiki ===
null ) {
441 wfDeprecated( __METHOD__ .
' with null $wiki',
'1.44' );
443 if ( !is_string( $wiki ) ) {
444 wfDeprecated( __METHOD__ .
' with non-string $wiki',
'1.44' );
446 $wiki = (string)$wiki;
447 if ( !is_array( $params ) ) {
448 wfDeprecated( __METHOD__ .
' with non-array $params',
'1.44' );
449 $params = (array)$params;
451 $overrides = $this->settings[$setting] ??
null;
452 $value = $overrides ? $this->processSetting( $overrides, $wiki, $params[
'tags'] ) :
null;
453 if ( !array_key_exists(
'@replaceableSettings', $this->settings )
454 || in_array( $setting, $this->settings[
'@replaceableSettings'] )
456 $this->doReplacements( $value, $params[
'replacements'] );
458 if ( $value !==
null ) {
459 if ( substr( $setting, 0, 1 ) ==
'+' && is_array( $value ) ) {
460 $setting = substr( $setting, 1 );
461 if ( is_array( $GLOBALS[$setting] ) ) {
462 $GLOBALS[$setting] = self::arrayMerge( $GLOBALS[$setting], $value );
464 $GLOBALS[$setting] = $value;
467 $GLOBALS[$setting] = $value;
485 if ( $wiki ===
null ) {
486 wfDeprecated( __METHOD__ .
' with null $wiki',
'1.44' );
488 if ( !is_string( $wiki ) ) {
489 wfDeprecated( __METHOD__ .
' with non-string $wiki',
'1.44' );
491 $wiki = (string)$wiki;
492 if ( $site !==
null && !is_string( $site ) ) {
493 wfDeprecated( __METHOD__ .
' with non-string $site',
'1.44' );
494 $site = (string)$site;
496 if ( !is_array( $params ) ) {
497 wfDeprecated( __METHOD__ .
' with non-array $params',
'1.44' );
498 $params = (array)$params;
500 if ( !is_array( $wikiTags ) ) {
501 wfDeprecated( __METHOD__ .
' with non-array $wikiTags',
'1.44' );
502 $wikiTags = (array)$wikiTags;
504 $params = $this->
mergeParams( $wiki, $site, $params, $wikiTags );
505 foreach ( $this->settings as $varName => $setting ) {
526 if ( !is_callable( $this->siteParamsCallback ) ) {
531 # Validate the returned value
532 if ( !is_array( $ret ) ) {
536 foreach ( $default as $name => $def ) {
537 if ( !isset( $ret[$name] ) || ( is_array( $def ) && !is_array( $ret[$name] ) ) ) {
557 protected function mergeParams( $wiki, $site, array $params, array $wikiTags ) {
560 $ret[
'suffix'] ??= $site;
565 $wikiTags[] = $ret[
'suffix'];
567 $ret[
'tags'] = array_unique( array_merge( $ret[
'tags'], $wikiTags ) );
569 $ret[
'params'] += $params;
573 if ( !isset( $ret[
'params'][
'lang'] ) && $ret[
'lang'] !==
null ) {
574 $ret[
'params'][
'lang'] = $ret[
'lang'];
576 if ( !isset( $ret[
'params'][
'site'] ) && $ret[
'suffix'] !==
null ) {
577 $ret[
'params'][
'site'] = $ret[
'suffix'];
582 $ret[
'replacements'] = [];
584 foreach ( $ret[
'params'] as $key => $value ) {
585 $ret[
'replacements'][
'$' . $key] = $value;
598 if ( $wiki ===
null ) {
599 wfDeprecated( __METHOD__ .
' with null $wiki',
'1.44' );
601 if ( !is_string( $wiki ) ) {
602 wfDeprecated( __METHOD__ .
' with non-string $wiki',
'1.44' );
604 $wiki = (string)$wiki;
607 if ( $def[
'suffix'] !==
null && $def[
'lang'] !==
null ) {
608 return [ $def[
'suffix'], $def[
'lang'] ];
611 $languageCode = str_replace(
'_',
'-', $wiki );
612 foreach ( $this->suffixes as $altSite => $suffix ) {
613 if ( $suffix ===
'' ) {
614 return [
'', $languageCode ];
615 } elseif ( str_ends_with( $wiki, $suffix ) ) {
616 $site = is_string( $altSite ) ? $altSite : $suffix;
617 $languageCode = substr( $languageCode, 0, -strlen( $suffix ) );
618 return [ $site, $languageCode ];
622 return [
null, null ];
635 private static function arrayMerge( array $array1, array $array2 ) {
637 foreach ( $array2 as $key => $value ) {
638 if ( isset( $out[$key] ) ) {
639 if ( is_array( $out[$key] ) && is_array( $value ) ) {
641 $out[$key] = self::arrayMerge( $out[$key], $value );
642 } elseif ( is_numeric( $key ) ) {
650 } elseif ( $out[$key] ===
false ) {
668 if ( $this->fullLoadCallback && !$this->fullLoadDone ) {
670 $this->fullLoadDone =
true;
676class_alias( SiteConfiguration::class,
'SiteConfiguration' );
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.