191 $overrides = $this->settings[$settingName] ??
null;
192 $value = $overrides ? $this->processSetting( $overrides, $wiki,
$params[
'tags'] ) :
null;
193 if ( !array_key_exists(
'@replaceableSettings', $this->settings )
194 || in_array( $settingName, $this->settings[
'@replaceableSettings'] )
196 $this->doReplacements( $value,
$params[
'replacements'] );
232 private function processSetting( $thisSetting, $wiki, $tags ) {
238 if ( array_key_exists( $wiki, $thisSetting ) ) {
240 $retval = $thisSetting[$wiki];
242 if ( array_key_exists(
"+$wiki", $thisSetting ) ) {
245 $retval = $thisSetting[
"+$wiki"];
248 foreach ( $tags as $tag ) {
249 if ( array_key_exists( $tag, $thisSetting ) ) {
250 if ( is_array( $retval ) && is_array( $thisSetting[$tag] ) ) {
253 $retval = self::arrayMerge( $retval, $thisSetting[$tag] );
258 $retval = $thisSetting[$tag];
261 } elseif ( array_key_exists(
"+$tag", $thisSetting ) ) {
265 $retval = self::arrayMerge( $retval ?? [], $thisSetting[
"+$tag"] );
269 if ( array_key_exists(
'default', $thisSetting ) ) {
270 if ( is_array( $retval ) && is_array( $thisSetting[
'default'] ) ) {
273 $retval = self::arrayMerge( $retval, $thisSetting[
'default'] );
279 $retval = $thisSetting[
'default'];
292 private function doReplacements( &$value, $replacements ) {
296 if ( is_string( $value ) ) {
297 $value = strtr( $value, $replacements );
298 } elseif ( is_array( $value ) ) {
299 foreach ( $value as &$val ) {
300 if ( is_string( $val ) ) {
301 $val = strtr( $val, $replacements );
315 public function getAll( $wiki, $site =
null,
$params = [], $wikiTags = [] ) {
319 foreach ( $this->settings as $varname => $overrides ) {
320 $value = $this->processSetting( $overrides, $wiki, $tags );
321 if ( $varname[0] ===
'+' ) {
322 $varname = substr( $varname, 1 );
323 if ( is_array( $value ) && is_array( $GLOBALS[$varname] ) ) {
324 $value = self::arrayMerge( $value, $GLOBALS[$varname] );
327 if ( $value !==
null ) {
328 $localSettings[$varname] = $value;
332 $replacements =
$params[
'replacements'];
333 if ( array_key_exists(
'@replaceableSettings', $this->settings ) ) {
334 foreach ( $this->settings[
'@replaceableSettings'] as $varname ) {
335 if ( array_key_exists( $varname, $localSettings ) ) {
336 $this->doReplacements( $localSettings[$varname], $replacements );
340 foreach ( $localSettings as &$value ) {
341 $this->doReplacements( $value, $replacements );
344 return $localSettings;
356 public function getBool( $setting, $wiki, $site =
null, $wikiTags = [] ) {
357 return (
bool)$this->
get( $setting, $wiki, $site, [], $wikiTags );
375 $overrides = $this->settings[$setting] ??
null;
376 $value = $overrides ? $this->processSetting( $overrides, $wiki,
$params[
'tags'] ) :
null;
377 if ( !array_key_exists(
'@replaceableSettings', $this->settings )
378 || in_array( $setting, $this->settings[
'@replaceableSettings'] )
380 $this->doReplacements( $value,
$params[
'replacements'] );
382 if ( $value !==
null ) {
383 if ( substr( $setting, 0, 1 ) ==
'+' && is_array( $value ) ) {
384 $setting = substr( $setting, 1 );
385 if ( is_array( $GLOBALS[$setting] ) ) {
386 $GLOBALS[$setting] = self::arrayMerge( $GLOBALS[$setting], $value );
388 $GLOBALS[$setting] = $value;
391 $GLOBALS[$setting] = $value;
410 foreach ( $this->settings as $varName => $setting ) {
431 if ( !is_callable( $this->siteParamsCallback ) ) {
436 # Validate the returned value
437 if ( !is_array( $ret ) ) {
441 foreach ( $default as $name => $def ) {
442 if ( !isset( $ret[$name] ) || ( is_array( $def ) && !is_array( $ret[$name] ) ) ) {
465 $ret[
'suffix'] ??= $site;
470 $wikiTags[] = $ret[
'suffix'];
472 $ret[
'tags'] = array_unique( array_merge( $ret[
'tags'], $wikiTags ) );
478 if ( !isset( $ret[
'params'][
'lang'] ) && $ret[
'lang'] !==
null ) {
479 $ret[
'params'][
'lang'] = $ret[
'lang'];
481 if ( !isset( $ret[
'params'][
'site'] ) && $ret[
'suffix'] !==
null ) {
482 $ret[
'params'][
'site'] = $ret[
'suffix'];
487 $ret[
'replacements'] = [];
489 foreach ( $ret[
'params'] as $key => $value ) {
490 $ret[
'replacements'][
'$' . $key] = $value;
505 if ( $def[
'suffix'] !==
null && $def[
'lang'] !==
null ) {
506 return [ $def[
'suffix'], $def[
'lang'] ];
509 $languageCode = str_replace(
'_',
'-', $wiki );
510 foreach ( $this->suffixes as $altSite => $suffix ) {
511 if ( $suffix ===
'' ) {
512 return [
'', $languageCode ];
513 } elseif ( str_ends_with( $wiki, $suffix ) ) {
514 $site = is_string( $altSite ) ? $altSite : $suffix;
515 $languageCode = substr( $languageCode, 0, -strlen( $suffix ) );
516 return [ $site, $languageCode ];
520 return [
null, null ];
533 private static function arrayMerge( array $array1, array $array2 ) {
535 foreach ( $array2 as $key => $value ) {
536 if ( isset( $out[$key] ) ) {
537 if ( is_array( $out[$key] ) && is_array( $value ) ) {
539 $out[$key] = self::arrayMerge( $out[$key], $value );
540 } elseif ( is_numeric( $key ) ) {
548 } elseif ( $out[$key] ===
false ) {
566 if ( $this->fullLoadCallback && !$this->fullLoadDone ) {
568 $this->fullLoadDone =
true;