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\Revision
;
30 use MediaWiki\Logger\Spi
as LoggerSpi
;
31 use MediaWiki\Storage\BlobStoreFactory
;
32 use MediaWiki\Storage\NameTableStoreFactory
;
34 use Wikimedia\Assert\Assert
;
35 use Wikimedia\Rdbms\ILBFactory
;
38 * Factory service for RevisionStore instances. This allows RevisionStores to be created for
41 * @warning Beware compatibility issues with schema migration in the context of cross-wiki access!
42 * This class assumes that all wikis are at compatible migration stages for all relevant schemas.
43 * Relevant schemas are: revision storage (MCR), the revision comment table, and the actor table.
44 * Migration stages are compatible as long as a) there are no wikis in the cluster that only write
45 * the old schema or b) there are no wikis that read only the new schema.
49 class RevisionStoreFactory
{
51 /** @var BlobStoreFactory */
52 private $blobStoreFactory;
53 /** @var ILBFactory */
54 private $dbLoadBalancerFactory;
55 /** @var WANObjectCache */
58 private $loggerProvider;
60 /** @var CommentStore */
61 private $commentStore;
62 /** @var ActorMigration */
63 private $actorMigration;
64 /** @var int One of the MIGRATION_* constants */
65 private $mcrMigrationStage;
68 * @see $wgContentHandlerUseDB
70 private $contentHandlerUseDB;
72 /** @var NameTableStoreFactory */
76 * @param ILBFactory $dbLoadBalancerFactory
77 * @param BlobStoreFactory $blobStoreFactory
78 * @param NameTableStoreFactory $nameTables
79 * @param WANObjectCache $cache
80 * @param CommentStore $commentStore
81 * @param ActorMigration $actorMigration
82 * @param int $migrationStage
83 * @param LoggerSpi $loggerProvider
84 * @param bool $contentHandlerUseDB see {@link $wgContentHandlerUseDB}. Must be the same
85 * for all wikis in the cluster. Will go away after MCR migration.
87 public function __construct(
88 ILBFactory
$dbLoadBalancerFactory,
89 BlobStoreFactory
$blobStoreFactory,
90 NameTableStoreFactory
$nameTables,
91 WANObjectCache
$cache,
92 CommentStore
$commentStore,
93 ActorMigration
$actorMigration,
95 LoggerSpi
$loggerProvider,
98 Assert
::parameterType( 'integer', $migrationStage, '$migrationStage' );
99 $this->dbLoadBalancerFactory
= $dbLoadBalancerFactory;
100 $this->blobStoreFactory
= $blobStoreFactory;
101 $this->nameTables
= $nameTables;
102 $this->cache
= $cache;
103 $this->commentStore
= $commentStore;
104 $this->actorMigration
= $actorMigration;
105 $this->mcrMigrationStage
= $migrationStage;
106 $this->loggerProvider
= $loggerProvider;
107 $this->contentHandlerUseDB
= $contentHandlerUseDB;
113 * @param bool|string $wikiId false for the current domain / wikid
115 * @return RevisionStore for the given wikiId with all necessary services and a logger
117 public function getRevisionStore( $wikiId = false ) {
118 Assert
::parameterType( 'string|boolean', $wikiId, '$wikiId' );
120 $store = new RevisionStore(
121 $this->dbLoadBalancerFactory
->getMainLB( $wikiId ),
122 $this->blobStoreFactory
->newSqlBlobStore( $wikiId ),
123 $this->cache
, // Pass local cache instance; Leave cache sharing to RevisionStore.
125 $this->nameTables
->getContentModels( $wikiId ),
126 $this->nameTables
->getSlotRoles( $wikiId ),
127 $this->mcrMigrationStage
,
128 $this->actorMigration
,
132 $store->setLogger( $this->loggerProvider
->getLogger( 'RevisionStore' ) );
133 $store->setContentHandlerUseDB( $this->contentHandlerUseDB
);