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.
9 // Hide this pattern from Doxygen, which spazzes out at it
11 if (!defined('SITE_CONFIGURATION')) {
12 define('SITE_CONFIGURATION', 1);
16 * This is a class used to hold configuration settings, particularly for multi-wiki sites.
19 class SiteConfiguration
{
20 var $suffixes = array();
22 var $settings = array();
23 var $localVHosts = array();
26 function get( $settingName, $wiki, $suffix, $params = array(), $wikiTags = array() ) {
27 if ( array_key_exists( $settingName, $this->settings
) ) {
28 $thisSetting =& $this->settings
[$settingName];
30 if ( array_key_exists( $wiki, $thisSetting ) ) {
31 $retval = $thisSetting[$wiki];
34 foreach ( $wikiTags as $tag ) {
35 if ( array_key_exists( $tag, $thisSetting ) ) {
36 $retval = $thisSetting[$tag];
40 if ( array_key_exists( $suffix, $thisSetting ) ) {
41 $retval = $thisSetting[$suffix];
44 if ( array_key_exists( 'default', $thisSetting ) ) {
45 $retval = $thisSetting['default'];
54 if ( !is_null( $retval ) && count( $params ) ) {
55 foreach ( $params as $key => $value ) {
56 $retval = $this->doReplace( '$' . $key, $value, $retval );
62 /** Type-safe string replace; won't do replacements on non-strings */
63 function doReplace( $from, $to, $in ) {
64 if( is_string( $in ) ) {
65 return str_replace( $from, $to, $in );
66 } elseif( is_array( $in ) ) {
67 foreach( $in as $key => $val ) {
68 $in[$key] = $this->doReplace( $from, $to, $val );
77 function getAll( $wiki, $suffix, $params, $wikiTags = array() ) {
78 $localSettings = array();
79 foreach ( $this->settings
as $varname => $stuff ) {
80 $value = $this->get( $varname, $wiki, $suffix, $params, $wikiTags );
81 if ( !is_null( $value ) ) {
82 $localSettings[$varname] = $value;
85 return $localSettings;
89 function getBool( $setting, $wiki, $suffix, $wikiTags = array() ) {
90 return (bool)($this->get( $setting, $wiki, $suffix, array(), $wikiTags ) );
94 function &getLocalDatabases() {
99 function initialise() {
103 function extractVar( $setting, $wiki, $suffix, &$var, $params, $wikiTags = array() ) {
104 $value = $this->get( $setting, $wiki, $suffix, $params, $wikiTags );
105 if ( !is_null( $value ) ) {
111 function extractGlobal( $setting, $wiki, $suffix, $params, $wikiTags = array() ) {
112 $value = $this->get( $setting, $wiki, $suffix, $params, $wikiTags );
113 if ( !is_null( $value ) ) {
114 $GLOBALS[$setting] = $value;
119 function extractAllGlobals( $wiki, $suffix, $params, $wikiTags = array() ) {
120 foreach ( $this->settings
as $varName => $setting ) {
121 $this->extractGlobal( $varName, $wiki, $suffix, $params, $wikiTags );
126 * Work out the site and language name from a database name
129 function siteFromDB( $db ) {
132 foreach ( $this->suffixes
as $suffix ) {
133 if ( $suffix === '' ) {
137 } elseif ( substr( $db, -strlen( $suffix ) ) == $suffix ) {
138 $site = $suffix == 'wiki' ?
'wikipedia' : $suffix;
139 $lang = substr( $db, 0, strlen( $db ) - strlen( $suffix ) );
143 $lang = str_replace( '_', '-', $lang );
144 return array( $site, $lang );
148 function isLocalVHost( $vhost ) {
149 return in_array( $vhost, $this->localVHosts
);