Merge "Check for valid user info before calling Linker::userLink() in Linker::revUser...
[lhc/web/wiklou.git] / includes / Storage / BlobStoreFactory.php
index 63ca74d..b59c68d 100644 (file)
 
 namespace MediaWiki\Storage;
 
-use Config;
 use Language;
+use MediaWiki\Config\ServiceOptions;
 use WANObjectCache;
-use Wikimedia\Rdbms\LoadBalancer;
+use Wikimedia\Rdbms\ILBFactory;
+use ExternalStoreAccess;
 
 /**
  * Service for instantiating BlobStores
@@ -35,9 +36,14 @@ use Wikimedia\Rdbms\LoadBalancer;
 class BlobStoreFactory {
 
        /**
-        * @var LoadBalancer
+        * @var ILBFactory
         */
-       private $loadBalancer;
+       private $lbFactory;
+
+       /**
+        * @var ExternalStoreAccess
+        */
+       private $extStoreAccess;
 
        /**
         * @var WANObjectCache
@@ -45,58 +51,77 @@ class BlobStoreFactory {
        private $cache;
 
        /**
-        * @var Config
+        * @var ServiceOptions
         */
-       private $config;
+       private $options;
 
        /**
         * @var Language
         */
        private $contLang;
 
+       /**
+        * TODO Make this a const when HHVM support is dropped (T192166)
+        *
+        * @var array
+        * @since 1.34
+        */
+       public static $constructorOptions = [
+               'CompressRevisions',
+               'DefaultExternalStore',
+               'LegacyEncoding',
+               'RevisionCacheExpiry',
+       ];
+
        public function __construct(
-               LoadBalancer $loadBalancer,
+               ILBFactory $lbFactory,
+               ExternalStoreAccess $extStoreAccess,
                WANObjectCache $cache,
-               Config $mainConfig,
+               ServiceOptions $options,
                Language $contLang
        ) {
-               $this->loadBalancer = $loadBalancer;
+               $options->assertRequiredOptions( self::$constructorOptions );
+
+               $this->lbFactory = $lbFactory;
+               $this->extStoreAccess = $extStoreAccess;
                $this->cache = $cache;
-               $this->config = $mainConfig;
+               $this->options = $options;
                $this->contLang = $contLang;
        }
 
        /**
         * @since 1.31
         *
-        * @param bool|string $wikiId The ID of the target wiki database. Use false for the local wiki.
+        * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki.
         *
         * @return BlobStore
         */
-       public function newBlobStore( $wikiId = false ) {
-               return $this->newSqlBlobStore( $wikiId );
+       public function newBlobStore( $dbDomain = false ) {
+               return $this->newSqlBlobStore( $dbDomain );
        }
 
        /**
         * @internal Please call newBlobStore and use the BlobStore interface.
         *
-        * @param bool|string $wikiId The ID of the target wiki database. Use false for the local wiki.
+        * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki.
         *
         * @return SqlBlobStore
         */
-       public function newSqlBlobStore( $wikiId = false ) {
+       public function newSqlBlobStore( $dbDomain = false ) {
+               $lb = $this->lbFactory->getMainLB( $dbDomain );
                $store = new SqlBlobStore(
-                       $this->loadBalancer,
+                       $lb,
+                       $this->extStoreAccess,
                        $this->cache,
-                       $wikiId
+                       $dbDomain
                );
 
-               $store->setCompressBlobs( $this->config->get( 'CompressRevisions' ) );
-               $store->setCacheExpiry( $this->config->get( 'RevisionCacheExpiry' ) );
-               $store->setUseExternalStore( $this->config->get( 'DefaultExternalStore' ) !== false );
+               $store->setCompressBlobs( $this->options->get( 'CompressRevisions' ) );
+               $store->setCacheExpiry( $this->options->get( 'RevisionCacheExpiry' ) );
+               $store->setUseExternalStore( $this->options->get( 'DefaultExternalStore' ) !== false );
 
-               if ( $this->config->get( 'LegacyEncoding' ) ) {
-                       $store->setLegacyEncoding( $this->config->get( 'LegacyEncoding' ), $this->contLang );
+               if ( $this->options->get( 'LegacyEncoding' ) ) {
+                       $store->setLegacyEncoding( $this->options->get( 'LegacyEncoding' ), $this->contLang );
                }
 
                return $store;