176 if ( !is_string( $settingName ) ) {
177 wfDeprecated( __METHOD__ .
' with non-string $settingName',
'1.44' );
178 $settingName = (string)$settingName;
180 if ( $wiki ===
null ) {
181 wfDeprecated( __METHOD__ .
' with null $wiki',
'1.44' );
183 if ( !is_string( $wiki ) ) {
184 wfDeprecated( __METHOD__ .
' with non-string $wiki',
'1.44' );
186 $wiki = (string)$wiki;
187 if ( $site !==
null && !is_string( $site ) ) {
188 wfDeprecated( __METHOD__ .
' with non-string $site',
'1.44' );
189 $site = (string)$site;
191 if ( !is_array( $params ) ) {
192 wfDeprecated( __METHOD__ .
' with non-array $params',
'1.44' );
193 $params = (array)$params;
195 if ( !is_array( $wikiTags ) ) {
196 wfDeprecated( __METHOD__ .
' with non-array $wikiTags',
'1.44' );
197 $wikiTags = (array)$wikiTags;
199 $params = $this->
mergeParams( $wiki, $site, $params, $wikiTags );
200 $overrides = $this->settings[$settingName] ??
null;
201 $value = $overrides ? $this->processSetting( $overrides, $wiki, $params[
'tags'] ) :
null;
202 if ( !array_key_exists(
'@replaceableSettings', $this->settings )
203 || in_array( $settingName, $this->settings[
'@replaceableSettings'] )
205 $this->doReplacements( $value, $params[
'replacements'] );
241 private function processSetting( $thisSetting, $wiki, $tags ) {
247 if ( array_key_exists( $wiki, $thisSetting ) ) {
249 $retval = $thisSetting[$wiki];
251 if ( array_key_exists(
"+$wiki", $thisSetting ) ) {
254 $retval = $thisSetting[
"+$wiki"];
257 foreach ( $tags as $tag ) {
258 if ( array_key_exists( $tag, $thisSetting ) ) {
259 if ( is_array( $retval ) && is_array( $thisSetting[$tag] ) ) {
262 $retval = self::arrayMerge( $retval, $thisSetting[$tag] );
267 $retval = $thisSetting[$tag];
270 } elseif ( array_key_exists(
"+$tag", $thisSetting ) ) {
274 $retval = self::arrayMerge( $retval ?? [], $thisSetting[
"+$tag"] );
278 if ( array_key_exists(
'default', $thisSetting ) ) {
279 if ( is_array( $retval ) && is_array( $thisSetting[
'default'] ) ) {
282 $retval = self::arrayMerge( $retval, $thisSetting[
'default'] );
288 $retval = $thisSetting[
'default'];
301 private function doReplacements( &$value, $replacements ) {
305 if ( is_string( $value ) ) {
306 $value = strtr( $value, $replacements );
307 } elseif ( is_array( $value ) ) {
308 foreach ( $value as &$val ) {
309 if ( is_string( $val ) ) {
310 $val = strtr( $val, $replacements );
324 public function getAll( $wiki, $site =
null, $params = [], $wikiTags = [] ) {
325 if ( $wiki ===
null ) {
326 wfDeprecated( __METHOD__ .
' with null $wiki',
'1.44' );
328 if ( !is_string( $wiki ) ) {
329 wfDeprecated( __METHOD__ .
' with non-string $wiki',
'1.44' );
331 $wiki = (string)$wiki;
332 if ( $site !==
null && !is_string( $site ) ) {
333 wfDeprecated( __METHOD__ .
' with non-string $site',
'1.44' );
334 $site = (string)$site;
336 if ( !is_array( $params ) ) {
337 wfDeprecated( __METHOD__ .
' with non-array $params',
'1.44' );
338 $params = (array)$params;
340 if ( !is_array( $wikiTags ) ) {
341 wfDeprecated( __METHOD__ .
' with non-array $wikiTags',
'1.44' );
342 $wikiTags = (array)$wikiTags;
344 $params = $this->
mergeParams( $wiki, $site, $params, $wikiTags );
345 $tags = $params[
'tags'];
347 foreach ( $this->settings as $varname => $overrides ) {
348 $value = $this->processSetting( $overrides, $wiki, $tags );
349 if ( $varname[0] ===
'+' ) {
350 $varname = substr( $varname, 1 );
351 if ( is_array( $value ) && is_array( $GLOBALS[$varname] ) ) {
352 $value = self::arrayMerge( $value, $GLOBALS[$varname] );
355 if ( $value !==
null ) {
356 $localSettings[$varname] = $value;
360 $replacements = $params[
'replacements'];
361 if ( array_key_exists(
'@replaceableSettings', $this->settings ) ) {
362 foreach ( $this->settings[
'@replaceableSettings'] as $varname ) {
363 if ( array_key_exists( $varname, $localSettings ) ) {
364 $this->doReplacements( $localSettings[$varname], $replacements );
368 foreach ( $localSettings as &$value ) {
369 $this->doReplacements( $value, $replacements );
372 return $localSettings;
384 public function getBool( $setting, $wiki, $site =
null, $wikiTags = [] ) {
385 if ( !is_string( $setting ) ) {
386 wfDeprecated( __METHOD__ .
' with non-string $setting',
'1.44' );
387 $setting = (string)$setting;
389 if ( $wiki ===
null ) {
390 wfDeprecated( __METHOD__ .
' with null $wiki',
'1.44' );
392 if ( !is_string( $wiki ) ) {
393 wfDeprecated( __METHOD__ .
' with non-string $wiki',
'1.44' );
395 $wiki = (string)$wiki;
396 if ( $site !==
null && !is_string( $site ) ) {
397 wfDeprecated( __METHOD__ .
' with non-string $site',
'1.44' );
398 $site = (string)$site;
400 if ( !is_array( $wikiTags ) ) {
401 wfDeprecated( __METHOD__ .
' with non-array $wikiTags',
'1.44' );
402 $wikiTags = (array)$wikiTags;
404 return (
bool)$this->
get( $setting, $wiki, $site, [], $wikiTags );
421 private function extractGlobalSetting( $setting, $wiki, $params ) {
422 $overrides = $this->settings[$setting] ??
null;
423 $value = $overrides ? $this->processSetting( $overrides, $wiki, $params[
'tags'] ) : null;
424 if ( !array_key_exists(
'@replaceableSettings', $this->settings )
425 || in_array( $setting, $this->settings[
'@replaceableSettings'] )
427 $this->doReplacements( $value, $params[
'replacements'] );
429 if ( $value !==
null ) {
430 if ( substr( $setting, 0, 1 ) ==
'+' && is_array( $value ) ) {
431 $setting = substr( $setting, 1 );
432 if ( is_array( $GLOBALS[$setting] ) ) {
433 $GLOBALS[$setting] = self::arrayMerge( $GLOBALS[$setting], $value );
435 $GLOBALS[$setting] = $value;
438 $GLOBALS[$setting] = $value;
456 if ( $wiki ===
null ) {
457 wfDeprecated( __METHOD__ .
' with null $wiki',
'1.44' );
459 if ( !is_string( $wiki ) ) {
460 wfDeprecated( __METHOD__ .
' with non-string $wiki',
'1.44' );
462 $wiki = (string)$wiki;
463 if ( $site !==
null && !is_string( $site ) ) {
464 wfDeprecated( __METHOD__ .
' with non-string $site',
'1.44' );
465 $site = (string)$site;
467 if ( !is_array( $params ) ) {
468 wfDeprecated( __METHOD__ .
' with non-array $params',
'1.44' );
469 $params = (array)$params;
471 if ( !is_array( $wikiTags ) ) {
472 wfDeprecated( __METHOD__ .
' with non-array $wikiTags',
'1.44' );
473 $wikiTags = (array)$wikiTags;
475 $params = $this->
mergeParams( $wiki, $site, $params, $wikiTags );
476 foreach ( $this->settings as $setting => $overrides ) {
477 $this->extractGlobalSetting( $setting, $wiki, $params );
497 if ( !is_callable( $this->siteParamsCallback ) ) {
502 # Validate the returned value
503 if ( !is_array( $ret ) ) {
507 foreach ( $default as $name => $def ) {
508 if ( !isset( $ret[$name] ) || ( is_array( $def ) && !is_array( $ret[$name] ) ) ) {
528 protected function mergeParams( $wiki, $site, array $params, array $wikiTags ) {
531 $ret[
'suffix'] ??= $site;
536 $wikiTags[] = $ret[
'suffix'];
538 $ret[
'tags'] = array_unique( array_merge( $ret[
'tags'], $wikiTags ) );
540 $ret[
'params'] += $params;
544 if ( !isset( $ret[
'params'][
'lang'] ) && $ret[
'lang'] !==
null ) {
545 $ret[
'params'][
'lang'] = $ret[
'lang'];
547 if ( !isset( $ret[
'params'][
'site'] ) && $ret[
'suffix'] !==
null ) {
548 $ret[
'params'][
'site'] = $ret[
'suffix'];
553 $ret[
'replacements'] = [];
554 foreach ( $ret[
'params'] as $key => $value ) {
555 $ret[
'replacements'][
'$' . $key] = $value;
568 if ( $wiki ===
null ) {
569 wfDeprecated( __METHOD__ .
' with null $wiki',
'1.44' );
571 if ( !is_string( $wiki ) ) {
572 wfDeprecated( __METHOD__ .
' with non-string $wiki',
'1.44' );
574 $wiki = (string)$wiki;
577 if ( $def[
'suffix'] !==
null && $def[
'lang'] !==
null ) {
578 return [ $def[
'suffix'], $def[
'lang'] ];
581 $languageCode = str_replace(
'_',
'-', $wiki );
582 foreach ( $this->suffixes as $altSite => $suffix ) {
583 if ( $suffix ===
'' ) {
584 return [
'', $languageCode ];
585 } elseif ( str_ends_with( $wiki, $suffix ) ) {
586 $site = is_string( $altSite ) ? $altSite : $suffix;
587 $languageCode = substr( $languageCode, 0, -strlen( $suffix ) );
588 return [ $site, $languageCode ];
592 return [
null, null ];
605 private static function arrayMerge( array $array1, array $array2 ) {
607 foreach ( $array2 as $key => $value ) {
608 if ( isset( $out[$key] ) ) {
609 if ( is_array( $out[$key] ) && is_array( $value ) ) {
611 $out[$key] = self::arrayMerge( $out[$key], $value );
612 } elseif ( is_numeric( $key ) ) {
620 } elseif ( $out[$key] ===
false ) {
638 if ( $this->fullLoadCallback && !$this->fullLoadDone ) {
640 $this->fullLoadDone =
true;