Merged FileBackend branch. Manually avoiding merging the many prop-only changes SVN...
[lhc/web/wiklou.git] / includes / Setup.php
index e3be061..6182086 100644 (file)
@@ -23,7 +23,6 @@ $fname = 'Setup.php';
 wfProfileIn( $fname );
 
 // Check to see if we are at the file scope
-// FIXME: use a different test here, maybe a constant defined at the top of DefaultSettings.php?
 if ( !isset( $wgVersion ) ) {
        echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
        die( 1 );
@@ -42,6 +41,12 @@ if ( $wgArticlePath === false ) {
        }
 }
 
+if ( !empty($wgActionPaths) && !isset($wgActionPaths['view']) ) {
+       # 'view' is assumed the default action path everywhere in the code
+       # but is rarely filled in $wgActionPaths
+       $wgActionPaths['view'] = $wgArticlePath;
+}
+
 if ( !empty($wgActionPaths) && !isset($wgActionPaths['view']) ) {
        # 'view' is assumed the default action path everywhere in the code
        # but is rarely filled in $wgActionPaths 
@@ -109,6 +114,19 @@ $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
 $wgNamespaceAliases['Image'] = NS_FILE;
 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
 
+/**
+ * Initialise $wgLockManagers to include basic FS version
+ */
+$wgLockManagers[] = array(
+       'name'          => 'fsLockManager',
+       'class'         => 'FSLockManager',
+       'lockDirectory' => "{$wgUploadDirectory}/lockdir",
+);
+$wgLockManagers[] = array(
+       'name'          => 'nullLockManager',
+       'class'         => 'NullLockManager',
+);
+
 /**
  * Initialise $wgLocalFileRepo from backwards-compatible settings
  */
@@ -174,6 +192,7 @@ if ( $wgUseInstantCommons ) {
        $wgForeignFileRepos[] = array(
                'class'                   => 'ForeignAPIRepo',
                'name'                    => 'wikimediacommons',
+               'directory'               => $wgUploadDirectory,
                'apibase'                 => 'http://commons.wikimedia.org/w/api.php',
                'hashLevels'              => 2,
                'fetchDescription'        => true,
@@ -181,6 +200,64 @@ if ( $wgUseInstantCommons ) {
                'apiThumbCacheExpiry'     => 86400,
        );
 }
+/*
+ * Add on default file backend config for repos to $wgFileBackends
+ */
+if ( !isset( $wgLocalFileRepo['backend'] ) ) {
+       $wgFileBackends[] = wfBackendForLegacyRepoConf( $wgLocalFileRepo );
+}
+foreach ( $wgForeignFileRepos as &$repo ) {
+       if ( !isset( $repo['backend'] ) ) {
+               $wgFileBackends[] = wfBackendForLegacyRepoConf( $repo );
+       }
+}
+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
+       $wgEnableAutoRotation = BitmapHandler::canRotate();
+}
 
 if ( $wgRCFilterByAge ) {
        # # Trim down $wgRCLinkDays so that it only lists links which are valid
@@ -310,30 +387,38 @@ if ( $wgNewUserLog ) {
        $wgLogTypes[]                        = 'newusers';
        $wgLogNames['newusers']              = 'newuserlogpage';
        $wgLogHeaders['newusers']            = 'newuserlogpagetext';
-       $wgLogActions['newusers/newusers']   = 'newuserlogentry'; // For compatibility with older log entries
-       $wgLogActions['newusers/create']     = 'newuserlog-create-entry';
-       $wgLogActions['newusers/create2']    = 'newuserlog-create2-entry';
-       $wgLogActions['newusers/autocreate'] = 'newuserlog-autocreate-entry';
+       # newusers, create, create2, autocreate
+       $wgLogActionsHandlers['newusers/*']  = 'NewUsersLogFormatter';
+}
+
+if ( $wgCookieSecure === 'detect' ) {
+       $wgCookieSecure = ( substr( $wgServer, 0, 6 ) === 'https:' );
 }
 
+MWDebug::init();
+
 if ( !defined( 'MW_COMPILED' ) ) {
        if ( !MWInit::classExists( 'AutoLoader' ) ) {
                require_once( "$IP/includes/AutoLoader.php" );
        }
 
        wfProfileIn( $fname . '-exception' );
-       require_once( "$IP/includes/Exception.php" );
-       wfInstallExceptionHandler();
+       MWExceptionHandler::installHandler();
        wfProfileOut( $fname . '-exception' );
 
        wfProfileIn( $fname . '-includes' );
+       require_once( "$IP/includes/normal/UtfNormalUtil.php" );
        require_once( "$IP/includes/GlobalFunctions.php" );
-       require_once( "$IP/includes/Hooks.php" );
        require_once( "$IP/includes/ProxyTools.php" );
        require_once( "$IP/includes/ImageFunctions.php" );
+       require_once( "$IP/includes/normal/UtfNormalDefines.php" );
        wfProfileOut( $fname . '-includes' );
 }
-require_once( MWInit::compiledPath( 'includes/normal/UtfNormalDefines.php' ) );
+
+# Now that GlobalFunctions is loaded, set the default for $wgCanonicalServer
+if ( $wgCanonicalServer === false ) {
+       $wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP );
+}
 
 wfProfileIn( $fname . '-misc1' );
 
@@ -345,18 +430,27 @@ wfMemoryLimit();
  * that happens whenever you use a date function without the timezone being
  * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
  */
-wfSuppressWarnings();
-date_default_timezone_set( date_default_timezone_get() );
-wfRestoreWarnings();
+if ( is_null( $wgLocaltimezone) ) {
+       wfSuppressWarnings();
+       $wgLocaltimezone = date_default_timezone_get();
+       wfRestoreWarnings();
+}
 
-# Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
-$wgRequest = new WebRequest;
+date_default_timezone_set( $wgLocaltimezone );
+if( is_null( $wgLocalTZoffset ) ) {
+       $wgLocalTZoffset = date( 'Z' ) / 60;
+}
 
 # Useful debug output
 global $wgCommandLineMode;
 if ( $wgCommandLineMode ) {
+       $wgRequest = new FauxRequest( array() );
+
        wfDebug( "\n\nStart command line script $self\n" );
 } else {
+       # 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()}";
 
        if ( $wgDebugPrintHttpHeaders ) {
@@ -367,6 +461,7 @@ if ( $wgCommandLineMode ) {
                }
        }
        wfDebug( "$debug\n" );
+       MWDebug::processRequest( $wgRequest );
 }
 
 wfProfileOut( $fname . '-misc1' );
@@ -434,12 +529,22 @@ 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;
-$wgArticle = 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' );