Fix regression in even sizing of diff columns; forgot to restore a couple bits I...
[mediawiki.git] / includes / SiteConfiguration.php
blob0968460cc3da21ad13143f05468c452445db50f1
1 <?php
3 /**
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.
7 */
8 if (!defined('SITE_CONFIGURATION')) {
9 define('SITE_CONFIGURATION', 1);
11 /**
12 * This is a class used to hold configuration settings, particularly for multi-wiki sites.
15 class SiteConfiguration {
16 var $suffixes = array();
17 var $wikis = array();
18 var $settings = array();
19 var $localVHosts = array();
21 /** */
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'];
30 } else {
31 $retval = NULL;
33 } else {
34 $retval = NULL;
37 if ( !is_null( $retval ) && count( $params ) ) {
38 foreach ( $params as $key => $value ) {
39 $retval = str_replace( '$' . $key, $value, $retval );
42 return $retval;
45 /** */
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;
57 /** */
58 function getBool( $setting, $wiki, $suffix ) {
59 return (bool)($this->get( $setting, $wiki, $suffix ));
62 /** */
63 function &getLocalDatabases() {
64 return $this->wikis;
67 /** */
68 function initialise() {
71 /** */
72 function extractVar( $setting, $wiki, $suffix, &$var, $params ) {
73 $value = $this->get( $setting, $wiki, $suffix, $params );
74 if ( !is_null( $value ) ) {
75 $var = $value;
79 /** */
80 function extractGlobal( $setting, $wiki, $suffix, $params ) {
81 $value = $this->get( $setting, $wiki, $suffix, $params );
82 if ( !is_null( $value ) ) {
83 $GLOBALS[$setting] = $value;
87 /** */
88 function extractAllGlobals( $wiki, $suffix, $params ) {
89 foreach ( $this->settings as $varName => $setting ) {
90 $this->extractGlobal( $varName, $wiki, $suffix, $params );
94 /**
95 * Work out the site and language name from a database name
96 * @param $db
98 function siteFromDB( $db ) {
99 $site = NULL;
100 $lang = NULL;
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 ) );
105 break;
108 $lang = str_replace( '_', '-', $lang );
109 return array( $site, $lang );
112 /** */
113 function isLocalVHost( $vhost ) {
114 return in_array( $vhost, $this->localVHosts );