MediaWiki 1.41.2
MediaWiki\Config\SiteConfiguration Class Reference

Configuration holder, particularly for multi-wiki sites. More...

Public Member Functions

 extractAllGlobals ( $wiki, $site=null, $params=[], $wikiTags=[])
 Retrieves the values of all settings, and places them in their corresponding global variables.
 
 extractGlobal ( $setting, $wiki, $site=null, $params=[], $wikiTags=[])
 Retrieves the value of a given setting, and places it in its corresponding global variable.
 
 extractGlobalSetting ( $setting, $wiki, $params)
 
 extractVar ( $setting, $wiki, $site, &$var, $params=[], $wikiTags=[])
 Retrieves the value of a given setting, and places it in a variable passed by reference.
 
 get ( $settingName, $wiki, $site=null, $params=[], $wikiTags=[])
 Retrieves a configuration setting for a given wiki.
 
 getAll ( $wiki, $site=null, $params=[], $wikiTags=[])
 Gets all settings for a wiki.
 
 getBool ( $setting, $wiki, $site=null, $wikiTags=[])
 Retrieves a configuration setting for a given wiki, forced to a boolean.
 
 getConfig ( $wiki, $settings)
 Get the resolved (post-setup) configuration of a potentially foreign wiki.
 
 getLocalDatabases ()
 Retrieves an array of local databases.
 
 loadFullData ()
 
 siteFromDB ( $wiki)
 Work out the site and language name from a database name.
 

Public Attributes

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

Protected Member Functions

 getWikiParams ( $wiki)
 Return specific settings for $wiki See the documentation of self::$siteParamsCallback for more in-depth documentation about this function.
 
 mergeParams ( $wiki, $site, 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.
 

Protected Attributes

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

Detailed Description

Configuration holder, 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' ];
Configuration holder, particularly for multi-wiki sites.

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 ];
const NS_HELP
Definition Defines.php:76
const NS_USER
Definition Defines.php:66
return true
Definition router.php:92

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 );

Simple suffix system where "pt_brwiki" becomes lang="pt-br", site="wiki":

$conf->suffixes[] = 'wiki';

Suffix is resolved as an alias, so "dewiki" becomes lang="de", site="wikipedia":

$conf->suffixes['wikipedia'] = 'wiki';
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.

Definition at line 130 of file SiteConfiguration.php.

Member Function Documentation

◆ extractAllGlobals()

MediaWiki\Config\SiteConfiguration::extractAllGlobals ( $wiki,
$site = 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 | null$siteThe site from ::siteFromDB(), or db suffix.
array$paramsList of parameters. $.'key' is replaced by $value in all returned data.
array$wikiTagsThe tags assigned to the wiki.

Definition at line 458 of file SiteConfiguration.php.

References MediaWiki\Config\SiteConfiguration\extractGlobalSetting(), and MediaWiki\Config\SiteConfiguration\mergeParams().

◆ extractGlobal()

MediaWiki\Config\SiteConfiguration::extractGlobal ( $setting,
$wiki,
$site = null,
$params = [],
$wikiTags = [] )

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

Deprecated
since 1.41 Use SiteConfiguration::get() instead.
Parameters
string$settingID of the setting name to retrieve
string$wikiWiki ID of the wiki in question.
string | null$siteThe site from ::siteFromDB(), or db suffix.
array$paramsList of parameters. $.'key' is replaced by $value in all returned data.
array$wikiTagsThe tags assigned to the wiki.

Definition at line 412 of file SiteConfiguration.php.

References MediaWiki\Config\SiteConfiguration\extractGlobalSetting(), MediaWiki\Config\SiteConfiguration\mergeParams(), and wfDeprecated().

◆ extractGlobalSetting()

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

Definition at line 429 of file SiteConfiguration.php.

Referenced by MediaWiki\Config\SiteConfiguration\extractAllGlobals(), and MediaWiki\Config\SiteConfiguration\extractGlobal().

◆ extractVar()

MediaWiki\Config\SiteConfiguration::extractVar ( $setting,
$wiki,
$site,
& $var,
$params = [],
$wikiTags = [] )

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

Deprecated
since 1.41 Use SiteConfiguration::get() instead.
Parameters
string$settingID of the setting name to retrieve
string$wikiWiki ID of the wiki in question.
string | null$siteThe site from ::siteFromDB(), or db suffix.
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 387 of file SiteConfiguration.php.

References wfDeprecated().

◆ get()

MediaWiki\Config\SiteConfiguration::get ( $settingName,
$wiki,
$site = 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 | null$siteThe site from ::siteFromDB(), or db suffix.
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 190 of file SiteConfiguration.php.

References MediaWiki\Config\SiteConfiguration\mergeParams().

◆ getAll()

MediaWiki\Config\SiteConfiguration::getAll ( $wiki,
$site = null,
$params = [],
$wikiTags = [] )

Gets all settings for a wiki.

Parameters
string$wikiWiki ID of the wiki in question.
string | null$siteThe site from ::siteFromDB(), or db suffix.
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 322 of file SiteConfiguration.php.

References MediaWiki\Config\SiteConfiguration\mergeParams().

◆ getBool()

MediaWiki\Config\SiteConfiguration::getBool ( $setting,
$wiki,
$site = 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 | null$siteThe site from ::siteFromDB(), or db suffix.
array$wikiTagsThe tags assigned to the wiki.
Returns
bool The value of the setting requested.

Definition at line 363 of file SiteConfiguration.php.

◆ getConfig()

MediaWiki\Config\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.

Deprecated
since 1.41. Use SiteConfiguration::get() instead.
Parameters
string$wiki
string | string[]$settingsA setting name or array of setting names
Returns
mixed|mixed[] Array if $settings is an array, otherwise the value
Since
1.21

Definition at line 590 of file SiteConfiguration.php.

References MediaWiki\Config\SiteConfiguration\$settings, MediaWiki\Shell\Shell\makeScriptCommand(), and wfDeprecated().

◆ getLocalDatabases()

MediaWiki\Config\SiteConfiguration::getLocalDatabases ( )

Retrieves an array of local databases.

Returns
array

Definition at line 372 of file SiteConfiguration.php.

References MediaWiki\Config\SiteConfiguration\$wikis.

◆ getWikiParams()

MediaWiki\Config\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 478 of file SiteConfiguration.php.

References MediaWiki\Config\SiteConfiguration\$siteParamsCallback.

Referenced by MediaWiki\Config\SiteConfiguration\mergeParams(), and MediaWiki\Config\SiteConfiguration\siteFromDB().

◆ loadFullData()

MediaWiki\Config\SiteConfiguration::loadFullData ( )

◆ mergeParams()

MediaWiki\Config\SiteConfiguration::mergeParams ( $wiki,
$site,
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 | null$siteThe site from ::siteFromDB(), or db suffix.
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 517 of file SiteConfiguration.php.

References MediaWiki\Config\SiteConfiguration\getWikiParams().

Referenced by MediaWiki\Config\SiteConfiguration\extractAllGlobals(), MediaWiki\Config\SiteConfiguration\extractGlobal(), MediaWiki\Config\SiteConfiguration\get(), and MediaWiki\Config\SiteConfiguration\getAll().

◆ siteFromDB()

MediaWiki\Config\SiteConfiguration::siteFromDB ( $wiki)

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

Parameters
string$wikiWiki ID
Returns
array [ string|null $site, string|null $languageCode ]

Definition at line 557 of file SiteConfiguration.php.

References MediaWiki\Config\SiteConfiguration\getWikiParams().

Member Data Documentation

◆ $cfgCache

array MediaWiki\Config\SiteConfiguration::$cfgCache = []
protected

Configuration cache for getConfig()

Definition at line 179 of file SiteConfiguration.php.

◆ $fullLoadCallback

string array MediaWiki\Config\SiteConfiguration::$fullLoadCallback = null

Optional callback to load full configuration data.

Definition at line 154 of file SiteConfiguration.php.

Referenced by MediaWiki\Config\SiteConfiguration\loadFullData().

◆ $fullLoadDone

MediaWiki\Config\SiteConfiguration::$fullLoadDone = false

Whether or not all data has been loaded.

Definition at line 157 of file SiteConfiguration.php.

◆ $settings

MediaWiki\Config\SiteConfiguration::$settings = []

The whole array of settings.

If the key "@replaceableSettings" exists, it contains a list of setting names that are subject to string replacement of $params.

Definition at line 148 of file SiteConfiguration.php.

Referenced by MediaWiki\Config\SiteConfiguration\getConfig().

◆ $siteParamsCallback

callable null MediaWiki\Config\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 173 of file SiteConfiguration.php.

Referenced by MediaWiki\Config\SiteConfiguration\getWikiParams().

◆ $suffixes

MediaWiki\Config\SiteConfiguration::$suffixes = []

Array of suffixes, for self::siteFromDB()

Definition at line 135 of file SiteConfiguration.php.

◆ $wikis

MediaWiki\Config\SiteConfiguration::$wikis = []

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

Definition at line 140 of file SiteConfiguration.php.

Referenced by MediaWiki\Config\SiteConfiguration\getLocalDatabases().


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