BlueSpice MediaWiki REL1_27
 All Classes Namespaces Files Functions Variables Groups Pages
SiteConfiguration Class Reference

Public Member Functions

 get ($settingName, $wiki, $suffix=null, $params=[], $wikiTags=[])
 
 doReplace ($from, $to, $in)
 
 getAll ($wiki, $suffix=null, $params=[], $wikiTags=[])
 
 getBool ($setting, $wiki, $suffix=null, $wikiTags=[])
 
getLocalDatabases ()
 
 extractVar ($setting, $wiki, $suffix, &$var, $params=[], $wikiTags=[])
 
 extractGlobal ($setting, $wiki, $suffix=null, $params=[], $wikiTags=[])
 
 extractGlobalSetting ($setting, $wiki, $params)
 
 extractAllGlobals ($wiki, $suffix=null, $params=[], $wikiTags=[])
 
 siteFromDB ($db)
 
 getConfig ($wiki, $settings)
 
 isLocalVHost ($vhost)
 
 loadFullData ()
 

Static Public Member Functions

static arrayMerge ($array1)
 

Public Attributes

 $suffixes = []
 
 $wikis = []
 
 $settings = []
 
 $localVHosts = []
 
 $fullLoadCallback = null
 
 $fullLoadDone = false
 
 $siteParamsCallback = null
 

Protected Member Functions

 getSetting ($settingName, $wiki, array $params)
 
 getWikiParams ($wiki)
 
 mergeParams ($wiki, $suffix, array $params, array $wikiTags)
 

Protected Attributes

 $cfgCache = []
 

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!

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
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
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.
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.
SiteConfiguration::extractGlobalSetting (   $setting,
  $wiki,
  $params 
)
Parameters
string$setting
string$wiki
array$params
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.
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.
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.
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.
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
& SiteConfiguration::getLocalDatabases ( )

Retrieves an array of local databases

Returns
array
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.
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
SiteConfiguration::isLocalVHost (   $vhost)

Returns true if the given vhost is handled locally.

Deprecated:
since 1.25; check if the host is in $wgLocalVirtualHosts instead.
Parameters
string$vhost
Returns
bool
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
SiteConfiguration::siteFromDB (   $db)

Work out the site and language name from a database name

Parameters
string$db
Returns
array

Member Data Documentation

SiteConfiguration::$fullLoadDone = false

Whether or not all data has been loaded

SiteConfiguration::$localVHosts = []

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

Deprecated:
since 1.25; use $wgLocalVirtualHosts instead.
SiteConfiguration::$settings = []

The whole array of settings

SiteConfiguration::$suffixes = []

Array of suffixes, for self::siteFromDB()

SiteConfiguration::$wikis = []

Array of wikis, should be the same as $wgLocalDatabases


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