MediaWiki  1.28.0
SiteConfiguration Class Reference

This is a class for holding configuration settings, particularly for multi-wiki sites. More...

Collaboration diagram for SiteConfiguration:

Public Member Functions

 doReplace ($from, $to, $in)
 Type-safe string replace; won't do replacements on non-strings private? More...
 
 extractAllGlobals ($wiki, $suffix=null, $params=[], $wikiTags=[])
 Retrieves the values of all settings, and places them in their corresponding global variables. More...
 
 extractGlobal ($setting, $wiki, $suffix=null, $params=[], $wikiTags=[])
 Retrieves the value of a given setting, and places it in its corresponding global variable. More...
 
 extractGlobalSetting ($setting, $wiki, $params)
 
 extractVar ($setting, $wiki, $suffix, &$var, $params=[], $wikiTags=[])
 Retrieves the value of a given setting, and places it in a variable passed by reference. More...
 
 get ($settingName, $wiki, $suffix=null, $params=[], $wikiTags=[])
 Retrieves a configuration setting for a given wiki. More...
 
 getAll ($wiki, $suffix=null, $params=[], $wikiTags=[])
 Gets all settings for a wiki. More...
 
 getBool ($setting, $wiki, $suffix=null, $wikiTags=[])
 Retrieves a configuration setting for a given wiki, forced to a boolean. More...
 
 getConfig ($wiki, $settings)
 Get the resolved (post-setup) configuration of a potentially foreign wiki. More...
 
getLocalDatabases ()
 Retrieves an array of local databases. More...
 
 loadFullData ()
 
 siteFromDB ($db)
 Work out the site and language name from a database name. More...
 

Static Public Member Functions

static arrayMerge ($array1)
 Merge multiple arrays together. More...
 

Public Attributes

string array $fullLoadCallback = null
 Optional callback to load full configuration data. More...
 
 $fullLoadDone = false
 Whether or not all data has been loaded. More...
 
 $localVHosts = []
 Array of domains that are local and can be handled by the same server. More...
 
 $settings = []
 The whole array of settings. More...
 
string array $siteParamsCallback = null
 A callback function that returns an array with the following keys (all optional): More...
 
 $suffixes = []
 Array of suffixes, for self::siteFromDB() More...
 
 $wikis = []
 Array of wikis, should be the same as $wgLocalDatabases. More...
 

Protected Member Functions

 getSetting ($settingName, $wiki, array $params)
 Really retrieves a configuration setting for a given wiki. More...
 
 getWikiParams ($wiki)
 Return specific settings for $wiki See the documentation of self::$siteParamsCallback for more in-depth documentation about this function. More...
 
 mergeParams ($wiki, $suffix, array $params, array $wikiTags)
 Merge params between the ones passed to the function and the ones given by self::$siteParamsCallback for backward compatibility Values returned by self::getWikiParams() have the priority. More...
 

Protected Attributes

array $cfgCache = []
 Configuration cache for getConfig() More...
 

Detailed Description

This is a class for holding configuration settings, particularly for multi-wiki sites.

A basic synopsis:

Consider a wikifarm having three sites: two production sites, one in English and one in German, and one testing site. You can assign them easy-to-remember identifiers - ISO 639 codes 'en' and 'de' for language wikis, and 'beta' for the testing wiki.

You would thus initialize the site configuration by specifying the wiki identifiers:

$conf = new SiteConfiguration;
$conf->wikis = [ 'de', 'en', 'beta' ];

When configuring the MediaWiki global settings (the $wg variables), the identifiers will be available to specify settings on a per wiki basis.

$conf->settings = [
'wgSomeSetting' => [
# production:
'de' => false,
'en' => false,
# test:
'beta => true,
],
];

With three wikis, that is easy to manage. But what about a farm with hundreds of wikis? Site configuration provides a special keyword named 'default' which is the value used when a wiki is not found. Hence the above code could be written:

$conf->settings = [
'wgSomeSetting' => [
'default' => false,
# Enable feature on test
'beta' => true,
],
];

Since settings can contain arrays, site configuration provides a way to merge an array with the default. This is very useful to avoid repeating settings again and again while still maintaining specific changes on a per wiki basis.

$conf->settings = [
'wgMergeSetting' = [
# Value that will be shared among all wikis:
'default' => [ NS_USER => true ],
# Leading '+' means merging the array of value with the defaults
'+beta' => [ NS_HELP => true ],
],
];
# Get configuration for the German site:
$conf->get( 'wgMergeSetting', 'de' );
// --> [ NS_USER => true ];
# Get configuration for the testing site:
$conf->get( 'wgMergeSetting', 'beta' );
// --> [ NS_USER => true, NS_HELP => true ];

Finally, to load all configuration settings, extract them in global context:

# Name / identifier of the wiki as set in $conf->wikis
$wikiID = 'beta';
$globals = $conf->getAll( $wikiID );
extract( $globals );
Note
For WikiMap to function, the configuration must define string values for $wgServer (or $wgCanonicalServer) and $wgArticlePath, even if these are the same for all wikis or can be correctly determined by the logic in Setup.php.
Todo:
Give examples for, suffixes: $conf->suffixes = [ 'wiki' ]; localVHosts callbacks!

Definition at line 122 of file SiteConfiguration.php.

Member Function Documentation

static SiteConfiguration::arrayMerge (   $array1)
static

Merge multiple arrays together.

On encountering duplicate keys, merge the two, but ONLY if they're arrays. PHP's array_merge_recursive() merges ANY duplicate values into arrays, which is not fun

Parameters
array$array1
Returns
array

Definition at line 583 of file SiteConfiguration.php.

References $out, $value, and as.

SiteConfiguration::doReplace (   $from,
  $to,
  $in 
)

Type-safe string replace; won't do replacements on non-strings private?

Parameters
string$from
string$to
string | array$in
Returns
string

Definition at line 279 of file SiteConfiguration.php.

References $from, and as.

Referenced by getSetting().

SiteConfiguration::extractAllGlobals (   $wiki,
  $suffix = null,
  $params = [],
  $wikiTags = [] 
)

Retrieves the values of all settings, and places them in their corresponding global variables.

Parameters
string$wikiWiki ID of the wiki in question.
string$suffixThe suffix of the wiki in question.
array$paramsList of parameters. $.'key' is replaced by $value in all returned data.
array$wikiTagsThe tags assigned to the wiki.

Definition at line 404 of file SiteConfiguration.php.

References as, extractGlobalSetting(), mergeParams(), and settings.

SiteConfiguration::extractGlobal (   $setting,
  $wiki,
  $suffix = null,
  $params = [],
  $wikiTags = [] 
)

Retrieves the value of a given setting, and places it in its corresponding global variable.

Parameters
string$settingID of the setting name to retrieve
string$wikiWiki ID of the wiki in question.
string$suffixThe suffix of the wiki in question.
array$paramsList of parameters. $.'key' is replaced by $value in all returned data.
array$wikiTagsThe tags assigned to the wiki.

Definition at line 369 of file SiteConfiguration.php.

References extractGlobalSetting(), and mergeParams().

SiteConfiguration::extractGlobalSetting (   $setting,
  $wiki,
  $params 
)
Parameters
string$setting
string$wiki
array$params

Definition at line 381 of file SiteConfiguration.php.

References $GLOBALS, $value, and getSetting().

Referenced by extractAllGlobals(), and extractGlobal().

SiteConfiguration::extractVar (   $setting,
  $wiki,
  $suffix,
$var,
  $params = [],
  $wikiTags = [] 
)

Retrieves the value of a given setting, and places it in a variable passed by reference.

Parameters
string$settingID of the setting name to retrieve
string$wikiWiki ID of the wiki in question.
string$suffixThe suffix of the wiki in question.
array$varReference The variable to insert the value into.
array$paramsList of parameters. $.'key' is replaced by $value in all returned data.
array$wikiTagsThe tags assigned to the wiki.

Definition at line 352 of file SiteConfiguration.php.

References $params, and $value.

SiteConfiguration::get (   $settingName,
  $wiki,
  $suffix = null,
  $params = [],
  $wikiTags = [] 
)

Retrieves a configuration setting for a given wiki.

Parameters
string$settingNameID of the setting name to retrieve
string$wikiWiki ID of the wiki in question.
string$suffixThe suffix of the wiki in question.
array$paramsList of parameters. $.'key' is replaced by $value in all returned data.
array$wikiTagsThe tags assigned to the wiki.
Returns
mixed The value of the setting requested.

Definition at line 186 of file SiteConfiguration.php.

References getSetting(), and mergeParams().

SiteConfiguration::getAll (   $wiki,
  $suffix = null,
  $params = [],
  $wikiTags = [] 
)

Gets all settings for a wiki.

Parameters
string$wikiWiki ID of the wiki in question.
string$suffixThe suffix of the wiki in question.
array$paramsList of parameters. $.'key' is replaced by $value in all returned data.
array$wikiTagsThe tags assigned to the wiki.
Returns
array Array of settings requested.

Definition at line 300 of file SiteConfiguration.php.

References $GLOBALS, $value, as, getSetting(), mergeParams(), and settings.

SiteConfiguration::getBool (   $setting,
  $wiki,
  $suffix = null,
  $wikiTags = [] 
)

Retrieves a configuration setting for a given wiki, forced to a boolean.

Parameters
string$settingID of the setting name to retrieve
string$wikiWiki ID of the wiki in question.
string$suffixThe suffix of the wiki in question.
array$wikiTagsThe tags assigned to the wiki.
Returns
bool The value of the setting requested.

Definition at line 330 of file SiteConfiguration.php.

SiteConfiguration::getConfig (   $wiki,
  $settings 
)

Get the resolved (post-setup) configuration of a potentially foreign wiki.

For foreign wikis, this is expensive, and only works if maintenance scripts are setup to handle the –wiki parameter such as in wiki farms.

Parameters
string$wiki
array | string$settingsA setting name or array of setting names
Returns
mixed|mixed[] Array if $settings is an array, otherwise the value
Exceptions
MWException
Since
1.21

Definition at line 523 of file SiteConfiguration.php.

References $GLOBALS, $IP, $name, $res, $settings, array(), as, global, unserialize(), wfShellExec(), wfShellWikiCmd(), and wfWikiID().

& SiteConfiguration::getLocalDatabases ( )

Retrieves an array of local databases.

Returns
array

Definition at line 339 of file SiteConfiguration.php.

References $wikis.

SiteConfiguration::getSetting (   $settingName,
  $wiki,
array  $params 
)
protected

Really retrieves a configuration setting for a given wiki.

Parameters
string$settingNameID of the setting name to retrieve.
string$wikiWiki ID of the wiki in question.
array$paramsArray of parameters.
Returns
mixed The value of the setting requested.

Definition at line 201 of file SiteConfiguration.php.

References $retval, $tag, $value, as, doReplace(), and settings.

Referenced by extractGlobalSetting(), get(), and getAll().

SiteConfiguration::getWikiParams (   $wiki)
protected

Return specific settings for $wiki See the documentation of self::$siteParamsCallback for more in-depth documentation about this function.

Parameters
string$wiki
Returns
array

Definition at line 421 of file SiteConfiguration.php.

References $name, $ret, and as.

Referenced by mergeParams(), and siteFromDB().

SiteConfiguration::loadFullData ( )

Definition at line 603 of file SiteConfiguration.php.

SiteConfiguration::mergeParams (   $wiki,
  $suffix,
array  $params,
array  $wikiTags 
)
protected

Merge params between the ones passed to the function and the ones given by self::$siteParamsCallback for backward compatibility Values returned by self::getWikiParams() have the priority.

Parameters
string$wikiWiki ID of the wiki in question.
string$suffixThe suffix of the wiki in question.
array$paramsList of parameters. $.'key' is replaced by $value in all returned data.
array$wikiTagsThe tags assigned to the wiki.
Returns
array

Definition at line 460 of file SiteConfiguration.php.

References $params, $ret, and getWikiParams().

Referenced by extractAllGlobals(), extractGlobal(), get(), and getAll().

SiteConfiguration::siteFromDB (   $db)

Work out the site and language name from a database name.

Parameters
string$db
Returns
array

Definition at line 488 of file SiteConfiguration.php.

References $lang, as, and getWikiParams().

Member Data Documentation

array SiteConfiguration::$cfgCache = []
protected

Configuration cache for getConfig()

Definition at line 175 of file SiteConfiguration.php.

string array SiteConfiguration::$fullLoadCallback = null

Optional callback to load full configuration data.

Definition at line 150 of file SiteConfiguration.php.

SiteConfiguration::$fullLoadDone = false

Whether or not all data has been loaded.

Definition at line 153 of file SiteConfiguration.php.

SiteConfiguration::$localVHosts = []

Array of domains that are local and can be handled by the same server.

Deprecated:
since 1.25; use $wgLocalVirtualHosts instead.

Definition at line 144 of file SiteConfiguration.php.

SiteConfiguration::$settings = []

The whole array of settings.

Definition at line 137 of file SiteConfiguration.php.

Referenced by getConfig().

string array SiteConfiguration::$siteParamsCallback = null

A callback function that returns an array with the following keys (all optional):

  • suffix: site's suffix
  • lang: site's lang
  • tags: array of wiki tags
  • params: array of parameters to be replaced The function will receive the SiteConfiguration instance in the first argument and the wiki in the second one. if suffix and lang are passed they will be used for the return value of self::siteFromDB() and self::$suffixes will be ignored

Definition at line 169 of file SiteConfiguration.php.

SiteConfiguration::$suffixes = []

Array of suffixes, for self::siteFromDB()

Definition at line 127 of file SiteConfiguration.php.

SiteConfiguration::$wikis = []

Array of wikis, should be the same as $wgLocalDatabases.

Definition at line 132 of file SiteConfiguration.php.

Referenced by getLocalDatabases().


The documentation for this class was generated from the following file: