188 $overrides = $this->settings[$settingName] ??
null;
189 $value = $overrides ? $this->processSetting( $overrides, $wiki,
$params[
'tags'] ) :
null;
190 if ( !array_key_exists(
'@replaceableSettings', $this->settings )
191 || in_array( $settingName, $this->settings[
'@replaceableSettings'] )
193 $this->doReplacements( $value,
$params[
'replacements'] );
229 private function processSetting( $thisSetting, $wiki, $tags ) {
235 if ( array_key_exists( $wiki, $thisSetting ) ) {
237 $retval = $thisSetting[$wiki];
239 if ( array_key_exists(
"+$wiki", $thisSetting ) ) {
242 $retval = $thisSetting[
"+$wiki"];
245 foreach ( $tags as $tag ) {
246 if ( array_key_exists( $tag, $thisSetting ) ) {
247 if ( is_array( $retval ) && is_array( $thisSetting[$tag] ) ) {
250 $retval = self::arrayMerge( $retval, $thisSetting[$tag] );
255 $retval = $thisSetting[$tag];
258 } elseif ( array_key_exists(
"+$tag", $thisSetting ) ) {
262 $retval = self::arrayMerge( $retval ?? [], $thisSetting[
"+$tag"] );
266 if ( array_key_exists(
'default', $thisSetting ) ) {
267 if ( is_array( $retval ) && is_array( $thisSetting[
'default'] ) ) {
270 $retval = self::arrayMerge( $retval, $thisSetting[
'default'] );
276 $retval = $thisSetting[
'default'];
289 private function doReplacements( &$value, $replacements ) {
293 if ( is_string( $value ) ) {
294 $value = strtr( $value, $replacements );
295 } elseif ( is_array( $value ) ) {
296 foreach ( $value as &$val ) {
297 if ( is_string( $val ) ) {
298 $val = strtr( $val, $replacements );
312 public function getAll( $wiki, $site =
null,
$params = [], $wikiTags = [] ) {
316 foreach ( $this->settings as $varname => $overrides ) {
317 $value = $this->processSetting( $overrides, $wiki, $tags );
318 if ( $varname[0] ===
'+' ) {
319 $varname = substr( $varname, 1 );
320 if ( is_array( $value ) && is_array( $GLOBALS[$varname] ) ) {
321 $value = self::arrayMerge( $value, $GLOBALS[$varname] );
324 if ( $value !==
null ) {
325 $localSettings[$varname] = $value;
329 $replacements =
$params[
'replacements'];
330 if ( array_key_exists(
'@replaceableSettings', $this->settings ) ) {
331 foreach ( $this->settings[
'@replaceableSettings'] as $varname ) {
332 if ( array_key_exists( $varname, $localSettings ) ) {
333 $this->doReplacements( $localSettings[$varname], $replacements );
337 foreach ( $localSettings as &$value ) {
338 $this->doReplacements( $value, $replacements );
341 return $localSettings;
353 public function getBool( $setting, $wiki, $site =
null, $wikiTags = [] ) {
354 return (
bool)$this->
get( $setting, $wiki, $site, [], $wikiTags );
372 $overrides = $this->settings[$setting] ??
null;
373 $value = $overrides ? $this->processSetting( $overrides, $wiki,
$params[
'tags'] ) :
null;
374 if ( !array_key_exists(
'@replaceableSettings', $this->settings )
375 || in_array( $setting, $this->settings[
'@replaceableSettings'] )
377 $this->doReplacements( $value,
$params[
'replacements'] );
379 if ( $value !==
null ) {
380 if ( substr( $setting, 0, 1 ) ==
'+' && is_array( $value ) ) {
381 $setting = substr( $setting, 1 );
382 if ( is_array( $GLOBALS[$setting] ) ) {
383 $GLOBALS[$setting] = self::arrayMerge( $GLOBALS[$setting], $value );
385 $GLOBALS[$setting] = $value;
388 $GLOBALS[$setting] = $value;
407 foreach ( $this->settings as $varName => $setting ) {
428 if ( !is_callable( $this->siteParamsCallback ) ) {
433 # Validate the returned value
434 if ( !is_array( $ret ) ) {
438 foreach ( $default as $name => $def ) {
439 if ( !isset( $ret[$name] ) || ( is_array( $def ) && !is_array( $ret[$name] ) ) ) {
462 $ret[
'suffix'] ??= $site;
467 $wikiTags[] = $ret[
'suffix'];
469 $ret[
'tags'] = array_unique( array_merge( $ret[
'tags'], $wikiTags ) );
475 if ( !isset( $ret[
'params'][
'lang'] ) && $ret[
'lang'] !==
null ) {
476 $ret[
'params'][
'lang'] = $ret[
'lang'];
478 if ( !isset( $ret[
'params'][
'site'] ) && $ret[
'suffix'] !==
null ) {
479 $ret[
'params'][
'site'] = $ret[
'suffix'];
484 $ret[
'replacements'] = [];
486 foreach ( $ret[
'params'] as $key => $value ) {
487 $ret[
'replacements'][
'$' . $key] = $value;
502 if ( $def[
'suffix'] !==
null && $def[
'lang'] !==
null ) {
503 return [ $def[
'suffix'], $def[
'lang'] ];
506 $languageCode = str_replace(
'_',
'-', $wiki );
507 foreach ( $this->suffixes as $altSite => $suffix ) {
508 if ( $suffix ===
'' ) {
509 return [
'', $languageCode ];
510 } elseif ( str_ends_with( $wiki, $suffix ) ) {
511 $site = is_string( $altSite ) ? $altSite : $suffix;
512 $languageCode = substr( $languageCode, 0, -strlen( $suffix ) );
513 return [ $site, $languageCode ];
517 return [
null, null ];
530 private static function arrayMerge( array $array1, array $array2 ) {
532 foreach ( $array2 as $key => $value ) {
533 if ( isset( $out[$key] ) ) {
534 if ( is_array( $out[$key] ) && is_array( $value ) ) {
536 $out[$key] = self::arrayMerge( $out[$key], $value );
537 } elseif ( is_numeric( $key ) ) {
545 } elseif ( $out[$key] ===
false ) {
563 if ( $this->fullLoadCallback && !$this->fullLoadDone ) {
565 $this->fullLoadDone =
true;