197 $params = $this->
mergeParams( $wiki, $site, $params, $wikiTags );
198 $overrides = $this->settings[$settingName] ??
null;
199 $value = $overrides ? $this->processSetting( $overrides, $wiki, $params[
'tags'] ) :
null;
200 if ( !array_key_exists(
'@replaceableSettings', $this->settings )
201 || in_array( $settingName, $this->settings[
'@replaceableSettings'] )
203 $this->doReplacements( $value, $params[
'replacements'] );
239 private function processSetting( $thisSetting, $wiki, $tags ) {
245 if ( array_key_exists( $wiki, $thisSetting ) ) {
247 $retval = $thisSetting[$wiki];
249 if ( array_key_exists(
"+$wiki", $thisSetting ) ) {
252 $retval = $thisSetting[
"+$wiki"];
255 foreach ( $tags as $tag ) {
256 if ( array_key_exists( $tag, $thisSetting ) ) {
257 if ( is_array( $retval ) && is_array( $thisSetting[$tag] ) ) {
260 $retval = self::arrayMerge( $retval, $thisSetting[$tag] );
265 $retval = $thisSetting[$tag];
268 } elseif ( array_key_exists(
"+$tag", $thisSetting ) ) {
272 $retval = self::arrayMerge( $retval ?? [], $thisSetting[
"+$tag"] );
276 if ( array_key_exists(
'default', $thisSetting ) ) {
277 if ( is_array( $retval ) && is_array( $thisSetting[
'default'] ) ) {
280 $retval = self::arrayMerge( $retval, $thisSetting[
'default'] );
286 $retval = $thisSetting[
'default'];
299 private function doReplacements( &$value, $replacements ) {
303 if ( is_string( $value ) ) {
304 $value = strtr( $value, $replacements );
305 } elseif ( is_array( $value ) ) {
306 foreach ( $value as &$val ) {
307 if ( is_string( $val ) ) {
308 $val = strtr( $val, $replacements );
322 public function getAll( $wiki, $site =
null, $params = [], $wikiTags = [] ) {
323 $params = $this->
mergeParams( $wiki, $site, $params, $wikiTags );
324 $tags = $params[
'tags'];
326 foreach ( $this->settings as $varname => $overrides ) {
327 $value = $this->processSetting( $overrides, $wiki, $tags );
328 if ( $varname[0] ===
'+' ) {
329 $varname = substr( $varname, 1 );
330 if ( is_array( $value ) && is_array( $GLOBALS[$varname] ) ) {
331 $value = self::arrayMerge( $value, $GLOBALS[$varname] );
334 if ( $value !==
null ) {
335 $localSettings[$varname] = $value;
339 $replacements = $params[
'replacements'];
340 if ( array_key_exists(
'@replaceableSettings', $this->settings ) ) {
341 foreach ( $this->settings[
'@replaceableSettings'] as $varname ) {
342 if ( array_key_exists( $varname, $localSettings ) ) {
343 $this->doReplacements( $localSettings[$varname], $replacements );
347 foreach ( $localSettings as &$value ) {
348 $this->doReplacements( $value, $replacements );
351 return $localSettings;
363 public function getBool( $setting, $wiki, $site =
null, $wikiTags = [] ) {
364 return (
bool)$this->
get( $setting, $wiki, $site, [], $wikiTags );
396 $value = $this->
get( $setting, $wiki, $site, $params, $wikiTags );
397 if ( $value !==
null ) {
420 $params = $this->
mergeParams( $wiki, $site, $params, $wikiTags );
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 $params = $this->
mergeParams( $wiki, $site, $params, $wikiTags );
465 foreach ( $this->settings as $varName => $setting ) {
486 if ( !is_callable( $this->siteParamsCallback ) ) {
491 # Validate the returned value
492 if ( !is_array( $ret ) ) {
496 foreach ( $default as $name => $def ) {
497 if ( !isset( $ret[$name] ) || ( is_array( $def ) && !is_array( $ret[$name] ) ) ) {
517 protected function mergeParams( $wiki, $site, array $params, array $wikiTags ) {
520 $ret[
'suffix'] ??= $site;
525 $wikiTags[] = $ret[
'suffix'];
527 $ret[
'tags'] = array_unique( array_merge( $ret[
'tags'], $wikiTags ) );
529 $ret[
'params'] += $params;
533 if ( !isset( $ret[
'params'][
'lang'] ) && $ret[
'lang'] !==
null ) {
534 $ret[
'params'][
'lang'] = $ret[
'lang'];
536 if ( !isset( $ret[
'params'][
'site'] ) && $ret[
'suffix'] !==
null ) {
537 $ret[
'params'][
'site'] = $ret[
'suffix'];
542 $ret[
'replacements'] = [];
544 foreach ( $ret[
'params'] as $key => $value ) {
545 $ret[
'replacements'][
'$' . $key] = $value;
560 if ( $def[
'suffix'] !==
null && $def[
'lang'] !==
null ) {
561 return [ $def[
'suffix'], $def[
'lang'] ];
564 $languageCode = str_replace(
'_',
'-', $wiki );
565 foreach ( $this->suffixes as $altSite => $suffix ) {
566 if ( $suffix ===
'' ) {
567 return [
'', $languageCode ];
568 } elseif ( str_ends_with( $wiki, $suffix ) ) {
569 $site = is_string( $altSite ) ? $altSite : $suffix;
570 $languageCode = substr( $languageCode, 0, -strlen( $suffix ) );
571 return [ $site, $languageCode ];
575 return [
null, null ];
597 if ( !preg_match(
'/^wg[A-Z]/', $name ) ) {
599 } elseif ( !isset( $GLOBALS[$name] ) ) {
602 $res[$name] = $GLOBALS[$name];
605 if ( isset( $this->cfgCache[$wiki] ) ) {
606 $res = array_intersect_key(
607 $this->cfgCache[$wiki],
610 if ( count( $res ) == count(
$settings ) ) {
611 return $multi ? $res : current( $res );
613 } elseif ( !in_array( $wiki, $this->wikis ) ) {
616 $this->cfgCache[$wiki] = [];
627 ->limits( [
'memory' => 0,
'filesize' => 0 ] )
630 $data = trim( $result->getStdout() );
631 if ( $result->getExitCode() || $data ===
'' ) {
632 throw new RuntimeException(
"Failed to run getConfiguration.php: {$result->getStderr()}" );
634 $res = unserialize( $data );
635 if ( !is_array( $res ) ) {
636 throw new RuntimeException(
"Failed to unserialize configuration array." );
638 $this->cfgCache[$wiki] += $res;
641 return $multi ? $res : current( $res );
654 private static function arrayMerge( array $array1, array $array2 ) {
656 foreach ( $array2 as $key => $value ) {
657 if ( isset( $out[$key] ) ) {
658 if ( is_array( $out[$key] ) && is_array( $value ) ) {
660 $out[$key] = self::arrayMerge( $out[$key], $value );
661 } elseif ( is_numeric( $key ) ) {
669 } elseif ( $out[$key] ===
false ) {
687 if ( $this->fullLoadCallback && !$this->fullLoadDone ) {
689 $this->fullLoadDone =
true;
697 class_alias( SiteConfiguration::class,
'SiteConfiguration' );
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.