3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 namespace MediaWiki\Storage
;
24 use MediaWiki\Config\ServiceOptions
;
26 use Wikimedia\Rdbms\ILBFactory
;
27 use ExternalStoreAccess
;
30 * Service for instantiating BlobStores
32 * This can be used to create BlobStore objects for other wikis.
36 class BlobStoreFactory
{
44 * @var ExternalStoreAccess
46 private $extStoreAccess;
67 public const CONSTRUCTOR_OPTIONS
= [
69 'DefaultExternalStore',
71 'RevisionCacheExpiry',
74 public function __construct(
75 ILBFactory
$lbFactory,
76 ExternalStoreAccess
$extStoreAccess,
77 WANObjectCache
$cache,
78 ServiceOptions
$options,
81 $options->assertRequiredOptions( self
::CONSTRUCTOR_OPTIONS
);
83 $this->lbFactory
= $lbFactory;
84 $this->extStoreAccess
= $extStoreAccess;
85 $this->cache
= $cache;
86 $this->options
= $options;
87 $this->contLang
= $contLang;
93 * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki.
97 public function newBlobStore( $dbDomain = false ) {
98 return $this->newSqlBlobStore( $dbDomain );
102 * @internal Please call newBlobStore and use the BlobStore interface.
104 * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki.
106 * @return SqlBlobStore
108 public function newSqlBlobStore( $dbDomain = false ) {
109 $lb = $this->lbFactory
->getMainLB( $dbDomain );
110 $store = new SqlBlobStore(
112 $this->extStoreAccess
,
117 $store->setCompressBlobs( $this->options
->get( 'CompressRevisions' ) );
118 $store->setCacheExpiry( $this->options
->get( 'RevisionCacheExpiry' ) );
119 $store->setUseExternalStore( $this->options
->get( 'DefaultExternalStore' ) !== false );
121 if ( $this->options
->get( 'LegacyEncoding' ) ) {
122 $store->setLegacyEncoding( $this->options
->get( 'LegacyEncoding' ), $this->contLang
);