188 public function get( $settingName, $wiki, $suffix =
null, $params = [],
191 $params = $this->
mergeParams( $wiki, $suffix, $params, $wikiTags );
192 return $this->
getSetting( $settingName, $wiki, $params );
203 protected function getSetting( $settingName, $wiki, array $params ) {
205 if ( array_key_exists( $settingName, $this->settings ) ) {
206 $thisSetting =& $this->settings[$settingName];
209 if ( array_key_exists( $wiki, $thisSetting ) ) {
210 $retval = $thisSetting[$wiki];
212 } elseif ( array_key_exists(
"+$wiki", $thisSetting ) && is_array( $thisSetting[
"+$wiki"] ) ) {
213 $retval = $thisSetting[
"+$wiki"];
217 foreach ( $params[
'tags'] as $tag ) {
218 if ( array_key_exists( $tag, $thisSetting ) ) {
219 if ( is_array( $retval ) && is_array( $thisSetting[$tag] ) ) {
222 $retval = $thisSetting[$tag];
225 } elseif ( array_key_exists(
"+$tag", $thisSetting ) && is_array( $thisSetting[
"+$tag"] ) ) {
226 if ( $retval ===
null ) {
233 $suffix = $params[
'suffix'];
234 if ( !is_null( $suffix ) ) {
235 if ( array_key_exists( $suffix, $thisSetting ) ) {
236 if ( is_array( $retval ) && is_array( $thisSetting[$suffix] ) ) {
239 $retval = $thisSetting[$suffix];
242 } elseif ( array_key_exists(
"+$suffix", $thisSetting )
243 && is_array( $thisSetting[
"+$suffix"] )
245 if ( $retval ===
null ) {
253 if ( array_key_exists(
'default', $thisSetting ) ) {
254 if ( is_array( $retval ) && is_array( $thisSetting[
'default'] ) ) {
257 $retval = $thisSetting[
'default'];
264 if ( !is_null( $retval ) && count( $params[
'params'] ) ) {
265 foreach ( $params[
'params'] as $key => $value ) {
266 $retval = $this->
doReplace(
'$' . $key, $value, $retval );
282 if ( is_string( $in ) ) {
283 return str_replace( $from, $to, $in );
284 } elseif ( is_array( $in ) ) {
285 foreach ( $in as $key => $val ) {
286 $in[$key] = $this->
doReplace( $from, $to, $val );
302 public function getAll( $wiki, $suffix =
null, $params = [], $wikiTags = [] ) {
303 $params = $this->
mergeParams( $wiki, $suffix, $params, $wikiTags );
305 foreach ( $this->settings as $varname => $stuff ) {
308 if ( substr( $varname, 0, 1 ) ==
'+' ) {
310 $var = substr( $varname, 1 );
313 $value = $this->
getSetting( $varname, $wiki, $params );
314 if ( $append && is_array( $value ) && is_array(
$GLOBALS[$var] ) ) {
317 if ( !is_null( $value ) ) {
318 $localSettings[$var] = $value;
321 return $localSettings;
332 public function getBool( $setting, $wiki, $suffix =
null, $wikiTags = [] ) {
333 return (
bool)$this->
get( $setting, $wiki, $suffix, [], $wikiTags );
355 $params = [], $wikiTags = []
357 $value = $this->
get( $setting, $wiki, $suffix, $params, $wikiTags );
358 if ( !is_null( $value ) ) {
372 $params = [], $wikiTags = []
374 $params = $this->
mergeParams( $wiki, $suffix, $params, $wikiTags );
384 $value = $this->
getSetting( $setting, $wiki, $params );
385 if ( !is_null( $value ) ) {
386 if ( substr( $setting, 0, 1 ) ==
'+' && is_array( $value ) ) {
387 $setting = substr( $setting, 1 );
388 if ( is_array(
$GLOBALS[$setting] ) ) {
409 $params = $this->
mergeParams( $wiki, $suffix, $params, $wikiTags );
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( $default[$name] ) && !is_array( $ret[$name] ) ) ) {
443 $ret[$name] = $default[$name];
462 protected function mergeParams( $wiki, $suffix, array $params, array $wikiTags ) {
465 if ( is_null( $ret[
'suffix'] ) ) {
466 $ret[
'suffix'] = $suffix;
469 $ret[
'tags'] = array_unique( array_merge( $ret[
'tags'], $wikiTags ) );
471 $ret[
'params'] += $params;
474 if ( !isset( $ret[
'params'][
'lang'] ) && !is_null( $ret[
'lang'] ) ) {
475 $ret[
'params'][
'lang'] = $ret[
'lang'];
477 if ( !isset( $ret[
'params'][
'site'] ) && !is_null( $ret[
'suffix'] ) ) {
478 $ret[
'params'][
'site'] = $ret[
'suffix'];
493 if ( !is_null( $def[
'suffix'] ) && !is_null( $def[
'lang'] ) ) {
494 return [ $def[
'suffix'], $def[
'lang'] ];
499 foreach ( $this->suffixes as $altSite => $suffix ) {
500 if ( $suffix ===
'' ) {
504 } elseif ( substr( $wiki, -strlen( $suffix ) ) == $suffix ) {
505 $site = is_numeric( $altSite ) ? $suffix : $altSite;
506 $lang = substr( $wiki, 0, strlen( $wiki ) - strlen( $suffix ) );
512 return [ $site,
$lang ];
531 if ( WikiMap::isCurrentWikiId( $wiki ) ) {
534 if ( !preg_match(
'/^wg[A-Z]/', $name ) ) {
535 throw new MWException(
"Variable '$name' does start with 'wg'." );
536 } elseif ( !isset(
$GLOBALS[$name] ) ) {
537 throw new MWException(
"Variable '$name' is not set." );
542 if ( isset( $this->cfgCache[$wiki] ) ) {
543 $res = array_intersect_key( $this->cfgCache[$wiki], array_flip(
$settings ) );
545 return $multi ?
$res : current(
$res );
547 } elseif ( !in_array( $wiki, $this->wikis ) ) {
550 $this->cfgCache[$wiki] = [];
552 $result = Shell::makeScriptCommand(
553 "$IP/maintenance/getConfiguration.php",
561 ->limits( [
'memory' => 0,
'filesize' => 0 ] )
564 $data = trim( $result->getStdout() );
565 if ( $result->getExitCode() || $data ===
'' ) {
566 throw new MWException(
"Failed to run getConfiguration.php: {$result->getStdout()}" );
569 if ( !is_array(
$res ) ) {
570 throw new MWException(
"Failed to unserialize configuration array." );
572 $this->cfgCache[$wiki] = $this->cfgCache[$wiki] +
$res;
575 return $multi ?
$res : current(
$res );
591 foreach ( $arrays as $array ) {
592 foreach ( $array as $key => $value ) {
593 if ( isset( $out[$key] ) && is_array( $out[$key] ) && is_array( $value ) ) {
595 } elseif ( !isset( $out[$key] ) || !$out[$key] && !is_numeric( $key ) ) {
599 } elseif ( is_numeric( $key ) ) {
609 if ( $this->fullLoadCallback && !$this->fullLoadDone ) {
611 $this->fullLoadDone =
true;
unserialize( $serialized)
This is a class for holding configuration settings, particularly for multi-wiki sites.
getConfig( $wiki, $settings)
Get the resolved (post-setup) configuration of a potentially foreign wiki.
$localVHosts
Array of domains that are local and can be handled by the same server.
extractAllGlobals( $wiki, $suffix=null, $params=[], $wikiTags=[])
Retrieves the values of all settings, and places them in their corresponding global variables.
$wikis
Array of wikis, should be the same as $wgLocalDatabases.
getSetting( $settingName, $wiki, array $params)
Really retrieves a configuration setting for a given wiki.
mergeParams( $wiki, $suffix, array $params, array $wikiTags)
Merge params between the ones passed to the function and the ones given by self::$siteParamsCallback ...
siteFromDB( $wiki)
Work out the site and language name from a database name.
array $cfgCache
Configuration cache for getConfig()
string array $fullLoadCallback
Optional callback to load full configuration data.
extractGlobal( $setting, $wiki, $suffix=null, $params=[], $wikiTags=[])
Retrieves the value of a given setting, and places it in its corresponding global variable.
string array $siteParamsCallback
A callback function that returns an array with the following keys (all optional):
extractGlobalSetting( $setting, $wiki, $params)
getAll( $wiki, $suffix=null, $params=[], $wikiTags=[])
Gets all settings for a wiki.
extractVar( $setting, $wiki, $suffix, &$var, $params=[], $wikiTags=[])
Retrieves the value of a given setting, and places it in a variable passed by reference.
getWikiParams( $wiki)
Return specific settings for $wiki See the documentation of self::$siteParamsCallback for more in-dep...
getBool( $setting, $wiki, $suffix=null, $wikiTags=[])
Retrieves a configuration setting for a given wiki, forced to a boolean.
$settings
The whole array of settings.
static arrayMerge(array $array1,... $arrays)
Merge multiple arrays together.
& getLocalDatabases()
Retrieves an array of local databases.
$fullLoadDone
Whether or not all data has been loaded.
$suffixes
Array of suffixes, for self::siteFromDB()
doReplace( $from, $to, $in)
Type-safe string replace; won't do replacements on non-strings private?
if(!isset( $args[0])) $lang