* Removed exifReader.inc and added a function which does roughly the same
[lhc/web/wiklou.git] / includes / SiteConfiguration.php
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.
6 *
7 * @package MediaWiki
8 */
9
10 /**
11 *
12 * @package MediaWiki
13 */
14
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.
19 */
20 if (!defined('SITE_CONFIGURATION')) {
21 define('SITE_CONFIGURATION', 1);
22
23 class SiteConfiguration {
24 var $suffixes, $wikis, $settings;
25 var $localDatabases;
26
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;
36 }
37 if ( !is_null( $retval ) && count( $params ) ) {
38 foreach ( $params as $key => $value ) {
39 $retval = str_replace( '$' . $key, $value, $retval );
40 }
41 }
42 return $retval;
43 }
44
45 function getBool( $setting, $wiki, $suffix ) {
46 return (bool)($this->get( $setting, $wiki, $suffix ));
47 }
48
49 function &getLocalDatabases() {
50 return $this->localDatabases;
51 }
52
53 function initialise() {
54 foreach ( $this->wikis as $db ) {
55 $this->localDatabases[$db] = $db;
56 }
57 }
58
59 function extractVar( $setting, $wiki, $suffix, &$var, $params ) {
60 $value = $this->get( $setting, $wiki, $suffix, $params );
61 if ( !is_null( $value ) ) {
62 $var = $value;
63 }
64 }
65
66 function extractGlobal( $setting, $wiki, $suffix, $params ) {
67 $value = $this->get( $setting, $wiki, $suffix, $params );
68 if ( !is_null( $value ) ) {
69 $GLOBALS[$setting] = $value;
70 }
71 }
72
73 function extractAllGlobals( $wiki, $suffix, $params ) {
74 foreach ( $this->settings as $varName => $setting ) {
75 $this->extractGlobal( $varName, $wiki, $suffix, $params );
76 }
77 }
78
79 /**
80 * Work out the site and language name from a database name
81 * @param $db
82 */
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;
91 }
92 }
93 return array( $site, $lang );
94 }
95 }
96 }
97
98 ?>