Manual:$wgConf
From MediaWiki.org
| Global Objects: $wgConf | |
|---|---|
| Create a site configuration object. Not used for much in a default install. |
|
| Introduced in version: | 1.5.0 (r9670) |
| Removed in version: | still in use |
| Allowed Values: | |
| Default Value: | new SiteConfiguration object. |
Other settings: Alphabetical | By Function
Contents |
[edit] Details
Create a site configuration object. Not used for much in a default install.
This is used on Wikimedia's mass installation to provide a centralized configuration file for a few hundred wikis, providing defaults per site group and per-wiki overrides.
It can be a bit confusing, though. :)
Currently needed by Extension:CentralAuth to fetch per-site information, eg linking to the proper user pages on each wiki.
[edit] Configuration
Wikis are grouped by the suffix on their database names; on a large installation there may be e.g. 'enwiki' and 'enwiktionary' and 'enwikibooks', each in a different suffix group. Suffixes have to be declared in the suffixes member variable of $wgConf if you want to use $wgConf->siteFromDB().
$wgConf->settings is the array of settings. Its format is $wgConf->settings['wgSettingName']['wiki'].
Settings may be assigned to (from the less specific to the more specific, this is the 'wiki' part of $wgConf->settings as mentioned above):
- 'default' to affect all wikis
- a suffix (eg 'wiki' or 'wiktionary') to affect all in that suffix group (can be determined with
$wgConf->siteFromDB()) - a wiki tag (since 1.12.0)
- a specific DB name.
For string settings, you can define parameters that will be replaced when extracting the settings. It can be useful when the setting has the same format for all wikis. The format is $name. Be careful to use single quotes (') or to escape the $ (\$) or it will be replaced with the PHP variable (that can be not defined at that time).
[edit] 1.13 and earlier
| MediaWiki version: | 1.13 | and earlier |
When extracting global settings, the object will search first the more specific level (the last one in the list above) and if it doesn't find the setting, it will search in less specific levels. When it finds one, if won't search for less specific ones. This means that you have to pay attention for some specific settings, such as $wgGroupPermissions, because it doesn't merge the setting with less specific levels, nor the default value (the one in DefaultSettings.php), you'll need to do it by yourself.
To extract the settings in global variables, you can use $wgConf->extractAllGlobals( $wiki, $suffix, $params, $wikiTags );.
Parameters are:
$wiki: Wiki's database name (generally $wgDBname). You have to define it yourself.$suffix: Wiki's suffix, used to to get the suffix level.$params: array of parameters mapping its name to its value.$wikiTags: (since 1.12.0) array of wiki tags.
[edit] 1.14 and newer
| MediaWiki version: | 1.14 | and newer |
Some new features were added in 1.14.0. The 1.13 and earlier part can still be used though.
[edit] Callback function
Since 1.14, a callback has been introduced to be able to modify the parameters passed to SiteConfiguration::get() and related function. It might be used to change parameters when such functions are called after LocalSettings.php (this is the case with CentralAuth). You can define it in $wgConf->siteParamsCallback. The callback function will receive the SiteConfiguration object in the first argument and the wiki name in the second one. It has to return an array with the following keys (all optional):
suffix: site's suffix (corresponding to $suffix paramter ofSiteConfiguration::get()and similar)lang: site's langtags: array of wiki tags (corresponding to $wikiTags parameter)params: array of parameters to be replaced (corresponding to $params parameter)
They'll be merged with the parameters passed to SiteConfiguration::get() and similar functions. If the suffix and lang are filled, the they'll be used to override the default behaviour of $wgConf->siteFromDB().
[edit] Settings merging
Arrays can now be merged. This might be useful for $wgGroupPermissions. To use it, you have to prefix the keys with a "+" for the settings you want to merge.
- To merge your customized version of the setting with the one in DefaultSettings.php, prefix the setting's name with "+" (such as
'+wgGroupPermissions') - To merge a more specific level with a less-specific one, prefix the level with a "+".
The two possibilities can be used together.
Example with $wgGroupPermissions:
$wgConf->settings = array( // ... // merge this with the value of $wgGroupPermissions defined // in DefaultSettings.php '+wgGroupPermissions' => array( // Allow bureaucrats to change status on remote wikis // and allow anonymous users to create page (this part // will not be merged with 'default' since there's no // "+" in front of 'centralwiki') 'centralwiki' => array( 'bureaucrat' => array( 'userrights-interwiki' => true, ), ), // A wiki with rollback right given to logged-in users // the 'default' part will be merged with this values // (i.e. anonymous users won't be able to create pages) '+somewiki' => array( 'user' => array( 'rollback' => true, ), ), // Disallow anonymous users to create pages. // Note: the 'default' key should never have a "+" in front of it 'default' => array( '*' => array( 'createpage' => false, 'createtalk' => false, ), ), ), // ... );
[edit] Example
This example uses 3 wikis: dewiki, enwiki and frwiki. They are located at http://localhost/$wgDBname/ (i.e. http://localhost/dewiki/, http://localhost/enwiki/ and http://localhost/frwiki/).
It assumes that $wgDBname is already defined.
Note: In this example, $wgConf->settings is declared in InitialiseSettings.php, this is not required and can be done in LocalSettings.php.
[edit] InitialiseSettings.php
<?php $wgConf->settings = array( 'wgServer' => array( 'default' => 'http://localhost', ), 'wgScriptPath' => array( 'default' => '/$wiki', ), 'wgArticlePath' => array( 'default' => '/$wiki/index.php/$1', ), 'wgSitename' => array( 'default' => 'Wikipedia', 'frwiki' => 'Wikipédia', ), 'wgLanguageCode' => array( 'default' => '$lang', ), 'wgLocalInterwiki' => array( 'default' => '$lang', ), );
[edit] LocalSettings.php
[edit] for 1.13 and earlier
| MediaWiki version: | 1.13 | and earlier |
$wgLocalDatabases = array( 'dewiki', 'enwiki', 'frwiki', ); $wgConf->wikis = $wgLocalDatabases; $wgConf->suffixes = array( 'wiki' ); $wgConf->localVHosts = array( 'localhost' ); require_once "$IP/InitialiseSettings.php"; list( $site, $lang ) = $wgConf->siteFromDB( $wgDBname ); $params = array( 'site' => $site, 'lang' => $lang, 'wiki' => $wgDBname, ); $wgConf->extractAllGlobals( $wgDBname, $site, $params, array() );
[edit] for 1.14 and newer
| MediaWiki version: | 1.14 | and newer |
$wgLocalDatabases = array( 'dewiki', 'enwiki', 'frwiki', ); $wgConf->wikis = $wgLocalDatabases; $wgConf->suffixes = array( 'wiki' ); $wgConf->localVHosts = array( 'localhost' ); require_once "$IP/InitialiseSettings.php"; function efGetSiteParams( $conf, $wiki ) { $site = null; $lang = null; foreach( $conf->suffixes as $suffix ) { if ( substr( $wiki, -strlen( $suffix ) ) == $suffix ) { $site = $suffix; $lang = substr( $wiki, 0, -strlen( $suffix ) ); break; } } return array( 'suffix' => $site, 'lang' => $lang, 'params' => array( 'lang' => $lang, 'site' => $site, 'wiki' => $wiki, ), 'tags' => array(), ); } $wgConf->siteParamsCallback = 'efGetSiteParams'; $wgConf->extractAllGlobals( $wgDBname );
[edit] Wikimedia configuration
To see how Wikimedia uses $wgConf to configure its wikis see:
- CommonSettings.php (Wikimedia's version of LocalSettings.php)
- InitialiseSettings.php (for
$wgConf->settings) - wgConf.php (used by CommonSettings.php to initialize $wgConf)