4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
19 * Attribution notice: when this file was created, much of its content was taken
20 * from the Revision.php file as present in release 1.30. Refer to the history
21 * of that file for original authorship.
26 namespace MediaWiki\Storage
;
30 use MediaWiki\Logger\Spi
as LoggerSpi
;
32 use Wikimedia\Assert\Assert
;
33 use Wikimedia\Rdbms\ILBFactory
;
36 * Factory service for RevisionStore instances. This allows RevisionStores to be created for
39 * @warning Beware compatibility issues with schema migration in the context of cross-wiki access!
40 * This class assumes that all wikis are at compatible migration stages for all relevant schemas.
41 * Relevant schemas are: revision storage (MCR), the revision comment table, and the actor table.
42 * Migration stages are compatible as long as a) there are no wikis in the cluster that only write
43 * the old schema or b) there are no wikis that read only the new schema.
47 class RevisionStoreFactory
{
49 /** @var BlobStoreFactory */
50 private $blobStoreFactory;
51 /** @var ILBFactory */
52 private $dbLoadBalancerFactory;
53 /** @var WANObjectCache */
56 private $loggerProvider;
58 /** @var CommentStore */
59 private $commentStore;
60 /** @var ActorMigration */
61 private $actorMigration;
62 /** @var int One of the MIGRATION_* constants */
63 private $mcrMigrationStage;
66 * @see $wgContentHandlerUseDB
68 private $contentHandlerUseDB;
70 /** @var NameTableStoreFactory */
74 * @param ILBFactory $dbLoadBalancerFactory
75 * @param BlobStoreFactory $blobStoreFactory
76 * @param NameTableStoreFactory $nameTables
77 * @param WANObjectCache $cache
78 * @param CommentStore $commentStore
79 * @param ActorMigration $actorMigration
80 * @param int $migrationStage
81 * @param LoggerSpi $loggerProvider
82 * @param bool $contentHandlerUseDB see {@link $wgContentHandlerUseDB}. Must be the same
83 * for all wikis in the cluster. Will go away after MCR migration.
85 public function __construct(
86 ILBFactory
$dbLoadBalancerFactory,
87 BlobStoreFactory
$blobStoreFactory,
88 NameTableStoreFactory
$nameTables,
89 WANObjectCache
$cache,
90 CommentStore
$commentStore,
91 ActorMigration
$actorMigration,
93 LoggerSpi
$loggerProvider,
96 Assert
::parameterType( 'integer', $migrationStage, '$migrationStage' );
97 $this->dbLoadBalancerFactory
= $dbLoadBalancerFactory;
98 $this->blobStoreFactory
= $blobStoreFactory;
99 $this->nameTables
= $nameTables;
100 $this->cache
= $cache;
101 $this->commentStore
= $commentStore;
102 $this->actorMigration
= $actorMigration;
103 $this->mcrMigrationStage
= $migrationStage;
104 $this->loggerProvider
= $loggerProvider;
105 $this->contentHandlerUseDB
= $contentHandlerUseDB;
111 * @param bool|string $wikiId false for the current domain / wikid
113 * @return RevisionStore for the given wikiId with all necessary services and a logger
115 public function getRevisionStore( $wikiId = false ) {
116 Assert
::parameterType( 'string|boolean', $wikiId, '$wikiId' );
118 $store = new RevisionStore(
119 $this->dbLoadBalancerFactory
->getMainLB( $wikiId ),
120 $this->blobStoreFactory
->newSqlBlobStore( $wikiId ),
121 $this->cache
, // Pass local cache instance; Leave cache sharing to RevisionStore.
123 $this->nameTables
->getContentModels( $wikiId ),
124 $this->nameTables
->getSlotRoles( $wikiId ),
125 $this->mcrMigrationStage
,
126 $this->actorMigration
,
130 $store->setLogger( $this->loggerProvider
->getLogger( 'RevisionStore' ) );
131 $store->setContentHandlerUseDB( $this->contentHandlerUseDB
);