filebackend: cleaned up the FileBackend constructor
[lhc/web/wiklou.git] / includes / filebackend / FileBackendGroup.php
index d790a99..e451e3c 100644 (file)
  * @since 1.19
  */
 class FileBackendGroup {
-       /**
-        * @var FileBackendGroup
-        */
+       /** @var FileBackendGroup */
        protected static $instance = null;
 
-       /** @var Array (name => ('class' => string, 'config' => array, 'instance' => object)) */
+       /** @var array (name => ('class' => string, 'config' => array, 'instance' => object)) */
        protected $backends = array();
 
-       protected function __construct() {}
+       protected function __construct() {
+       }
 
        /**
         * @return FileBackendGroup
@@ -47,13 +46,12 @@ class FileBackendGroup {
                        self::$instance = new self();
                        self::$instance->initFromGlobals();
                }
+
                return self::$instance;
        }
 
        /**
         * Destroy the singleton instance
-        *
-        * @return void
         */
        public static function destroySingleton() {
                self::$instance = null;
@@ -61,8 +59,6 @@ class FileBackendGroup {
 
        /**
         * Register file backends from the global variables
-        *
-        * @return void
         */
        protected function initFromGlobals() {
                global $wgLocalFileRepo, $wgForeignFileRepos, $wgFileBackends;
@@ -95,17 +91,17 @@ class FileBackendGroup {
                                : 0644;
                        // Get the FS backend configuration
                        $autoBackends[] = array(
-                               'name'           => $backendName,
-                               'class'          => 'FSFileBackend',
-                               'lockManager'    => 'fsLockManager',
+                               'name' => $backendName,
+                               'class' => 'FSFileBackend',
+                               'lockManager' => 'fsLockManager',
                                'containerPaths' => array(
-                                       "{$repoName}-public"  => "{$directory}",
-                                       "{$repoName}-thumb"   => $thumbDir,
-                                       "{$repoName}-transcoded"   => $transcodedDir,
+                                       "{$repoName}-public" => "{$directory}",
+                                       "{$repoName}-thumb" => $thumbDir,
+                                       "{$repoName}-transcoded" => $transcodedDir,
                                        "{$repoName}-deleted" => $deletedDir,
-                                       "{$repoName}-temp"    => "{$directory}/temp"
+                                       "{$repoName}-temp" => "{$directory}/temp"
                                ),
-                               'fileMode'       => $fileMode,
+                               'fileMode' => $fileMode,
                        );
                }
 
@@ -116,8 +112,7 @@ class FileBackendGroup {
        /**
         * Register an array of file backend configurations
         *
-        * @param $configs Array
-        * @return void
+        * @param array $configs
         * @throws MWException
         */
        protected function register( array $configs ) {
@@ -135,8 +130,8 @@ class FileBackendGroup {
 
                        unset( $config['class'] ); // backend won't need this
                        $this->backends[$name] = array(
-                               'class'    => $class,
-                               'config'   => $config,
+                               'class' => $class,
+                               'config' => $config,
                                'instance' => null
                        );
                }
@@ -145,7 +140,7 @@ class FileBackendGroup {
        /**
         * Get the backend object with a given name
         *
-        * @param $name string
+        * @param string $name
         * @return FileBackend
         * @throws MWException
         */
@@ -157,16 +152,25 @@ class FileBackendGroup {
                if ( !isset( $this->backends[$name]['instance'] ) ) {
                        $class = $this->backends[$name]['class'];
                        $config = $this->backends[$name]['config'];
+                       $config['wikiId'] = isset( $config['wikiId'] )
+                               ? $config['wikiId']
+                               : wfWikiID(); // e.g. "my_wiki-en_"
+                       $config['lockManager'] =
+                               LockManagerGroup::singleton( $config['wikiId'] )->get( $config['lockManager'] );
+                       $config['fileJournal'] = isset( $config['fileJournal'] )
+                               ? FileJournal::factory( $config['fileJournal'], $name )
+                               : FileJournal::factory( array( 'class' => 'NullFileJournal' ), $name );
                        $this->backends[$name]['instance'] = new $class( $config );
                }
+
                return $this->backends[$name]['instance'];
        }
 
        /**
         * Get the config array for a backend object with a given name
         *
-        * @param $name string
-        * @return Array
+        * @param string $name
+        * @return array
         * @throws MWException
         */
        public function config( $name ) {
@@ -174,13 +178,14 @@ class FileBackendGroup {
                        throw new MWException( "No backend defined with the name `$name`." );
                }
                $class = $this->backends[$name]['class'];
+
                return array( 'class' => $class ) + $this->backends[$name]['config'];
        }
 
        /**
         * Get an appropriate backend object from a storage path
         *
-        * @param $storagePath string
+        * @param string $storagePath
         * @return FileBackend|null Backend or null on failure
         */
        public function backendFromPath( $storagePath ) {
@@ -188,6 +193,7 @@ class FileBackendGroup {
                if ( $backend !== null && isset( $this->backends[$backend] ) ) {
                        return $this->get( $backend );
                }
+
                return null;
        }
 }