* (bug 20336) changed json_decode json_encode to static class in global functions
[lhc/web/wiklou.git] / includes / SiteConfiguration.php
index 3910bdb..b6d8367 100644 (file)
@@ -26,7 +26,7 @@ class SiteConfiguration {
         * Array of wikis, should be the same as $wgLocalDatabases
         */
        public $wikis = array();
-       
+
        /**
         * The whole array of settings
         */
@@ -36,6 +36,14 @@ class SiteConfiguration {
         * Array of domains that are local and can be handled by the same server
         */
        public $localVHosts = array();
+       
+       /**
+        * Optional callback to load full configuration data.
+        */
+       public $fullLoadCallback = null;
+       
+       /** Whether or not all data has been loaded */
+       public $fullLoadDone = false;
 
        /**
         * A callback function that returns an array with the following keys (all
@@ -64,7 +72,7 @@ class SiteConfiguration {
                $params = $this->mergeParams( $wiki, $suffix, $params, $wikiTags );
                return $this->getSetting( $settingName, $wiki, $params );
        }
-       
+
        /**
         * Really retrieves a configuration setting for a given wiki.
         *
@@ -85,7 +93,7 @@ class SiteConfiguration {
                                } elseif( array_key_exists( "+$wiki", $thisSetting ) && is_array( $thisSetting["+$wiki"] ) ) {
                                        $retval = $thisSetting["+$wiki"];
                                }
-                               
+
                                // Do tag settings
                                foreach( $params['tags'] as $tag ) {
                                        if( array_key_exists( $tag, $thisSetting ) ) {
@@ -117,7 +125,7 @@ class SiteConfiguration {
                                                $retval = self::arrayMerge( $retval, $thisSetting["+$suffix"] );
                                        }
                                }
-                               
+
                                // Fall back to default.
                                if( array_key_exists( 'default', $thisSetting ) ) {
                                        if( is_array( $retval ) && is_array( $thisSetting['default'] ) ) {
@@ -293,7 +301,7 @@ class SiteConfiguration {
                        if( !isset( $ret[$name] ) || ( is_array( $default[$name] ) && !is_array( $ret[$name] ) ) )
                                $ret[$name] = $default[$name];
                }
-               
+
                return $ret;
        }
 
@@ -317,19 +325,14 @@ class SiteConfiguration {
 
                $ret['tags'] = array_unique( array_merge( $ret['tags'], $wikiTags ) );
 
+               $ret['params'] += $params;
+
                // Automatically fill that ones if needed
                if( !isset( $ret['params']['lang'] ) && !is_null( $ret['lang'] ) )
                        $ret['params']['lang'] = $ret['lang'];
                if( !isset( $ret['params']['site'] ) && !is_null( $ret['suffix'] ) )
                        $ret['params']['site'] = $ret['suffix'];
-       
-               $ret['params'] += $params;
-               /*echo "$wiki<br/>\n";
-               var_dump( $ret );
-               echo "<br/>\n";
-               foreach( debug_backtrace() as $row )
-               echo "File: {$row['file']} Line: {$row['line']}<br/>\n";
-               echo "<br/>\n";*/
+
                return $ret;
        }
 
@@ -339,7 +342,7 @@ class SiteConfiguration {
         */
        public function siteFromDB( $db ) {
                // Allow override
-               $def = $this->getWikiParams( $db );             
+               $def = $this->getWikiParams( $db );
                if( !is_null( $def['suffix'] ) && !is_null( $def['lang'] ) )
                        return array( $def['suffix'], $def['lang'] );
 
@@ -368,7 +371,7 @@ class SiteConfiguration {
        public function isLocalVHost( $vhost ) {
                return in_array( $vhost, $this->localVHosts );
        }
-       
+
        /**
         * Merge multiple arrays together.
         * On encountering duplicate keys, merge the two, but ONLY if they're arrays.
@@ -389,8 +392,15 @@ class SiteConfiguration {
                                }
                        }
                }
-       
+
                return $out;
        }
+       
+       public function loadFullData() {
+               if ($this->fullLoadCallback && !$this->fullLoadDone) {
+                       call_user_func( $this->fullLoadCallback, $this );
+                       $this->fullLoadDone = true;
+               }
+       }
 }
-}
+} // End of multiple inclusion guard