X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Ffilebackend%2FFileBackendGroup.php;h=9e04d0963292d33233c35a679bf515dae77b3c40;hb=0e4b7631097508cd7982559569eda464b6ca47d3;hp=a5860e257186d7f6e1cc29019df17791ef6b5e0e;hpb=243a466018d24415de27815cfae995865c45a66a;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/filebackend/FileBackendGroup.php b/includes/filebackend/FileBackendGroup.php index a5860e2571..9e04d09632 100644 --- a/includes/filebackend/FileBackendGroup.php +++ b/includes/filebackend/FileBackendGroup.php @@ -117,12 +117,14 @@ class FileBackendGroup { } $name = $config['name']; if ( isset( $this->backends[$name] ) ) { - throw new LogicException( "Backend with name `{$name}` already registered." ); + throw new LogicException( "Backend with name '$name' already registered." ); } elseif ( !isset( $config['class'] ) ) { - throw new InvalidArgumentException( "Backend with name `{$name}` has no class." ); + throw new InvalidArgumentException( "Backend with name '$name' has no class." ); } $class = $config['class']; + // @FIXME: ideally this would default to the DB domain (which includes the schema) + $config['domainId'] = $config['domainId'] ?? ( $config['wikiId'] ?? wfWikiID() ); $config['readOnly'] = $config['readOnly'] ?? $readOnlyReason; unset( $config['class'] ); // backend won't need this @@ -148,6 +150,7 @@ class FileBackendGroup { $class = $config['class']; if ( $class === FileBackendMultiWrite::class ) { + // @todo How can we test this? What's the intended use-case? foreach ( $config['backends'] as $index => $beConfig ) { if ( isset( $beConfig['template'] ) ) { // Config is just a modified version of a registered backend's. @@ -172,40 +175,40 @@ class FileBackendGroup { */ public function config( $name ) { if ( !isset( $this->backends[$name] ) ) { - throw new InvalidArgumentException( "No backend defined with the name `$name`." ); + throw new InvalidArgumentException( "No backend defined with the name '$name'." ); } - $class = $this->backends[$name]['class']; $config = $this->backends[$name]['config']; - $config['class'] = $class; - if ( isset( $config['domainId'] ) ) { - $domain = $config['domainId']; - } else { - // @FIXME: this does not include the domain for b/c but it ideally should - $domain = $config['wikiId'] ?? wfWikiID(); - } - // Set default parameter values - $config += [ - 'domainId' => $domain, // e.g. "my_wiki-en_" - 'mimeCallback' => [ $this, 'guessMimeInternal' ], - 'obResetFunc' => 'wfResetOutputBuffers', - 'streamMimeFunc' => [ StreamFile::class, 'contentTypeFromPath' ], - 'tmpDirectory' => wfTempDir(), - 'statusWrapper' => [ Status::class, 'wrap' ], - 'wanCache' => MediaWikiServices::getInstance()->getMainWANObjectCache(), - 'srvCache' => ObjectCache::getLocalServerInstance( 'hash' ), - 'logger' => LoggerFactory::getInstance( 'FileOperation' ), - 'profiler' => function ( $section ) { - return Profiler::instance()->scopedProfileIn( $section ); - } - ]; - $config['lockManager'] = - LockManagerGroup::singleton( $domain )->get( $config['lockManager'] ); - $config['fileJournal'] = isset( $config['fileJournal'] ) - ? FileJournal::factory( $config['fileJournal'], $name ) - : FileJournal::factory( [ 'class' => NullFileJournal::class ], $name ); - - return $config; + $services = MediaWikiServices::getInstance(); + + return array_merge( + // Default backend parameters + [ + 'mimeCallback' => [ $this, 'guessMimeInternal' ], + 'obResetFunc' => 'wfResetOutputBuffers', + 'streamMimeFunc' => [ StreamFile::class, 'contentTypeFromPath' ], + 'tmpFileFactory' => $services->getTempFSFileFactory(), + 'statusWrapper' => [ Status::class, 'wrap' ], + 'wanCache' => $services->getMainWANObjectCache(), + 'srvCache' => ObjectCache::getLocalServerInstance( 'hash' ), + 'logger' => LoggerFactory::getInstance( 'FileOperation' ), + 'profiler' => function ( $section ) { + return Profiler::instance()->scopedProfileIn( $section ); + } + ], + // Configured backend parameters + $config, + // Resolved backend parameters + [ + 'class' => $this->backends[$name]['class'], + 'lockManager' => + LockManagerGroup::singleton( $config['domainId'] ) + ->get( $config['lockManager'] ), + 'fileJournal' => isset( $config['fileJournal'] ) + ? FileJournal::factory( $config['fileJournal'], $name ) + : FileJournal::factory( [ 'class' => NullFileJournal::class ], $name ) + ] + ); } /** @@ -239,7 +242,8 @@ class FileBackendGroup { if ( !$type && $fsPath ) { $type = $magic->guessMimeType( $fsPath, false ); } elseif ( !$type && strlen( $content ) ) { - $tmpFile = TempFSFile::factory( 'mime_', '', wfTempDir() ); + $tmpFile = MediaWikiServices::getInstance()->getTempFSFileFactory() + ->newTempFSFile( 'mime_', '' ); file_put_contents( $tmpFile->getPath(), $content ); $type = $magic->guessMimeType( $tmpFile->getPath(), false ); }