MediaWiki
REL1_20
|
This is a class for holding configuration settings, particularly for multi-wiki sites. More...
Public Member Functions | |
doReplace ($from, $to, $in) | |
Type-safe string replace; won't do replacements on non-strings private? | |
extractAllGlobals ($wiki, $suffix=null, $params=array(), $wikiTags=array()) | |
Retrieves the values of all settings, and places them in their corresponding global variables. | |
extractGlobal ($setting, $wiki, $suffix=null, $params=array(), $wikiTags=array()) | |
Retrieves the value of a given setting, and places it in its corresponding global variable. | |
extractGlobalSetting ($setting, $wiki, $params) | |
extractVar ($setting, $wiki, $suffix, &$var, $params=array(), $wikiTags=array()) | |
Retrieves the value of a given setting, and places it in a variable passed by reference. | |
get ($settingName, $wiki, $suffix=null, $params=array(), $wikiTags=array()) | |
Retrieves a configuration setting for a given wiki. | |
getAll ($wiki, $suffix=null, $params=array(), $wikiTags=array()) | |
Gets all settings for a wiki. | |
getBool ($setting, $wiki, $suffix=null, $wikiTags=array()) | |
Retrieves a configuration setting for a given wiki, forced to a boolean. | |
& | getLocalDatabases () |
Retrieves an array of local databases. | |
isLocalVHost ($vhost) | |
Returns true if the given vhost is handled locally. | |
loadFullData () | |
siteFromDB ($db) | |
Work out the site and language name from a database name. | |
Static Public Member Functions | |
static | arrayMerge ($array1) |
Merge multiple arrays together. | |
Public Attributes | |
string array | $fullLoadCallback = null |
Optional callback to load full configuration data. | |
$fullLoadDone = false | |
Whether or not all data has been loaded. | |
$localVHosts = array() | |
Array of domains that are local and can be handled by the same server. | |
$settings = array() | |
The whole array of settings. | |
string array | $siteParamsCallback = null |
A callback function that returns an array with the following keys (all optional): | |
$suffixes = array() | |
Array of suffixes, for self::siteFromDB() | |
$wikis = array() | |
Array of wikis, should be the same as $wgLocalDatabases. | |
Protected Member Functions | |
getSetting ($settingName, $wiki, $params) | |
Really retrieves a configuration setting for a given wiki. | |
getWikiParams ($wiki) | |
Return specific settings for $wiki See the documentation of self::$siteParamsCallback for more in-depth documentation about this function. | |
mergeParams ($wiki, $suffix, $params, $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. |
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 = array( '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 = array( 'wgSomeSetting' => array( # 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 = array( 'wgSomeSetting' => array( '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 = array( 'wgMergeSetting' = array( # Value that will be shared among all wikis: 'default' => array( NS_USER => true ), # Leading '+' means merging the array of value with the defaults '+beta' => array( NS_HELP => true ), ), ); # Get configuration for the German site: $conf->get( 'wgMergeSetting', 'de' ); // --> array( NS_USER => true ); # Get configuration for the testing site: $conf->get( 'wgMergeSetting', 'beta' ); // --> array( 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 );
TODO: give examples for, suffixes: $conf->suffixes = array( 'wiki' ); localVHosts callbacks!
Definition at line 117 of file SiteConfiguration.php.
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
$array1 | array |
Definition at line 506 of file SiteConfiguration.php.
SiteConfiguration::doReplace | ( | $ | from, |
$ | to, | ||
$ | in | ||
) |
Type-safe string replace; won't do replacements on non-strings private?
$from | |
$to | |
$in |
Definition at line 260 of file SiteConfiguration.php.
SiteConfiguration::extractAllGlobals | ( | $ | wiki, |
$ | suffix = null , |
||
$ | params = array() , |
||
$ | wikiTags = array() |
||
) |
Retrieves the values of all settings, and places them in their corresponding global variables.
$wiki | String Wiki ID of the wiki in question. |
$suffix | String The suffix of the wiki in question. |
$params | Array List of parameters. $.'key' is replaced by $value in all returned data. |
$wikiTags | Array The tags assigned to the wiki. |
Definition at line 381 of file SiteConfiguration.php.
SiteConfiguration::extractGlobal | ( | $ | setting, |
$ | wiki, | ||
$ | suffix = null , |
||
$ | params = array() , |
||
$ | wikiTags = array() |
||
) |
Retrieves the value of a given setting, and places it in its corresponding global variable.
$setting | String ID of the setting name to retrieve |
$wiki | String Wiki ID of the wiki in question. |
$suffix | String The suffix of the wiki in question. |
$params | Array List of parameters. $.'key' is replaced by $value in all returned data. |
$wikiTags | Array The tags assigned to the wiki. |
Definition at line 348 of file SiteConfiguration.php.
SiteConfiguration::extractGlobalSetting | ( | $ | setting, |
$ | wiki, | ||
$ | params | ||
) |
$setting | string |
$wiki | string |
$params | array |
Definition at line 358 of file SiteConfiguration.php.
SiteConfiguration::extractVar | ( | $ | setting, |
$ | wiki, | ||
$ | suffix, | ||
&$ | var, | ||
$ | params = array() , |
||
$ | wikiTags = array() |
||
) |
Retrieves the value of a given setting, and places it in a variable passed by reference.
$setting | String ID of the setting name to retrieve |
$wiki | String Wiki ID of the wiki in question. |
$suffix | String The suffix of the wiki in question. |
$var | array Reference The variable to insert the value into. |
$params | Array List of parameters. $.'key' is replaced by $value in all returned data. |
$wikiTags | Array The tags assigned to the wiki. |
Definition at line 333 of file SiteConfiguration.php.
SiteConfiguration::get | ( | $ | settingName, |
$ | wiki, | ||
$ | suffix = null , |
||
$ | params = array() , |
||
$ | wikiTags = array() |
||
) |
Retrieves a configuration setting for a given wiki.
$settingName | String ID of the setting name to retrieve |
$wiki | String Wiki ID of the wiki in question. |
$suffix | String The suffix of the wiki in question. |
$params | Array List of parameters. $.'key' is replaced by $value in all returned data. |
$wikiTags | Array The tags assigned to the wiki. |
Definition at line 171 of file SiteConfiguration.php.
SiteConfiguration::getAll | ( | $ | wiki, |
$ | suffix = null , |
||
$ | params = array() , |
||
$ | wikiTags = array() |
||
) |
Gets all settings for a wiki.
$wiki | String Wiki ID of the wiki in question. |
$suffix | String The suffix of the wiki in question. |
$params | Array List of parameters. $.'key' is replaced by $value in all returned data. |
$wikiTags | Array The tags assigned to the wiki. |
Definition at line 281 of file SiteConfiguration.php.
SiteConfiguration::getBool | ( | $ | setting, |
$ | wiki, | ||
$ | suffix = null , |
||
$ | wikiTags = array() |
||
) |
Retrieves a configuration setting for a given wiki, forced to a boolean.
$setting | String ID of the setting name to retrieve |
$wiki | String Wiki ID of the wiki in question. |
$suffix | String The suffix of the wiki in question. |
$wikiTags | Array The tags assigned to the wiki. |
Definition at line 311 of file SiteConfiguration.php.
Retrieves an array of local databases.
Definition at line 320 of file SiteConfiguration.php.
SiteConfiguration::getSetting | ( | $ | settingName, |
$ | wiki, | ||
$ | params | ||
) | [protected] |
Really retrieves a configuration setting for a given wiki.
$settingName | String ID of the setting name to retrieve. |
$wiki | String Wiki ID of the wiki in question. |
$params | Array: array of parameters. |
Definition at line 184 of file SiteConfiguration.php.
SiteConfiguration::getWikiParams | ( | $ | wiki | ) | [protected] |
Return specific settings for $wiki See the documentation of self::$siteParamsCallback for more in-depth documentation about this function.
$wiki | String |
Definition at line 396 of file SiteConfiguration.php.
SiteConfiguration::isLocalVHost | ( | $ | vhost | ) |
Returns true if the given vhost is handled locally.
$vhost | String |
Definition at line 492 of file SiteConfiguration.php.
Definition at line 524 of file SiteConfiguration.php.
SiteConfiguration::mergeParams | ( | $ | wiki, |
$ | suffix, | ||
$ | params, | ||
$ | 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.
$wiki | String Wiki ID of the wiki in question. |
$suffix | String The suffix of the wiki in question. |
$params | Array List of parameters. $.'key' is replaced by $value in all returned data. |
$wikiTags | Array The tags assigned to the wiki. |
Definition at line 435 of file SiteConfiguration.php.
SiteConfiguration::siteFromDB | ( | $ | db | ) |
Work out the site and language name from a database name.
$db |
Definition at line 463 of file SiteConfiguration.php.
string array SiteConfiguration::$fullLoadCallback = null |
Optional callback to load full configuration data.
Definition at line 142 of file SiteConfiguration.php.
SiteConfiguration::$fullLoadDone = false |
Whether or not all data has been loaded.
Definition at line 145 of file SiteConfiguration.php.
SiteConfiguration::$localVHosts = array() |
Array of domains that are local and can be handled by the same server.
Definition at line 137 of file SiteConfiguration.php.
SiteConfiguration::$settings = array() |
The whole array of settings.
Definition at line 132 of file SiteConfiguration.php.
string array SiteConfiguration::$siteParamsCallback = null |
A callback function that returns an array with the following keys (all optional):
Definition at line 160 of file SiteConfiguration.php.
SiteConfiguration::$suffixes = array() |
Array of suffixes, for self::siteFromDB()
Definition at line 122 of file SiteConfiguration.php.
SiteConfiguration::$wikis = array() |
Array of wikis, should be the same as $wgLocalDatabases.
Definition at line 127 of file SiteConfiguration.php.