X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSiteConfiguration.php;h=8d9256b81145a5fd2e4deecf10fefe17586f549d;hb=bab359434217e9aca1ab0e4b5abf4b94bbd8c60b;hp=c3b1a6ac7ff8aa97ed15985e028c8e7a610b1228;hpb=04fdc78370dbc042116488d6826e19bf3910273b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SiteConfiguration.php b/includes/SiteConfiguration.php index c3b1a6ac7f..8d9256b811 100644 --- a/includes/SiteConfiguration.php +++ b/includes/SiteConfiguration.php @@ -36,15 +36,15 @@ * * @code * $conf = new SiteConfiguration; - * $conf->wikis = array( 'de', 'en', 'beta' ); + * $conf->wikis = [ 'de', 'en', 'beta' ]; * @endcode * * When configuring the MediaWiki global settings (the $wg variables), * the identifiers will be available to specify settings on a per wiki basis. * * @code - * $conf->settings = array( - * 'wgSomeSetting' => array( + * $conf->settings = [ + * 'wgSomeSetting' => [ * * # production: * 'de' => false, @@ -52,8 +52,8 @@ * * # test: * 'beta => true, - * ), - * ); + * ], + * ]; * @endcode * * With three wikis, that is easy to manage. But what about a farm with @@ -62,15 +62,15 @@ * the above code could be written: * * @code - * $conf->settings = array( - * 'wgSomeSetting' => array( + * $conf->settings = [ + * 'wgSomeSetting' => [ * * 'default' => false, * * # Enable feature on test * 'beta' => true, - * ), - * ); + * ], + * ]; * @endcode * * @@ -80,23 +80,23 @@ * on a per wiki basis. * * @code - * $conf->settings = array( - * 'wgMergeSetting' = array( + * $conf->settings = [ + * 'wgMergeSetting' = [ * # Value that will be shared among all wikis: - * 'default' => array( NS_USER => true ), + * 'default' => [ NS_USER => true ], * * # Leading '+' means merging the array of value with the defaults - * '+beta' => array( NS_HELP => true ), - * ), - * ); + * '+beta' => [ NS_HELP => true ], + * ], + * ]; * * # Get configuration for the German site: * $conf->get( 'wgMergeSetting', 'de' ); - * // --> array( NS_USER => true ); + * // --> [ NS_USER => true ]; * * # Get configuration for the testing site: * $conf->get( 'wgMergeSetting', 'beta' ); - * // --> array( NS_USER => true, NS_HELP => true ); + * // --> [ NS_USER => true, NS_HELP => true ]; * @endcode * * Finally, to load all configuration settings, extract them in global context: @@ -108,9 +108,14 @@ * extract( $globals ); * @endcode * + * @note For WikiMap to function, the configuration must define string values for + * $wgServer (or $wgCanonicalServer) and $wgArticlePath, even if these are the + * same for all wikis or can be correctly determined by the logic in + * Setup.php. + * * @todo Give examples for, * suffixes: - * $conf->suffixes = array( 'wiki' ); + * $conf->suffixes = [ 'wiki' ]; * localVHosts * callbacks! */ @@ -119,24 +124,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. @@ -167,7 +172,7 @@ class SiteConfiguration { * Configuration cache for getConfig() * @var array */ - protected $cfgCache = array(); + protected $cfgCache = []; /** * Retrieves a configuration setting for a given wiki. @@ -178,8 +183,8 @@ 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 ); @@ -217,7 +222,7 @@ class SiteConfiguration { break 2; } elseif ( array_key_exists( "+$tag", $thisSetting ) && is_array( $thisSetting["+$tag"] ) ) { if ( $retval === null ) { - $retval = array(); + $retval = []; } $retval = self::arrayMerge( $retval, $thisSetting["+$tag"] ); } @@ -236,7 +241,7 @@ class SiteConfiguration { && is_array( $thisSetting["+$suffix"] ) ) { if ( $retval === null ) { - $retval = array(); + $retval = []; } $retval = self::arrayMerge( $retval, $thisSetting["+$suffix"] ); } @@ -269,7 +274,7 @@ class SiteConfiguration { * @param string $from * @param string $to * @param string|array $in - * @return string + * @return string|array */ function doReplace( $from, $to, $in ) { if ( is_string( $in ) ) { @@ -292,9 +297,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; @@ -322,8 +327,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 ); } /** @@ -345,7 +350,7 @@ class SiteConfiguration { * @param array $wikiTags The tags assigned to the wiki. */ public function extractVar( $setting, $wiki, $suffix, &$var, - $params = array(), $wikiTags = array() + $params = [], $wikiTags = [] ) { $value = $this->get( $setting, $wiki, $suffix, $params, $wikiTags ); if ( !is_null( $value ) ) { @@ -362,7 +367,7 @@ class SiteConfiguration { * @param array $wikiTags The tags assigned to the wiki. */ public function extractGlobal( $setting, $wiki, $suffix = null, - $params = array(), $wikiTags = array() + $params = [], $wikiTags = [] ) { $params = $this->mergeParams( $wiki, $suffix, $params, $wikiTags ); $this->extractGlobalSetting( $setting, $wiki, $params ); @@ -396,8 +401,8 @@ 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 ) { @@ -414,18 +419,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; @@ -484,7 +489,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; @@ -501,7 +506,7 @@ class SiteConfiguration { } } $lang = str_replace( '_', '-', $lang ); - return array( $site, $lang ); + return [ $site, $lang ]; } /** @@ -521,7 +526,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'." ); @@ -539,19 +544,19 @@ class SiteConfiguration { } 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." ); } @@ -565,17 +570,6 @@ class SiteConfiguration { return $multi ? $res : current( $res ); } - /** - * 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 - */ - 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.