Merged FileBackend branch. Manually avoiding merging the many prop-only changes SVN...
[lhc/web/wiklou.git] / includes / Setup.php
index 5c08261..6182086 100644 (file)
@@ -114,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
  */
@@ -179,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,
@@ -186,6 +200,59 @@ 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
@@ -462,6 +529,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;