Restore load position override for 'site.styles' module
[lhc/web/wiklou.git] / includes / SiteConfiguration.php
index 2f28e7b..1a92fb2 100644 (file)
  * extract( $globals );
  * @endcode
  *
- * TODO: give examples for,
+ * @todo Give examples for,
  * suffixes:
  * $conf->suffixes = array( 'wiki' );
  * localVHosts
@@ -119,22 +119,24 @@ class SiteConfiguration {
        /**
         * Array of suffixes, for self::siteFromDB()
         */
-       public $suffixes = array();
+       public $suffixes = [];
 
        /**
         * Array of wikis, should be the same as $wgLocalDatabases
         */
-       public $wikis = array();
+       public $wikis = [];
 
        /**
         * The whole array of settings
         */
-       public $settings = array();
+       public $settings = [];
 
        /**
         * Array of domains that are local and can be handled by the same server
+        *
+        * @deprecated since 1.25; use $wgLocalVirtualHosts instead.
         */
-       public $localVHosts = array();
+       public $localVHosts = [];
 
        /**
         * Optional callback to load full configuration data.
@@ -165,7 +167,7 @@ class SiteConfiguration {
         * Configuration cache for getConfig()
         * @var array
         */
-       protected $cfgCache = array();
+       protected $cfgCache = [];
 
        /**
         * Retrieves a configuration setting for a given wiki.
@@ -176,7 +178,9 @@ class SiteConfiguration {
         * @param array $wikiTags The tags assigned to the wiki.
         * @return mixed The value of the setting requested.
         */
-       public function get( $settingName, $wiki, $suffix = null, $params = array(), $wikiTags = array() ) {
+       public function get( $settingName, $wiki, $suffix = null, $params = [],
+               $wikiTags = []
+       ) {
                $params = $this->mergeParams( $wiki, $suffix, $params, $wikiTags );
                return $this->getSetting( $settingName, $wiki, $params );
        }
@@ -189,7 +193,7 @@ class SiteConfiguration {
         * @param array $params Array of parameters.
         * @return mixed The value of the setting requested.
         */
-       protected function getSetting( $settingName, $wiki, /*array*/ $params ) {
+       protected function getSetting( $settingName, $wiki, array $params ) {
                $retval = null;
                if ( array_key_exists( $settingName, $this->settings ) ) {
                        $thisSetting =& $this->settings[$settingName];
@@ -205,15 +209,15 @@ class SiteConfiguration {
                                // Do tag settings
                                foreach ( $params['tags'] as $tag ) {
                                        if ( array_key_exists( $tag, $thisSetting ) ) {
-                                               if ( isset( $retval ) && is_array( $retval ) && is_array( $thisSetting[$tag] ) ) {
+                                               if ( is_array( $retval ) && is_array( $thisSetting[$tag] ) ) {
                                                        $retval = self::arrayMerge( $retval, $thisSetting[$tag] );
                                                } else {
                                                        $retval = $thisSetting[$tag];
                                                }
                                                break 2;
                                        } elseif ( array_key_exists( "+$tag", $thisSetting ) && is_array( $thisSetting["+$tag"] ) ) {
-                                               if ( !isset( $retval ) ) {
-                                                       $retval = array();
+                                               if ( $retval === null ) {
+                                                       $retval = [];
                                                }
                                                $retval = self::arrayMerge( $retval, $thisSetting["+$tag"] );
                                        }
@@ -222,15 +226,17 @@ class SiteConfiguration {
                                $suffix = $params['suffix'];
                                if ( !is_null( $suffix ) ) {
                                        if ( array_key_exists( $suffix, $thisSetting ) ) {
-                                               if ( isset( $retval ) && is_array( $retval ) && is_array( $thisSetting[$suffix] ) ) {
+                                               if ( is_array( $retval ) && is_array( $thisSetting[$suffix] ) ) {
                                                        $retval = self::arrayMerge( $retval, $thisSetting[$suffix] );
                                                } else {
                                                        $retval = $thisSetting[$suffix];
                                                }
                                                break;
-                                       } elseif ( array_key_exists( "+$suffix", $thisSetting ) && is_array( $thisSetting["+$suffix"] ) ) {
-                                               if ( !isset( $retval ) ) {
-                                                       $retval = array();
+                                       } elseif ( array_key_exists( "+$suffix", $thisSetting )
+                                               && is_array( $thisSetting["+$suffix"] )
+                                       ) {
+                                               if ( $retval === null ) {
+                                                       $retval = [];
                                                }
                                                $retval = self::arrayMerge( $retval, $thisSetting["+$suffix"] );
                                        }
@@ -286,9 +292,9 @@ class SiteConfiguration {
         * @param array $wikiTags The tags assigned to the wiki.
         * @return array Array of settings requested.
         */
-       public function getAll( $wiki, $suffix = null, $params = array(), $wikiTags = array() ) {
+       public function getAll( $wiki, $suffix = null, $params = [], $wikiTags = [] ) {
                $params = $this->mergeParams( $wiki, $suffix, $params, $wikiTags );
-               $localSettings = array();
+               $localSettings = [];
                foreach ( $this->settings as $varname => $stuff ) {
                        $append = false;
                        $var = $varname;
@@ -316,8 +322,8 @@ class SiteConfiguration {
         * @param array $wikiTags The tags assigned to the wiki.
         * @return bool The value of the setting requested.
         */
-       public function getBool( $setting, $wiki, $suffix = null, $wikiTags = array() ) {
-               return (bool)$this->get( $setting, $wiki, $suffix, array(), $wikiTags );
+       public function getBool( $setting, $wiki, $suffix = null, $wikiTags = [] ) {
+               return (bool)$this->get( $setting, $wiki, $suffix, [], $wikiTags );
        }
 
        /**
@@ -338,7 +344,9 @@ class SiteConfiguration {
         * @param array $params List of parameters. $.'key' is replaced by $value in all returned data.
         * @param array $wikiTags The tags assigned to the wiki.
         */
-       public function extractVar( $setting, $wiki, $suffix, &$var, $params = array(), $wikiTags = array() ) {
+       public function extractVar( $setting, $wiki, $suffix, &$var,
+               $params = [], $wikiTags = []
+       ) {
                $value = $this->get( $setting, $wiki, $suffix, $params, $wikiTags );
                if ( !is_null( $value ) ) {
                        $var = $value;
@@ -353,7 +361,9 @@ class SiteConfiguration {
         * @param array $params List of parameters. $.'key' is replaced by $value in all returned data.
         * @param array $wikiTags The tags assigned to the wiki.
         */
-       public function extractGlobal( $setting, $wiki, $suffix = null, $params = array(), $wikiTags = array() ) {
+       public function extractGlobal( $setting, $wiki, $suffix = null,
+               $params = [], $wikiTags = []
+       ) {
                $params = $this->mergeParams( $wiki, $suffix, $params, $wikiTags );
                $this->extractGlobalSetting( $setting, $wiki, $params );
        }
@@ -386,7 +396,9 @@ class SiteConfiguration {
         * @param array $params List of parameters. $.'key' is replaced by $value in all returned data.
         * @param array $wikiTags The tags assigned to the wiki.
         */
-       public function extractAllGlobals( $wiki, $suffix = null, $params = array(), $wikiTags = array() ) {
+       public function extractAllGlobals( $wiki, $suffix = null, $params = [],
+               $wikiTags = []
+       ) {
                $params = $this->mergeParams( $wiki, $suffix, $params, $wikiTags );
                foreach ( $this->settings as $varName => $setting ) {
                        $this->extractGlobalSetting( $varName, $wiki, $params );
@@ -402,18 +414,18 @@ class SiteConfiguration {
         * @return array
         */
        protected function getWikiParams( $wiki ) {
-               static $default = array(
+               static $default = [
                        'suffix' => null,
                        'lang' => null,
-                       'tags' => array(),
-                       'params' => array(),
-               );
+                       'tags' => [],
+                       'params' => [],
+               ];
 
                if ( !is_callable( $this->siteParamsCallback ) ) {
                        return $default;
                }
 
-               $ret = call_user_func_array( $this->siteParamsCallback, array( $this, $wiki ) );
+               $ret = call_user_func_array( $this->siteParamsCallback, [ $this, $wiki ] );
                # Validate the returned value
                if ( !is_array( $ret ) ) {
                        return $default;
@@ -440,7 +452,7 @@ class SiteConfiguration {
         * @param array $wikiTags The tags assigned to the wiki.
         * @return array
         */
-       protected function mergeParams( $wiki, $suffix, /*array*/ $params, /*array*/ $wikiTags ) {
+       protected function mergeParams( $wiki, $suffix, array $params, array $wikiTags ) {
                $ret = $this->getWikiParams( $wiki );
 
                if ( is_null( $ret['suffix'] ) ) {
@@ -472,7 +484,7 @@ class SiteConfiguration {
                // Allow override
                $def = $this->getWikiParams( $db );
                if ( !is_null( $def['suffix'] ) && !is_null( $def['lang'] ) ) {
-                       return array( $def['suffix'], $def['lang'] );
+                       return [ $def['suffix'], $def['lang'] ];
                }
 
                $site = null;
@@ -489,7 +501,7 @@ class SiteConfiguration {
                        }
                }
                $lang = str_replace( '_', '-', $lang );
-               return array( $site, $lang );
+               return [ $site, $lang ];
        }
 
        /**
@@ -509,7 +521,7 @@ class SiteConfiguration {
                $multi = is_array( $settings );
                $settings = (array)$settings;
                if ( $wiki === wfWikiID() ) { // $wiki is this wiki
-                       $res = array();
+                       $res = [];
                        foreach ( $settings as $name ) {
                                if ( !preg_match( '/^wg[A-Z]/', $name ) ) {
                                        throw new MWException( "Variable '$name' does start with 'wg'." );
@@ -522,24 +534,24 @@ class SiteConfiguration {
                        if ( isset( $this->cfgCache[$wiki] ) ) {
                                $res = array_intersect_key( $this->cfgCache[$wiki], array_flip( $settings ) );
                                if ( count( $res ) == count( $settings ) ) {
-                                       return $res; // cache hit
+                                       return $multi ? $res : current( $res ); // cache hit
                                }
                        } elseif ( !in_array( $wiki, $this->wikis ) ) {
                                throw new MWException( "No such wiki '$wiki'." );
                        } else {
-                               $this->cfgCache[$wiki] = array();
+                               $this->cfgCache[$wiki] = [];
                        }
                        $retVal = 1;
                        $cmd = wfShellWikiCmd(
                                "$IP/maintenance/getConfiguration.php",
-                               array(
+                               [
                                        '--wiki', $wiki,
                                        '--settings', implode( ' ', $settings ),
                                        '--format', 'PHP'
-                               )
+                               ]
                        );
                        // ulimit5.sh breaks this call
-                       $data = trim( wfShellExec( $cmd, $retVal, array(), array( 'memory' => 0 ) ) );
+                       $data = trim( wfShellExec( $cmd, $retVal, [], [ 'memory' => 0 ] ) );
                        if ( $retVal != 0 || !strlen( $data ) ) {
                                throw new MWException( "Failed to run getConfiguration.php." );
                        }
@@ -555,6 +567,8 @@ class SiteConfiguration {
 
        /**
         * Returns true if the given vhost is handled locally.
+        *
+        * @deprecated since 1.25; check if the host is in $wgLocalVirtualHosts instead.
         * @param string $vhost
         * @return bool
         */
@@ -574,12 +588,14 @@ class SiteConfiguration {
         */
        static function arrayMerge( $array1/* ... */ ) {
                $out = $array1;
-               for ( $i = 1; $i < func_num_args(); $i++ ) {
+               $argsCount = func_num_args();
+               for ( $i = 1; $i < $argsCount; $i++ ) {
                        foreach ( func_get_arg( $i ) as $key => $value ) {
                                if ( isset( $out[$key] ) && is_array( $out[$key] ) && is_array( $value ) ) {
                                        $out[$key] = self::arrayMerge( $out[$key], $value );
                                } elseif ( !isset( $out[$key] ) || !$out[$key] && !is_numeric( $key ) ) {
-                                       // Values that evaluate to true given precedence, for the primary purpose of merging permissions arrays.
+                                       // Values that evaluate to true given precedence, for the
+                                       // primary purpose of merging permissions arrays.
                                        $out[$key] = $value;
                                } elseif ( is_numeric( $key ) ) {
                                        $out[] = $value;