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
;
29 * Service for instantiating BlobStores
31 * This can be used to create BlobStore objects for other wikis.
35 class BlobStoreFactory
{
58 * TODO Make this a const when HHVM support is dropped (T192166)
63 public static $constructorOptions = [
65 'DefaultExternalStore',
67 'RevisionCacheExpiry',
70 public function __construct(
71 ILBFactory
$lbFactory,
72 WANObjectCache
$cache,
73 ServiceOptions
$options,
76 $options->assertRequiredOptions( self
::$constructorOptions );
78 $this->lbFactory
= $lbFactory;
79 $this->cache
= $cache;
80 $this->options
= $options;
81 $this->contLang
= $contLang;
87 * @param bool|string $wikiId The ID of the target wiki database. Use false for the local wiki.
91 public function newBlobStore( $wikiId = false ) {
92 return $this->newSqlBlobStore( $wikiId );
96 * @internal Please call newBlobStore and use the BlobStore interface.
98 * @param bool|string $wikiId The ID of the target wiki database. Use false for the local wiki.
100 * @return SqlBlobStore
102 public function newSqlBlobStore( $wikiId = false ) {
103 $lb = $this->lbFactory
->getMainLB( $wikiId );
104 $store = new SqlBlobStore(
110 $store->setCompressBlobs( $this->options
->get( 'CompressRevisions' ) );
111 $store->setCacheExpiry( $this->options
->get( 'RevisionCacheExpiry' ) );
112 $store->setUseExternalStore( $this->options
->get( 'DefaultExternalStore' ) !== false );
114 if ( $this->options
->get( 'LegacyEncoding' ) ) {
115 $store->setLegacyEncoding( $this->options
->get( 'LegacyEncoding' ), $this->contLang
);