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;
64 * TODO Make this a const when HHVM support is dropped (T192166)
69 public static $constructorOptions = [
71 'DefaultExternalStore',
73 'RevisionCacheExpiry',
76 public function __construct(
77 ILBFactory
$lbFactory,
78 ExternalStoreAccess
$extStoreAccess,
79 WANObjectCache
$cache,
80 ServiceOptions
$options,
83 $options->assertRequiredOptions( self
::$constructorOptions );
85 $this->lbFactory
= $lbFactory;
86 $this->extStoreAccess
= $extStoreAccess;
87 $this->cache
= $cache;
88 $this->options
= $options;
89 $this->contLang
= $contLang;
95 * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki.
99 public function newBlobStore( $dbDomain = false ) {
100 return $this->newSqlBlobStore( $dbDomain );
104 * @internal Please call newBlobStore and use the BlobStore interface.
106 * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki.
108 * @return SqlBlobStore
110 public function newSqlBlobStore( $dbDomain = false ) {
111 $lb = $this->lbFactory
->getMainLB( $dbDomain );
112 $store = new SqlBlobStore(
114 $this->extStoreAccess
,
119 $store->setCompressBlobs( $this->options
->get( 'CompressRevisions' ) );
120 $store->setCacheExpiry( $this->options
->get( 'RevisionCacheExpiry' ) );
121 $store->setUseExternalStore( $this->options
->get( 'DefaultExternalStore' ) !== false );
123 if ( $this->options
->get( 'LegacyEncoding' ) ) {
124 $store->setLegacyEncoding( $this->options
->get( 'LegacyEncoding' ), $this->contLang
);