X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Ffilebackend%2FFileBackendGroup.php;h=5d0da6d32a5c6c2d1e62e03f9349072fbb0173aa;hp=c8a68d2d26f91ef2744d7fc19c64fd12c13fc53f;hb=c6d1ceb90a9684fa0da758d88ba1e994fad4cffc;hpb=305499a998c763f1ec9bf5c203708b4200d06747 diff --git a/includes/filebackend/FileBackendGroup.php b/includes/filebackend/FileBackendGroup.php index c8a68d2d26..5d0da6d32a 100644 --- a/includes/filebackend/FileBackendGroup.php +++ b/includes/filebackend/FileBackendGroup.php @@ -19,9 +19,9 @@ * * @file * @ingroup FileBackend - * @author Aaron Schulz */ use \MediaWiki\Logger\LoggerFactory; +use MediaWiki\MediaWikiServices; /** * Class to handle file backend registration @@ -62,7 +62,7 @@ class FileBackendGroup { * Register file backends from the global variables */ protected function initFromGlobals() { - global $wgLocalFileRepo, $wgForeignFileRepos, $wgFileBackends; + global $wgLocalFileRepo, $wgForeignFileRepos, $wgFileBackends, $wgDirectoryMode; // Register explicitly defined backends $this->register( $wgFileBackends, wfConfiguredReadOnlyReason() ); @@ -87,9 +87,6 @@ class FileBackendGroup { $transcodedDir = isset( $info['transcodedDir'] ) ? $info['transcodedDir'] : "{$directory}/transcoded"; - $fileMode = isset( $info['fileMode'] ) - ? $info['fileMode'] - : 0644; // Get the FS backend configuration $autoBackends[] = [ 'name' => $backendName, @@ -102,7 +99,8 @@ class FileBackendGroup { "{$repoName}-deleted" => $deletedDir, "{$repoName}-temp" => "{$directory}/temp" ], - 'fileMode' => $fileMode, + 'fileMode' => isset( $info['fileMode'] ) ? $info['fileMode'] : 0644, + 'directoryMode' => $wgDirectoryMode, ]; } @@ -151,29 +149,11 @@ class FileBackendGroup { * @throws InvalidArgumentException */ public function get( $name ) { - if ( !isset( $this->backends[$name] ) ) { - throw new InvalidArgumentException( "No backend defined with the name `$name`." ); - } // Lazy-load the actual backend instance if ( !isset( $this->backends[$name]['instance'] ) ) { - $class = $this->backends[$name]['class']; - $config = $this->backends[$name]['config']; - $config += [ - 'wikiId' => wfWikiID(), // e.g. "my_wiki-en_" - 'mimeCallback' => [ $this, 'guessMimeInternal' ], - 'obResetFunc' => 'wfResetOutputBuffers', - 'streamMimeFunc' => [ 'StreamFile', 'contentTypeFromPath' ] - ]; - $config['lockManager'] = - LockManagerGroup::singleton( $config['wikiId'] )->get( $config['lockManager'] ); - $config['fileJournal'] = isset( $config['fileJournal'] ) - ? FileJournal::factory( $config['fileJournal'], $name ) - : FileJournal::factory( [ 'class' => 'NullFileJournal' ], $name ); - $config['wanCache'] = ObjectCache::getMainWANInstance(); - $config['statusWrapper'] = [ 'Status', 'wrap' ]; - $config['tmpDirectory'] = wfTempDir(); - $config['logger'] = LoggerFactory::getInstance( 'FileOperation' ); - $config['profiler'] = Profiler::instance(); + $config = $this->config( $name ); + + $class = $config['class']; if ( $class === 'FileBackendMultiWrite' ) { foreach ( $config['backends'] as $index => $beConfig ) { if ( isset( $beConfig['template'] ) ) { @@ -194,7 +174,7 @@ class FileBackendGroup { * Get the config array for a backend object with a given name * * @param string $name - * @return array + * @return array Parameters to FileBackend::__construct() * @throws InvalidArgumentException */ public function config( $name ) { @@ -203,7 +183,27 @@ class FileBackendGroup { } $class = $this->backends[$name]['class']; - return [ 'class' => $class ] + $this->backends[$name]['config']; + $config = $this->backends[$name]['config']; + $config['class'] = $class; + $config += [ // set defaults + 'wikiId' => wfWikiID(), // e.g. "my_wiki-en_" + 'mimeCallback' => [ $this, 'guessMimeInternal' ], + 'obResetFunc' => 'wfResetOutputBuffers', + 'streamMimeFunc' => [ 'StreamFile', 'contentTypeFromPath' ], + 'tmpDirectory' => wfTempDir(), + 'statusWrapper' => [ 'Status', 'wrap' ], + 'wanCache' => MediaWikiServices::getInstance()->getMainWANObjectCache(), + 'srvCache' => ObjectCache::getLocalServerInstance( 'hash' ), + 'logger' => LoggerFactory::getInstance( 'FileOperation' ), + 'profiler' => Profiler::instance() + ]; + $config['lockManager'] = + LockManagerGroup::singleton( $config['wikiId'] )->get( $config['lockManager'] ); + $config['fileJournal'] = isset( $config['fileJournal'] ) + ? FileJournal::factory( $config['fileJournal'], $name ) + : FileJournal::factory( [ 'class' => 'NullFileJournal' ], $name ); + + return $config; } /**