*ahem* self-revert. Something weird happened with getAll()
authorAndrew Garrett <werdna@users.mediawiki.org>
Wed, 20 Aug 2008 14:12:52 +0000 (14:12 +0000)
committerAndrew Garrett <werdna@users.mediawiki.org>
Wed, 20 Aug 2008 14:12:52 +0000 (14:12 +0000)
includes/GlobalFunctions.php
includes/SiteConfiguration.php

index 25327e6..dabe06d 100644 (file)
@@ -2242,28 +2242,6 @@ function wfArrayMerge( $array1/* ... */ ) {
        return $out;
 }
 
-/**
- * Merge multiple arrays together.
- * On encountering duplicate keys, merge the two, but ONLY if they're arrays.
- * PHP's array_merge_recursive() merges ANY duplicate values into arrays,
- * which is not fun
- */
-function wfArrayDeepMerge( $array1/* ... */ ) {
-       $out = $array1;
-       for( $i=1; $i< func_num_args(); $i++ ) {
-               foreach( func_get_arg( $i ) as $key => $value ) {
-                       if ( isset($out[$key]) && is_array($out[$key]) && is_array($value) ) {
-                               $out[$key] = wfArrayDeepMerge( $out[$key], $value );
-                       } elseif ( !isset($out[$key] || !$out[$key] ) {
-                               // Values that evaluate to true given precedence, for the primary purpose of merging permissions arrays.
-                               $out[$key] = $value;
-                       }
-               }
-       }
-       
-       return $out;
-}
-
 /**
  * Make a URL index, appropriate for the el_index field of externallinks.
  */
index 49291e2..9d09109 100644 (file)
@@ -32,13 +32,6 @@ class SiteConfiguration {
         * @return Mixed the value of the setting requested.
         */
        function get( $settingName, $wiki, $suffix, $params = array(), $wikiTags = array() ) {
-               $append = false;
-               $var = $settingName;
-               if ( substr( $varname, 0, 1 ) == '+' ) {
-                       $append = true;
-                       $var = substr( $settingName, 1 );
-               }
-       
                if ( array_key_exists( $settingName, $this->settings ) ) {
                        $thisSetting =& $this->settings[$settingName];
                        do {
@@ -54,7 +47,7 @@ class SiteConfiguration {
                                foreach ( $wikiTags as $tag ) {
                                        if ( array_key_exists( $tag, $thisSetting ) ) {
                                                if ( isset($retval) && is_array($retval) && is_array($thisSetting[$tag]) ) {
-                                                       $retval = wfArrayDeepMerge( $retval, $thisSetting[$tag] );
+                                                       $retval = array_merge( $retval, $thisSetting[$tag] );
                                                } else {
                                                        $retval = $thisSetting[$tag];
                                                }
@@ -62,14 +55,14 @@ class SiteConfiguration {
                                        } elseif ( array_key_exists( "+$tag", $thisSetting ) && is_array($thisSetting["+$tag"]) ) {
                                                if (!isset($retval))
                                                        $retval = array();
-                                               $retval = wfArrayDeepMerge( $retval, $thisSetting["+$tag"] );
+                                               $retval = array_merge( $retval, $thisSetting["+$tag"] );
                                        }
                                }
                                
                                // Do suffix settings
                                if ( array_key_exists( $suffix, $thisSetting ) ) {
                                        if ( isset($retval) && is_array($retval) && is_array($thisSetting[$suffix]) ) {
-                                               $retval = wfArrayDeepMerge( $retval, $thisSetting[$suffix] );
+                                               $retval = array_merge( $retval, $thisSetting[$suffix] );
                                        } else {
                                                $retval = $thisSetting[$suffix];
                                        }
@@ -77,13 +70,13 @@ class SiteConfiguration {
                                } elseif ( array_key_exists( "+$suffix", $thisSetting ) && is_array($thisSetting["+$suffix"]) ) {
                                        if (!isset($retval))
                                                $retval = array();
-                                       $retval = wfArrayDeepMerge( $retval, $thisSetting["+$suffix"] );
+                                       $retval = array_merge( $retval, $thisSetting["+$suffix"] );
                                }
                                
                                // Fall back to default.
                                if ( array_key_exists( 'default', $thisSetting ) ) {
                                        if ( isset($retval) && is_array($retval) && is_array($thisSetting['default']) ) {
-                                               $retval = wfArrayDeepMerge( $retval, $thisSetting['default'] );
+                                               $retval = array_merge( $retval, $thisSetting['default'] );
                                        } else {
                                                $retval = $thisSetting['default'];
                                        }
@@ -100,10 +93,6 @@ class SiteConfiguration {
                                $retval = $this->doReplace( '$' . $key, $value, $retval );
                        }
                }
-               
-               if ( $append && is_array($value) && is_array( $GLOBALS[$var] ) )
-                       $value = wfArrayDeepMerge( $value, $GLOBALS[$var] );
-                               
                return $retval;
        }
 
@@ -132,8 +121,16 @@ class SiteConfiguration {
        function getAll( $wiki, $suffix, $params, $wikiTags = array() ) {
                $localSettings = array();
                foreach ( $this->settings as $varname => $stuff ) {
+                       $append = false;
+                       $var = $varname;
+                       if ( substr( $varname, 0, 1 ) == '+' ) {
+                               $append = true;
+                               $var = substr( $varname, 1 );
+                       }
+                       
                        $value = $this->get( $varname, $wiki, $suffix, $params, $wikiTags );
-
+                       if ( $append && is_array($value) && is_array( $GLOBALS[$var] ) )
+                               $value = array_merge( $value, $GLOBALS[$var] );
                        if ( !is_null( $value ) ) {
                                $localSettings[$var] = $value;
                        }
@@ -190,7 +187,16 @@ class SiteConfiguration {
        function extractGlobal( $setting, $wiki, $suffix, $params, $wikiTags = array() ) {
                $value = $this->get( $setting, $wiki, $suffix, $params, $wikiTags );
                if ( !is_null( $value ) ) {
-                       $GLOBALS[$setting] = $value;
+                       if (substr($setting,0,1) == '+' && is_array($value)) {
+                               $setting = substr($setting,1);
+                               if ( is_array($GLOBALS[$setting]) ) {
+                                       $GLOBALS[$setting] = array_merge( $GLOBALS[$setting], $value );
+                               } else {
+                                       $GLOBALS[$setting] = $value;
+                               }
+                       } else {
+                               $GLOBALS[$setting] = $value;
+                       }
                }
        }