Merge "Change if/else to a ternary operator"
[lhc/web/wiklou.git] / includes / Setup.php
index 6182086..335d37b 100644 (file)
@@ -1,6 +1,21 @@
 <?php
 /**
- * Include most things that's need to customize the site
+ * Include most things that's need to customize the site.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
  *
  * @file
  */
@@ -49,7 +64,7 @@ if ( !empty($wgActionPaths) && !isset($wgActionPaths['view']) ) {
 
 if ( !empty($wgActionPaths) && !isset($wgActionPaths['view']) ) {
        # 'view' is assumed the default action path everywhere in the code
-       # but is rarely filled in $wgActionPaths 
+       # but is rarely filled in $wgActionPaths
        $wgActionPaths['view'] = $wgArticlePath ;
 }
 
@@ -176,7 +191,7 @@ if ( $wgUseSharedUploads ) {
                );
        } else {
                $wgForeignFileRepos[] = array(
-                       'class' => 'FSRepo',
+                       'class' => 'FileRepo',
                        'name' => 'shared',
                        'directory' => $wgSharedUploadDirectory,
                        'url' => $wgSharedUploadPath,
@@ -190,69 +205,33 @@ if ( $wgUseSharedUploads ) {
 }
 if ( $wgUseInstantCommons ) {
        $wgForeignFileRepos[] = array(
-               'class'                   => 'ForeignAPIRepo',
-               'name'                    => 'wikimediacommons',
-               'directory'               => $wgUploadDirectory,
-               'apibase'                 => 'http://commons.wikimedia.org/w/api.php',
-               'hashLevels'              => 2,
-               'fetchDescription'        => true,
-               'descriptionCacheExpiry'  => 43200,
-               'apiThumbCacheExpiry'     => 86400,
+               'class'                  => 'ForeignAPIRepo',
+               'name'                   => 'wikimediacommons',
+               'apibase'                => WebRequest::detectProtocol() === 'https' ?
+                       'https://commons.wikimedia.org/w/api.php' :
+                       'http://commons.wikimedia.org/w/api.php',
+               'hashLevels'             => 2,
+               'fetchDescription'       => true,
+               'descriptionCacheExpiry' => 43200,
+               'apiThumbCacheExpiry'    => 86400,
        );
 }
 /*
- * Add on default file backend config for repos to $wgFileBackends
+ * Add on default file backend config for file repos.
+ * FileBackendGroup will handle initializing the backends.
  */
 if ( !isset( $wgLocalFileRepo['backend'] ) ) {
-       $wgFileBackends[] = wfBackendForLegacyRepoConf( $wgLocalFileRepo );
+       $wgLocalFileRepo['backend'] = $wgLocalFileRepo['name'] . '-backend';
 }
 foreach ( $wgForeignFileRepos as &$repo ) {
+       if ( !isset( $repo['directory'] ) && $repo['class'] === 'ForeignAPIRepo' ) {
+               $repo['directory'] = $wgUploadDirectory; // b/c
+       }
        if ( !isset( $repo['backend'] ) ) {
-               $wgFileBackends[] = wfBackendForLegacyRepoConf( $repo );
+               $repo['backend'] = $repo['name'] . '-backend';
        }
 }
 unset( $repo ); // no global pollution; destroy reference
-/*
- * Get file backend configuration for a given repo
- * configuration that lacks a backend parameter.
- * Also updates the repo config to use the backend.
- */
-function wfBackendForLegacyRepoConf( &$info ) {
-       // Local vars that used to be FSRepo members...
-       $directory = $info['directory'];
-       $deletedDir = isset( $info['deletedDir'] )
-               ? $info['deletedDir']
-               : false;
-       $thumbDir = isset( $info['thumbDir'] )
-               ? $info['thumbDir']
-               : "{$directory}/thumb";
-       $fileMode = isset( $info['fileMode'] )
-               ? $info['fileMode']
-               : 0644;
-
-       // Make a backend name (based on repo name)
-       $backendName = $info['name'] . '-backend';
-       // Update repo config to use this backend
-       $info['backend'] = $backendName;
-       // Disable "deleted" zone in repo config if deleted dir not set
-       if ( $deletedDir !== false ) {
-               $info['zones']['deleted'] = array(
-                       'container' => 'images-deleted', 'directory' => '' );
-       }
-       // Get the FS backend configuration
-       return array(
-               'name'           => $backendName,
-               'class'          => 'FSFileBackend',
-               'lockManager'    => 'fsLockManager',
-               'containerPaths' => array(
-                       "images-public"  => "{$directory}",
-                       "images-temp"    => "{$directory}/temp",
-                       "images-thumb"   => $thumbDir,
-                       "images-deleted" => $deletedDir
-               ),
-               'fileMode'       => $fileMode,
-       );
-}
 
 if ( is_null( $wgEnableAutoRotation ) ) {
        // Only enable auto-rotation when the bitmap handler can rotate
@@ -335,8 +314,10 @@ $wgContLanguageCode = $wgLanguageCode;
 
 # Easy to forget to falsify $wgShowIPinHeader for static caches.
 # If file cache or squid cache is on, just disable this (DWIMD).
+# Do the same for $wgDebugToolbar.
 if ( $wgUseFileCache || $wgUseSquid ) {
        $wgShowIPinHeader = false;
+       $wgDebugToolbar = false;
 }
 
 # $wgAllowRealName and $wgAllowUserSkin were removed in 1.16
@@ -395,7 +376,12 @@ if ( $wgCookieSecure === 'detect' ) {
        $wgCookieSecure = ( substr( $wgServer, 0, 6 ) === 'https:' );
 }
 
-MWDebug::init();
+// Disable MWDebug for command line mode, this prevents MWDebug from eating up
+// all the memory from logging SQL queries on maintenance scripts
+global $wgCommandLineMode;
+if ( $wgDebugToolbar && !$wgCommandLineMode ) {
+       MWDebug::init();
+}
 
 if ( !defined( 'MW_COMPILED' ) ) {
        if ( !MWInit::classExists( 'AutoLoader' ) ) {
@@ -410,7 +396,6 @@ if ( !defined( 'MW_COMPILED' ) ) {
        require_once( "$IP/includes/normal/UtfNormalUtil.php" );
        require_once( "$IP/includes/GlobalFunctions.php" );
        require_once( "$IP/includes/ProxyTools.php" );
-       require_once( "$IP/includes/ImageFunctions.php" );
        require_once( "$IP/includes/normal/UtfNormalDefines.php" );
        wfProfileOut( $fname . '-includes' );
 }
@@ -420,6 +405,16 @@ if ( $wgCanonicalServer === false ) {
        $wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP );
 }
 
+// Initialize $wgHTCPMulticastRouting from backwards-compatible settings
+if ( !$wgHTCPMulticastRouting && $wgHTCPMulticastAddress ) {
+       $wgHTCPMulticastRouting = array(
+               '' => array(
+                       'host' => $wgHTCPMulticastAddress,
+                       'port' => $wgHTCPPort,
+               )
+       );
+}
+
 wfProfileIn( $fname . '-misc1' );
 
 # Raise the memory limit if it's too low
@@ -442,7 +437,6 @@ if( is_null( $wgLocalTZoffset ) ) {
 }
 
 # Useful debug output
-global $wgCommandLineMode;
 if ( $wgCommandLineMode ) {
        $wgRequest = new FauxRequest( array() );
 
@@ -451,17 +445,16 @@ if ( $wgCommandLineMode ) {
        # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
        $wgRequest = new WebRequest;
 
-       $debug = "Start request\n\n{$_SERVER['REQUEST_METHOD']} {$wgRequest->getRequestURL()}";
+       $debug = "\n\nStart request {$_SERVER['REQUEST_METHOD']} {$wgRequest->getRequestURL()}\n";
 
        if ( $wgDebugPrintHttpHeaders ) {
-               $debug .= "\nHTTP HEADERS:\n";
+               $debug .= "HTTP HEADERS:\n";
 
                foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
                        $debug .= "$name: $value\n";
                }
        }
-       wfDebug( "$debug\n" );
-       MWDebug::processRequest( $wgRequest );
+       wfDebug( $debug );
 }
 
 wfProfileOut( $fname . '-misc1' );
@@ -470,6 +463,7 @@ wfProfileIn( $fname . '-memcached' );
 $wgMemc = wfGetMainCache();
 $messageMemc = wfGetMessageCacheStorage();
 $parserMemc = wfGetParserCacheStorage();
+$wgLangConvMemc = wfGetLangConverterCacheStorage();
 
 wfDebug( 'CACHES: ' . get_class( $wgMemc ) . '[main] ' .
        get_class( $messageMemc ) . '[message] ' .
@@ -489,11 +483,9 @@ if ( !wfIniGetBool( 'session.auto_start' ) ) {
 
 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
        if ( $wgRequest->checkSessionCookie() || isset( $_COOKIE[$wgCookiePrefix . 'Token'] ) ) {
-               wfIncrStats( 'request_with_session' );
                wfSetupSession();
                $wgSessionStarted = true;
        } else {
-               wfIncrStats( 'request_without_session' );
                $wgSessionStarted = false;
        }
 }
@@ -510,7 +502,7 @@ $wgRequest->interpolateTitle();
 $wgUser = RequestContext::getMain()->getUser(); # BackCompat
 
 /**
- * @var Language
+ * @var $wgLang Language
  */
 $wgLang = new StubUserLang;
 
@@ -520,7 +512,7 @@ $wgLang = new StubUserLang;
 $wgOut = RequestContext::getMain()->getOutput(); # BackCompat
 
 /**
- * @var Parser
+ * @var $wgParser Parser
  */
 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
 
@@ -529,22 +521,11 @@ if ( !is_object( $wgAuth ) ) {
        wfRunHooks( 'AuthPluginSetup', array( &$wgAuth ) );
 }
 
-# Register file lock managers
-LockManagerGroup::singleton()->register( $wgLockManagers );
-# Register file backends
-FileBackendGroup::singleton()->register( $wgFileBackends );
-
 # Placeholders in case of DB error
 $wgTitle = null;
 
 $wgDeferredUpdateList = array();
 
-// We need to check for safe_mode, because mail() will throw an E_NOTICE
-// on additional parameters
-if( !is_null($wgAdditionalMailParams) && wfIniGetBool('safe_mode') ) {
-       $wgAdditionalMailParams = null;
-}
-
 wfProfileOut( $fname . '-globals' );
 wfProfileIn( $fname . '-extensions' );