Merge "Rewrite pref cleanup script"
[lhc/web/wiklou.git] / includes / Storage / BlobStoreFactory.php
1 <?php
2 /**
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.
7 *
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.
12 *
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
17 *
18 * @file
19 */
20
21 namespace MediaWiki\Storage;
22
23 use Config;
24 use Language;
25 use WANObjectCache;
26 use Wikimedia\Rdbms\LoadBalancer;
27
28 /**
29 * Service for instantiating BlobStores
30 *
31 * This can be used to create BlobStore objects for other wikis.
32 *
33 * @since 1.31
34 */
35 class BlobStoreFactory {
36
37 /**
38 * @var LoadBalancer
39 */
40 private $loadBalancer;
41
42 /**
43 * @var WANObjectCache
44 */
45 private $cache;
46
47 /**
48 * @var Config
49 */
50 private $config;
51
52 /**
53 * @var Language
54 */
55 private $contLang;
56
57 public function __construct(
58 LoadBalancer $loadBalancer,
59 WANObjectCache $cache,
60 Config $mainConfig,
61 Language $contLang
62 ) {
63 $this->loadBalancer = $loadBalancer;
64 $this->cache = $cache;
65 $this->config = $mainConfig;
66 $this->contLang = $contLang;
67 }
68
69 /**
70 * @since 1.31
71 *
72 * @param bool|string $wikiId The ID of the target wiki database. Use false for the local wiki.
73 *
74 * @return BlobStore
75 */
76 public function newBlobStore( $wikiId = false ) {
77 return $this->newSqlBlobStore( $wikiId );
78 }
79
80 /**
81 * @internal Please call newBlobStore and use the BlobStore interface.
82 *
83 * @param bool|string $wikiId The ID of the target wiki database. Use false for the local wiki.
84 *
85 * @return SqlBlobStore
86 */
87 public function newSqlBlobStore( $wikiId = false ) {
88 $store = new SqlBlobStore(
89 $this->loadBalancer,
90 $this->cache,
91 $wikiId
92 );
93
94 $store->setCompressBlobs( $this->config->get( 'CompressRevisions' ) );
95 $store->setCacheExpiry( $this->config->get( 'RevisionCacheExpiry' ) );
96 $store->setUseExternalStore( $this->config->get( 'DefaultExternalStore' ) !== false );
97
98 if ( $this->config->get( 'LegacyEncoding' ) ) {
99 $store->setLegacyEncoding( $this->config->get( 'LegacyEncoding' ), $this->contLang );
100 }
101
102 return $store;
103 }
104
105 }