From 5a2a85a1b4e19167d28c2302f24e963f440ebb95 Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Wed, 20 Aug 2008 14:12:52 +0000 Subject: [PATCH] *ahem* self-revert. Something weird happened with getAll() --- includes/GlobalFunctions.php | 22 ------------------ includes/SiteConfiguration.php | 42 +++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 40 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 25327e6f19..dabe06d53b 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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. */ diff --git a/includes/SiteConfiguration.php b/includes/SiteConfiguration.php index 49291e2040..9d091097f1 100644 --- a/includes/SiteConfiguration.php +++ b/includes/SiteConfiguration.php @@ -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; + } } } -- 2.20.1