Do *NOT* force all wikis into a non-functional initial state with a broken whitelist...
[mediawiki.git] / includes / SiteConfiguration.php
blob1abe48d8e9de46cfc3a13420d5037105ea2988b6
1 <?php
2 /**
3 *This file is used to configure the live Wikimedia wikis. The file that
4 * includes it contains passwords and other sensitive data, and there's
5 * currently no public equivalent.
7 * @package MediaWiki
8 */
10 /**
12 * @package MediaWiki
15 /**
16 * The include paths change after this file is included from commandLine.inc,
17 * meaning that require_once() fails to detect that it is including the same
18 * file again. We use DIY C-style protection as a workaround.
20 if (!defined('SITE_CONFIGURATION')) {
21 define('SITE_CONFIGURATION', 1);
23 class SiteConfiguration {
24 var $suffixes, $wikis, $settings;
25 var $localDatabases;
27 function get( $setting, $wiki, $suffix, $params = array() ) {
28 if ( array_key_exists( $wiki, $this->settings[$setting] ) ) {
29 $retval = $this->settings[$setting][$wiki];
30 } elseif ( array_key_exists( $suffix, $this->settings[$setting] ) ) {
31 $retval = $this->settings[$setting][$suffix];
32 } elseif ( array_key_exists( 'default', $this->settings[$setting] ) ) {
33 $retval = $this->settings[$setting]['default'];
34 } else {
35 $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 function getBool( $setting, $wiki, $suffix ) {
46 return (bool)($this->get( $setting, $wiki, $suffix ));
49 function &getLocalDatabases() {
50 return $this->localDatabases;
53 function initialise() {
54 foreach ( $this->wikis as $db ) {
55 $this->localDatabases[$db] = $db;
59 function extractVar( $setting, $wiki, $suffix, &$var, $params ) {
60 $value = $this->get( $setting, $wiki, $suffix, $params );
61 if ( !is_null( $value ) ) {
62 $var = $value;
66 function extractGlobal( $setting, $wiki, $suffix, $params ) {
67 $value = $this->get( $setting, $wiki, $suffix, $params );
68 if ( !is_null( $value ) ) {
69 $GLOBALS[$setting] = $value;
73 function extractAllGlobals( $wiki, $suffix, $params ) {
74 foreach ( $this->settings as $varName => $setting ) {
75 $this->extractGlobal( $varName, $wiki, $suffix, $params );
79 /**
80 * Work out the site and language name from a database name
81 * @param $db
83 function siteFromDB( $db ) {
84 $site = NULL;
85 $lang = NULL;
86 foreach ( $this->suffixes as $suffix ) {
87 if ( substr( $db, -strlen( $suffix ) ) == $suffix ) {
88 $site = $suffix == 'wiki' ? 'wikipedia' : $suffix;
89 $lang = substr( $db, 0, strlen( $db ) - strlen( $suffix ) );
90 break;
93 return array( $site, $lang );