194 $overrides = $this->settings[$settingName] ??
null;
195 $value = $overrides ? $this->processSetting( $overrides, $wiki,
$params[
'tags'] ) :
null;
196 if ( !array_key_exists(
'@replaceableSettings', $this->settings )
197 || in_array( $settingName, $this->settings[
'@replaceableSettings'] )
199 $this->doReplacements( $value,
$params[
'replacements'] );
235 private function processSetting( $thisSetting, $wiki, $tags ) {
241 if ( array_key_exists( $wiki, $thisSetting ) ) {
243 $retval = $thisSetting[$wiki];
245 if ( array_key_exists(
"+$wiki", $thisSetting ) ) {
248 $retval = $thisSetting[
"+$wiki"];
251 foreach ( $tags as $tag ) {
252 if ( array_key_exists( $tag, $thisSetting ) ) {
253 if ( is_array( $retval ) && is_array( $thisSetting[$tag] ) ) {
256 $retval = self::arrayMerge( $retval, $thisSetting[$tag] );
261 $retval = $thisSetting[$tag];
264 } elseif ( array_key_exists(
"+$tag", $thisSetting ) ) {
268 $retval = self::arrayMerge( $retval ?? [], $thisSetting[
"+$tag"] );
272 if ( array_key_exists(
'default', $thisSetting ) ) {
273 if ( is_array( $retval ) && is_array( $thisSetting[
'default'] ) ) {
276 $retval = self::arrayMerge( $retval, $thisSetting[
'default'] );
282 $retval = $thisSetting[
'default'];
295 private function doReplacements( &$value, $replacements ) {
299 if ( is_string( $value ) ) {
300 $value = strtr( $value, $replacements );
301 } elseif ( is_array( $value ) ) {
302 foreach ( $value as &$val ) {
303 if ( is_string( $val ) ) {
304 $val = strtr( $val, $replacements );
318 public function getAll( $wiki, $site =
null,
$params = [], $wikiTags = [] ) {
322 foreach ( $this->settings as $varname => $overrides ) {
323 $value = $this->processSetting( $overrides, $wiki, $tags );
324 if ( $varname[0] ===
'+' ) {
325 $varname = substr( $varname, 1 );
326 if ( is_array( $value ) && is_array( $GLOBALS[$varname] ) ) {
327 $value = self::arrayMerge( $value, $GLOBALS[$varname] );
330 if ( $value !==
null ) {
331 $localSettings[$varname] = $value;
335 $replacements =
$params[
'replacements'];
336 if ( array_key_exists(
'@replaceableSettings', $this->settings ) ) {
337 foreach ( $this->settings[
'@replaceableSettings'] as $varname ) {
338 if ( array_key_exists( $varname, $localSettings ) ) {
339 $this->doReplacements( $localSettings[$varname], $replacements );
343 foreach ( $localSettings as &$value ) {
344 $this->doReplacements( $value, $replacements );
347 return $localSettings;
359 public function getBool( $setting, $wiki, $site =
null, $wikiTags = [] ) {
360 return (
bool)$this->
get( $setting, $wiki, $site, [], $wikiTags );
392 $value = $this->
get( $setting, $wiki, $site,
$params, $wikiTags );
393 if ( $value !==
null ) {
426 $overrides = $this->settings[$setting] ??
null;
427 $value = $overrides ? $this->processSetting( $overrides, $wiki,
$params[
'tags'] ) :
null;
428 if ( !array_key_exists(
'@replaceableSettings', $this->settings )
429 || in_array( $setting, $this->settings[
'@replaceableSettings'] )
431 $this->doReplacements( $value,
$params[
'replacements'] );
433 if ( $value !==
null ) {
434 if ( substr( $setting, 0, 1 ) ==
'+' && is_array( $value ) ) {
435 $setting = substr( $setting, 1 );
436 if ( is_array( $GLOBALS[$setting] ) ) {
437 $GLOBALS[$setting] = self::arrayMerge( $GLOBALS[$setting], $value );
439 $GLOBALS[$setting] = $value;
442 $GLOBALS[$setting] = $value;
461 foreach ( $this->settings as $varName => $setting ) {
482 if ( !is_callable( $this->siteParamsCallback ) ) {
487 # Validate the returned value
488 if ( !is_array( $ret ) ) {
492 foreach ( $default as $name => $def ) {
493 if ( !isset( $ret[$name] ) || ( is_array( $def ) && !is_array( $ret[$name] ) ) ) {
516 $ret[
'suffix'] ??= $site;
521 $wikiTags[] = $ret[
'suffix'];
523 $ret[
'tags'] = array_unique( array_merge( $ret[
'tags'], $wikiTags ) );
529 if ( !isset( $ret[
'params'][
'lang'] ) && $ret[
'lang'] !==
null ) {
530 $ret[
'params'][
'lang'] = $ret[
'lang'];
532 if ( !isset( $ret[
'params'][
'site'] ) && $ret[
'suffix'] !==
null ) {
533 $ret[
'params'][
'site'] = $ret[
'suffix'];
538 $ret[
'replacements'] = [];
540 foreach ( $ret[
'params'] as $key => $value ) {
541 $ret[
'replacements'][
'$' . $key] = $value;
556 if ( $def[
'suffix'] !==
null && $def[
'lang'] !==
null ) {
557 return [ $def[
'suffix'], $def[
'lang'] ];
560 $languageCode = str_replace(
'_',
'-', $wiki );
561 foreach ( $this->suffixes as $altSite => $suffix ) {
562 if ( $suffix ===
'' ) {
563 return [
'', $languageCode ];
564 } elseif ( str_ends_with( $wiki, $suffix ) ) {
565 $site = is_string( $altSite ) ? $altSite : $suffix;
566 $languageCode = substr( $languageCode, 0, -strlen( $suffix ) );
567 return [ $site, $languageCode ];
571 return [
null, null ];
584 private static function arrayMerge( array $array1, array $array2 ) {
586 foreach ( $array2 as $key => $value ) {
587 if ( isset( $out[$key] ) ) {
588 if ( is_array( $out[$key] ) && is_array( $value ) ) {
590 $out[$key] = self::arrayMerge( $out[$key], $value );
591 } elseif ( is_numeric( $key ) ) {
599 } elseif ( $out[$key] ===
false ) {
617 if ( $this->fullLoadCallback && !$this->fullLoadDone ) {
619 $this->fullLoadDone =
true;
625class_alias( SiteConfiguration::class,
'SiteConfiguration' );
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
array $params
The job parameters.