MediaWiki  1.23.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=array(), $wikiTags=array())
 Retrieves the values of all settings, and places them in their corresponding global variables. More...
 
 extractGlobal ( $setting, $wiki, $suffix=null, $params=array(), $wikiTags=array())
 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=array(), $wikiTags=array())
 Retrieves the value of a given setting, and places it in a variable passed by reference. More...
 
 get ( $settingName, $wiki, $suffix=null, $params=array(), $wikiTags=array())
 Retrieves a configuration setting for a given wiki. More...
 
 getAll ( $wiki, $suffix=null, $params=array(), $wikiTags=array())
 Gets all settings for a wiki. More...
 
 getBool ( $setting, $wiki, $suffix=null, $wikiTags=array())
 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...
 
 isLocalVHost ( $vhost)
 Returns true if the given vhost is handled locally. 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()
 Array of domains that are local and can be handled by the same server. More...
 
 $settings = array()
 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()
 Array of suffixes, for self::siteFromDB() More...
 
 $wikis = array()
 Array of wikis, should be the same as $wgLocalDatabases. More...
 

Protected Member Functions

 getSetting ( $settingName, $wiki, $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, $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. More...
 

Protected Attributes

array $cfgCache = array()
 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 = 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.

Member Function Documentation

◆ arrayMerge()

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
$array1array
Returns
array

Definition at line 572 of file SiteConfiguration.php.

References $out, $value, and as.

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

◆ doReplace()

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

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

Parameters
$from
$to
$in
Returns
string

Definition at line 265 of file SiteConfiguration.php.

References $from, $in, and as.

Referenced by getSetting().

◆ extractAllGlobals()

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

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 386 of file SiteConfiguration.php.

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

◆ extractGlobal()

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.

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 353 of file SiteConfiguration.php.

References $params, extractGlobalSetting(), and mergeParams().

◆ extractGlobalSetting()

SiteConfiguration::extractGlobalSetting (   $setting,
  $wiki,
  $params 
)
Parameters
$settingstring
$wikistring
$paramsarray

Definition at line 363 of file SiteConfiguration.php.

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

Referenced by extractAllGlobals(), and extractGlobal().

◆ extractVar()

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.

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 338 of file SiteConfiguration.php.

References $params, and $value.

◆ get()

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

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 176 of file SiteConfiguration.php.

References $params, getSetting(), and mergeParams().

◆ getAll()

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

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 286 of file SiteConfiguration.php.

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

◆ getBool()

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

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 316 of file SiteConfiguration.php.

References array().

◆ getConfig()

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
Array|mixed Array if $settings is an array, otherwise the value
Exceptions
MWException
Since
1.21

Definition at line 503 of file SiteConfiguration.php.

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

◆ getLocalDatabases()

& SiteConfiguration::getLocalDatabases ( )

Retrieves an array of local databases.

Returns
array

Definition at line 325 of file SiteConfiguration.php.

References $wikis.

◆ getSetting()

SiteConfiguration::getSetting (   $settingName,
  $wiki,
  $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 189 of file SiteConfiguration.php.

References $params, $retval, $value, array(), arrayMerge(), as, doReplace(), and settings.

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

◆ getWikiParams()

SiteConfiguration::getWikiParams (   $wiki)
protected

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

Parameters
$wikiString
Returns
array

Definition at line 401 of file SiteConfiguration.php.

References $name, $ret, array(), and as.

Referenced by mergeParams(), and siteFromDB().

◆ isLocalVHost()

SiteConfiguration::isLocalVHost (   $vhost)

Returns true if the given vhost is handled locally.

Parameters
$vhostString
Returns
bool

Definition at line 558 of file SiteConfiguration.php.

◆ loadFullData()

SiteConfiguration::loadFullData ( )

Definition at line 590 of file SiteConfiguration.php.

◆ mergeParams()

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.

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 440 of file SiteConfiguration.php.

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

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

◆ siteFromDB()

SiteConfiguration::siteFromDB (   $db)

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

Parameters
$db
Returns
array

Definition at line 468 of file SiteConfiguration.php.

References array(), as, and getWikiParams().

Member Data Documentation

◆ $cfgCache

array SiteConfiguration::$cfgCache = array()
protected

Configuration cache for getConfig()

Definition at line 165 of file SiteConfiguration.php.

◆ $fullLoadCallback

string array SiteConfiguration::$fullLoadCallback = null

Optional callback to load full configuration data.

Definition at line 142 of file SiteConfiguration.php.

◆ $fullLoadDone

SiteConfiguration::$fullLoadDone = false

Whether or not all data has been loaded.

Definition at line 145 of file SiteConfiguration.php.

◆ $localVHosts

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.

◆ $settings

SiteConfiguration::$settings = array()

The whole array of settings.

Definition at line 132 of file SiteConfiguration.php.

Referenced by getConfig().

◆ $siteParamsCallback

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 160 of file SiteConfiguration.php.

◆ $suffixes

SiteConfiguration::$suffixes = array()

Array of suffixes, for self::siteFromDB()

Definition at line 122 of file SiteConfiguration.php.

◆ $wikis

SiteConfiguration::$wikis = array()

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

Definition at line 127 of file SiteConfiguration.php.

Referenced by getLocalDatabases().


The documentation for this class was generated from the following file:
of
globals txt Globals are evil The original MediaWiki code relied on globals for processing context far too often MediaWiki development since then has been a story of slowly moving context out of global variables and into objects Storing processing context in object member variables allows those objects to be reused in a much more flexible way Consider the elegance of
Definition: globals.txt:10
NS_HELP
const NS_HELP
Definition: Defines.php:91
SiteConfiguration
This is a class for holding configuration settings, particularly for multi-wiki sites.
Definition: SiteConfiguration.php:117
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
will
</td >< td > &</td >< td > t want your writing to be edited mercilessly and redistributed at will
Definition: All_system_messages.txt:914
on
We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going on
Definition: hooks.txt:86
NS_USER
const NS_USER
Definition: Defines.php:81
that
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global then executing the whole list after the page is displayed We don t do anything smart like collating updates to the same table or such because the list is almost always going to have just one item on if that
Definition: deferred.txt:11