* (bug 1368) Fix SQL error on stopword/short word search w/ MySQL 3.x
[lhc/web/wiklou.git] / includes / SiteConfiguration.php
index d717129..1abe48d 100644 (file)
@@ -1,28 +1,45 @@
 <?php
+/**
+ *This file is used to configure the live Wikimedia wikis. The file that
+ * includes it contains passwords and other sensitive data, and there's
+ * currently no public equivalent.
+ *
+ * @package MediaWiki
+ */
 
-# This file is used to configure the live Wikimedia wikis. The file that includes
-# it contains passwords and other sensitive data, and there's currently no public
-# equivalent. 
+/**
+ *
+ * @package MediaWiki
+ */
+
+/**
+ * The include paths change after this file is included from commandLine.inc, 
+ * meaning that require_once() fails to detect that it is including the same
+ * file again. We use DIY C-style protection as a workaround.
+ */
+if (!defined('SITE_CONFIGURATION')) {
+define('SITE_CONFIGURATION', 1);
 
 class SiteConfiguration {
        var $suffixes, $wikis, $settings;
        var $localDatabases;
        
        function get( $setting, $wiki, $suffix, $params = array() ) {
-               if ( array_key_exists( $this->settings[$setting], $wiki ) ) {
+               if ( array_key_exists( $wiki, $this->settings[$setting] ) ) {
                        $retval = $this->settings[$setting][$wiki];
-               } elseif ( array_key_exists( $this->settings[$setting], $suffix ) ) {
+               } elseif ( array_key_exists( $suffix, $this->settings[$setting] ) ) {
                        $retval = $this->settings[$setting][$suffix];
-               } elseif ( array_key_exists( $this->settings[$setting], "default" ) ) {
+               } elseif ( array_key_exists( 'default', $this->settings[$setting] ) ) {
                        $retval = $this->settings[$setting]['default'];
                } else {
                        $retval = NULL;
                }
                if ( !is_null( $retval ) && count( $params ) ) {
                        foreach ( $params as $key => $value ) {
-                               str_replace( "\${$key}", $value, $retval );
+                               $retval = str_replace( '$' . $key, $value, $retval );
                        }
                }
+               return $retval;
        }
 
        function getBool( $setting, $wiki, $suffix ) {
@@ -30,7 +47,7 @@ class SiteConfiguration {
        }
 
        function &getLocalDatabases() {
-               return $this->localDatabases();
+               return $this->localDatabases;
        }
        
        function initialise() {
@@ -39,26 +56,43 @@ class SiteConfiguration {
                }
        }
 
-       function extractVar( $setting, $wiki, $suffix, &$var, &$params ) {
-               $value = $this->get( $settings, $wiki, $suffix, $params );
+       function extractVar( $setting, $wiki, $suffix, &$var, $params ) {
+               $value = $this->get( $setting, $wiki, $suffix, $params );
                if ( !is_null( $value ) ) {
                        $var = $value;
                }
        }
        
-       function extractGlobal( $setting, $wiki, $suffix, &$params ) {
-               $value = $this->get( $settings, $wiki, $suffix, $params );
+       function extractGlobal( $setting, $wiki, $suffix, $params ) {
+               $value = $this->get( $setting, $wiki, $suffix, $params );
                if ( !is_null( $value ) ) {
                        $GLOBALS[$setting] = $value;
                }
        }
 
-       function extractAllGlobals( $wiki, $suffix, &$params ) {
-               foreach ( $settings as $varName => $setting ) {
+       function extractAllGlobals( $wiki, $suffix, $params ) {
+               foreach ( $this->settings as $varName => $setting ) {
                        $this->extractGlobal( $varName, $wiki, $suffix, $params );
                }
        }
-}
 
+       /**
+        * Work out the site and language name from a database name
+        * @param $db
+        */
+       function siteFromDB( $db ) {
+               $site = NULL;
+               $lang = NULL;
+               foreach ( $this->suffixes as $suffix ) {
+                       if ( substr( $db, -strlen( $suffix ) ) == $suffix ) {
+                               $site = $suffix == 'wiki' ? 'wikipedia' : $suffix;
+                               $lang = substr( $db, 0, strlen( $db ) - strlen( $suffix ) );
+                               break;
+                       }
+               }
+               return array( $site, $lang );
+       }
+}
+}
        
 ?>