4 * The include paths change after this file is included from commandLine.inc,
5 * meaning that require_once() fails to detect that it is including the same
6 * file again. We use DIY C-style protection as a workaround.
8 if (!defined('SITE_CONFIGURATION')) {
9 define('SITE_CONFIGURATION', 1);
12 * This is a class used to hold configuration settings, particularly for multi-wiki sites.
15 class SiteConfiguration
{
16 var $suffixes = array();
18 var $settings = array();
19 var $localVHosts = array();
22 function get( $setting, $wiki, $suffix, $params = array() ) {
23 if ( array_key_exists( $setting, $this->settings
) ) {
24 if ( array_key_exists( $wiki, $this->settings
[$setting] ) ) {
25 $retval = $this->settings
[$setting][$wiki];
26 } elseif ( array_key_exists( $suffix, $this->settings
[$setting] ) ) {
27 $retval = $this->settings
[$setting][$suffix];
28 } elseif ( array_key_exists( 'default', $this->settings
[$setting] ) ) {
29 $retval = $this->settings
[$setting]['default'];
37 if ( !is_null( $retval ) && count( $params ) ) {
38 foreach ( $params as $key => $value ) {
39 $retval = str_replace( '$' . $key, $value, $retval );
46 function getAll( $wiki, $suffix, $params ) {
47 $localSettings = array();
48 foreach ( $this->settings
as $varname => $stuff ) {
49 $value = $this->get( $varname, $wiki, $suffix, $params );
50 if ( !is_null( $value ) ) {
51 $localSettings[$varname] = $value;
54 return $localSettings;
58 function getBool( $setting, $wiki, $suffix ) {
59 return (bool)($this->get( $setting, $wiki, $suffix ));
63 function &getLocalDatabases() {
68 function initialise() {
72 function extractVar( $setting, $wiki, $suffix, &$var, $params ) {
73 $value = $this->get( $setting, $wiki, $suffix, $params );
74 if ( !is_null( $value ) ) {
80 function extractGlobal( $setting, $wiki, $suffix, $params ) {
81 $value = $this->get( $setting, $wiki, $suffix, $params );
82 if ( !is_null( $value ) ) {
83 $GLOBALS[$setting] = $value;
88 function extractAllGlobals( $wiki, $suffix, $params ) {
89 foreach ( $this->settings
as $varName => $setting ) {
90 $this->extractGlobal( $varName, $wiki, $suffix, $params );
95 * Work out the site and language name from a database name
98 function siteFromDB( $db ) {
101 foreach ( $this->suffixes
as $suffix ) {
102 if ( substr( $db, -strlen( $suffix ) ) == $suffix ) {
103 $site = $suffix == 'wiki' ?
'wikipedia' : $suffix;
104 $lang = substr( $db, 0, strlen( $db ) - strlen( $suffix ) );
108 $lang = str_replace( '_', '-', $lang );
109 return array( $site, $lang );
113 function isLocalVHost( $vhost ) {
114 return in_array( $vhost, $this->localVHosts
);