Fix bug 26570 (user CSS preview broken) and bug 26555 (styles added with $out->addSty...
[lhc/web/wiklou.git] / includes / SiteConfiguration.php
index 25c289f..f4a4576 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'] ) ) {
@@ -186,10 +194,9 @@ class SiteConfiguration {
 
        /**
         * Retrieves a configuration setting for a given wiki, forced to a boolean.
-        * @param $settingName String ID of the setting name to retrieve
+        * @param $setting String ID of the setting name to retrieve
         * @param $wiki String Wiki ID of the wiki in question.
         * @param $suffix String The suffix of the wiki in question.
-        * @param $params Array List of parameters. $.'key' is replaced by $value in all returned data.
         * @param $wikiTags Array The tags assigned to the wiki.
         * @return bool The value of the setting requested.
         */
@@ -208,7 +215,7 @@ class SiteConfiguration {
 
        /**
         * Retrieves the value of a given setting, and places it in a variable passed by reference.
-        * @param $settingName String ID of the setting name to retrieve
+        * @param $setting String ID of the setting name to retrieve
         * @param $wiki String Wiki ID of the wiki in question.
         * @param $suffix String The suffix of the wiki in question.
         * @param $var Reference The variable to insert the value into.
@@ -224,7 +231,7 @@ class SiteConfiguration {
 
        /**
         * Retrieves the value of a given setting, and places it in its corresponding global variable.
-        * @param $settingName String ID of the setting name to retrieve
+        * @param $setting String ID of the setting name to retrieve
         * @param $wiki String Wiki ID of the wiki in question.
         * @param $suffix String The suffix of the wiki in question.
         * @param $params Array List of parameters. $.'key' is replaced by $value in all returned data.
@@ -286,14 +293,15 @@ class SiteConfiguration {
 
                $ret = call_user_func_array( $this->siteParamsCallback, array( $this, $wiki ) );
                # Validate the returned value
-               if( !is_array( $ret ) )
+               if( !is_array( $ret ) ) {
                        return $default;
+               }
 
                foreach( $default as $name => $def ){
                        if( !isset( $ret[$name] ) || ( is_array( $default[$name] ) && !is_array( $ret[$name] ) ) )
                                $ret[$name] = $default[$name];
                }
-               
+
                return $ret;
        }
 
@@ -317,13 +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;
+
                return $ret;
        }
 
@@ -333,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'] );
 
@@ -362,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.
@@ -383,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