From 616fabe05a2b66e1c7ba7b93a632d2eaa32f184d Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 22 Sep 2016 21:54:49 -0700 Subject: [PATCH] Move FileBackendMultiWrite to /libs Change-Id: I8079693a62db390028cd9f72b2bd7a81ae1164c3 --- autoload.php | 2 +- includes/DefaultSettings.php | 5 +++++ includes/filebackend/FileBackendGroup.php | 9 +++++++++ .../{ => libs}/filebackend/FileBackendMultiWrite.php | 8 -------- 4 files changed, 15 insertions(+), 9 deletions(-) rename includes/{ => libs}/filebackend/FileBackendMultiWrite.php (98%) diff --git a/autoload.php b/autoload.php index dd4bb9d1ac..767cb786fe 100644 --- a/autoload.php +++ b/autoload.php @@ -458,7 +458,7 @@ $wgAutoloadLocalClasses = [ 'FileBackendDBRepoWrapper' => __DIR__ . '/includes/filerepo/FileBackendDBRepoWrapper.php', 'FileBackendError' => __DIR__ . '/includes/libs/filebackend/FileBackendError.php', 'FileBackendGroup' => __DIR__ . '/includes/filebackend/FileBackendGroup.php', - 'FileBackendMultiWrite' => __DIR__ . '/includes/filebackend/FileBackendMultiWrite.php', + 'FileBackendMultiWrite' => __DIR__ . '/includes/libs/filebackend/FileBackendMultiWrite.php', 'FileBackendStore' => __DIR__ . '/includes/filebackend/FileBackendStore.php', 'FileBackendStoreOpHandle' => __DIR__ . '/includes/filebackend/FileBackendStore.php', 'FileBackendStoreShardDirIterator' => __DIR__ . '/includes/filebackend/FileBackendStore.php', diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 8180443347..7facf2fcf7 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -616,6 +616,11 @@ $wgUploadDialog = [ * Additional parameters are specific to the file backend class used. * These settings should be global to all wikis when possible. * + * FileBackendMultiWrite::__construct() is augmented with a 'template' option that + * can be used in any of the values of the 'backends' array. Its value is the name of + * another backend in $wgFileBackends. When set, it pre-fills the array with all of the + * configuration of the named backend. Explicitly set values in the array take precedence. + * * There are two particularly important aspects about each backend: * - a) Whether it is fully qualified or wiki-relative. * By default, the paths of files are relative to the current wiki, diff --git a/includes/filebackend/FileBackendGroup.php b/includes/filebackend/FileBackendGroup.php index d9e5a540e2..1ebd0b9998 100644 --- a/includes/filebackend/FileBackendGroup.php +++ b/includes/filebackend/FileBackendGroup.php @@ -172,6 +172,15 @@ class FileBackendGroup { $config['tmpDirectory'] = wfTempDir(); $config['logger'] = LoggerFactory::getInstance( 'FileOperation' ); $config['profiler'] = Profiler::instance(); + if ( $class === 'FileBackendMultiWrite' ) { + foreach ( $config['backends'] as $index => $beConfig ) { + if ( isset( $beConfig['template'] ) ) { + // Config is just a modified version of a registered backend's. + // This should only be used when that config is used only by this backend. + $config['backends'][$index] += $this->config( $beConfig['template'] ); + } + } + } $this->backends[$name]['instance'] = new $class( $config ); } diff --git a/includes/filebackend/FileBackendMultiWrite.php b/includes/libs/filebackend/FileBackendMultiWrite.php similarity index 98% rename from includes/filebackend/FileBackendMultiWrite.php rename to includes/libs/filebackend/FileBackendMultiWrite.php index db79155533..7c32d02e86 100644 --- a/includes/filebackend/FileBackendMultiWrite.php +++ b/includes/libs/filebackend/FileBackendMultiWrite.php @@ -74,9 +74,6 @@ class FileBackendMultiWrite extends FileBackend { * - class : The name of the backend class * - isMultiMaster : This must be set for one backend. * - readAffinity : Use this for reads without 'latest' set. - * - template: : If given a backend name, this will use - * the config of that backend as a template. - * Values specified here take precedence. * - syncChecks : Integer bitfield of internal backend sync checks to perform. * Possible bits include the FileBackendMultiWrite::CHECK_* constants. * There are constants for SIZE, TIME, and SHA1. @@ -107,11 +104,6 @@ class FileBackendMultiWrite extends FileBackend { // to keep these backends hidden from outside the proxy. $namesUsed = []; foreach ( $config['backends'] as $index => $config ) { - if ( isset( $config['template'] ) ) { - // Config is just a modified version of a registered backend's. - // This should only be used when that config is used only by this backend. - $config = $config + FileBackendGroup::singleton()->config( $config['template'] ); - } $name = $config['name']; if ( isset( $namesUsed[$name] ) ) { // don't break FileOp predicates throw new LogicException( "Two or more backends defined with the name $name." ); -- 2.20.1