Allowed array-merging for site config. You can now set a setting for '+whatever'...
authorAndrew Garrett <werdna@users.mediawiki.org>
Mon, 18 Aug 2008 09:26:48 +0000 (09:26 +0000)
committerAndrew Garrett <werdna@users.mediawiki.org>
Mon, 18 Aug 2008 09:26:48 +0000 (09:26 +0000)
includes/SiteConfiguration.php

index 73aae1a..88d4133 100644 (file)
@@ -22,27 +22,64 @@ class SiteConfiguration {
        var $settings = array();
        var $localVHosts = array();
 
-       /** */
+       /**
+        * Retrieves a configuration setting for a given wiki.
+        * @param $settingName 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 Mixed the value of the setting requested.
+        */
        function get( $settingName, $wiki, $suffix, $params = array(), $wikiTags = array() ) {
                if ( array_key_exists( $settingName, $this->settings ) ) {
                        $thisSetting =& $this->settings[$settingName];
                        do {
+                               // Do individual wiki settings
                                if ( array_key_exists( $wiki, $thisSetting ) ) {
                                        $retval = $thisSetting[$wiki];
                                        break;
+                               } elseif ( array_key_exists( "+$wiki", $thisSetting ) && is_array($thisSetting["+$wiki"]) ) {
+                                       $retval = $thisSetting["+$wiki"];
                                }
+                               
+                               // Do tag settings
                                foreach ( $wikiTags as $tag ) {
                                        if ( array_key_exists( $tag, $thisSetting ) ) {
-                                               $retval = $thisSetting[$tag];
+                                               if ( is_array($retval) && is_array($thisSetting[$tag]) ) {
+                                                       $retval = array_merge( $retval, $thisSetting[$tag] );
+                                               } else {
+                                                       $retval = $thisSetting[$tag];
+                                               }
                                                break 2;
+                                       } elseif ( array_key_exists( "+$tag", $thisSetting ) && is_array($thisSetting["+$tag"]) ) {
+                                               if (!isset($retval))
+                                                       $retval = array();
+                                               $retval = array_merge( $retval, $thisSetting["+$tag"] );
                                        }
                                }
+                               
+                               // Do suffix settings
                                if ( array_key_exists( $suffix, $thisSetting ) ) {
-                                       $retval = $thisSetting[$suffix];
+                                       if ( is_array($retval) && is_array($thisSetting[$suffix]) ) {
+                                               $retval = array_merge( $retval, $thisSetting[$suffix] );
+                                       } else {
+                                               $retval = $thisSetting[$suffix];
+                                       }
                                        break;
+                               } elseif ( array_key_exists( "+$suffix", $thisSetting ) && is_array($thisSetting["+$suffix"]) ) {
+                                       if (!isset($retval))
+                                               $retval = array();
+                                       $retval = array_merge( $retval, $thisSetting["+$suffix"] );
                                }
+                               
+                               // Fall back to default.
                                if ( array_key_exists( 'default', $thisSetting ) ) {
-                                       $retval = $thisSetting['default'];
+                                       if ( is_array($retval) && is_array($thisSetting['default']) ) {
+                                               $retval = array_merge( $retval, $thisSetting['default'] );
+                                       } else {
+                                               $retval = $thisSetting['default'];
+                                       }
                                        break;
                                }
                                $retval = null;
@@ -73,7 +110,14 @@ class SiteConfiguration {
                }
        }
 
-       /** */
+       /**
+        * Gets all settings for a wiki
+        * @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 Array Array of settings requested.
+        */
        function getAll( $wiki, $suffix, $params, $wikiTags = array() ) {
                $localSettings = array();
                foreach ( $this->settings as $varname => $stuff ) {
@@ -85,21 +129,37 @@ class SiteConfiguration {
                return $localSettings;
        }
 
-       /** */
+       /**
+        * Retrieves a configuration setting for a given wiki, forced to a boolean.
+        * @param $settingName 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.
+        */
        function getBool( $setting, $wiki, $suffix, $wikiTags = array() ) {
                return (bool)($this->get( $setting, $wiki, $suffix, array(), $wikiTags ) );
        }
 
-       /** */
+       /** Retrieves an array of local databases */
        function &getLocalDatabases() {
                return $this->wikis;
        }
 
-       /** */
+       /** A no-op */
        function initialise() {
        }
 
-       /** */
+       /**
+        * 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 $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.
+        * @param $params Array List of parameters. $.'key' is replaced by $value in all returned data.
+        * @param $wikiTags Array The tags assigned to the wiki.
+        */
        function extractVar( $setting, $wiki, $suffix, &$var, $params, $wikiTags = array() ) {
                $value = $this->get( $setting, $wiki, $suffix, $params, $wikiTags );
                if ( !is_null( $value ) ) {
@@ -107,7 +167,14 @@ 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 $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.
+        */
        function extractGlobal( $setting, $wiki, $suffix, $params, $wikiTags = array() ) {
                $value = $this->get( $setting, $wiki, $suffix, $params, $wikiTags );
                if ( !is_null( $value ) ) {
@@ -115,7 +182,13 @@ class SiteConfiguration {
                }
        }
 
-       /** */
+       /**
+        * Retrieves the values of all settings, and places them in their corresponding global variables.
+        * @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.
+        */
        function extractAllGlobals( $wiki, $suffix, $params, $wikiTags = array() ) {
                foreach ( $this->settings as $varName => $setting ) {
                        $this->extractGlobal( $varName, $wiki, $suffix, $params, $wikiTags );
@@ -144,7 +217,7 @@ class SiteConfiguration {
                return array( $site, $lang );
        }
 
-       /** */
+       /** Returns true if the given vhost is handled locally. */
        function isLocalVHost( $vhost ) {
                return in_array( $vhost, $this->localVHosts );
        }