Merge "Simplify HTMLTitleTextField::validate"
[lhc/web/wiklou.git] / includes / Storage / RevisionStoreFactory.php
1 <?php
2
3 /**
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.
8 *
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.
13 *
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
18 *
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.
22 *
23 * @file
24 */
25
26 namespace MediaWiki\Storage;
27
28 use ActorMigration;
29 use CommentStore;
30 use MediaWiki\Logger\Spi as LoggerSpi;
31 use WANObjectCache;
32 use Wikimedia\Assert\Assert;
33 use Wikimedia\Rdbms\ILBFactory;
34
35 /**
36 * Factory service for RevisionStore instances. This allows RevisionStores to be created for
37 * cross-wiki access.
38 *
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.
44 *
45 * @since 1.32
46 */
47 class RevisionStoreFactory {
48
49 /** @var BlobStoreFactory */
50 private $blobStoreFactory;
51 /** @var ILBFactory */
52 private $dbLoadBalancerFactory;
53 /** @var WANObjectCache */
54 private $cache;
55 /** @var LoggerSpi */
56 private $loggerProvider;
57
58 /** @var CommentStore */
59 private $commentStore;
60 /** @var ActorMigration */
61 private $actorMigration;
62 /** @var int One of the MIGRATION_* constants */
63 private $mcrMigrationStage;
64 /**
65 * @var bool
66 * @see $wgContentHandlerUseDB
67 */
68 private $contentHandlerUseDB;
69
70 /** @var NameTableStoreFactory */
71 private $nameTables;
72
73 /**
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.
84 */
85 public function __construct(
86 ILBFactory $dbLoadBalancerFactory,
87 BlobStoreFactory $blobStoreFactory,
88 NameTableStoreFactory $nameTables,
89 WANObjectCache $cache,
90 CommentStore $commentStore,
91 ActorMigration $actorMigration,
92 $migrationStage,
93 LoggerSpi $loggerProvider,
94 $contentHandlerUseDB
95 ) {
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;
106 }
107
108 /**
109 * @since 1.32
110 *
111 * @param bool|string $wikiId false for the current domain / wikid
112 *
113 * @return RevisionStore for the given wikiId with all necessary services and a logger
114 */
115 public function getRevisionStore( $wikiId = false ) {
116 Assert::parameterType( 'string|boolean', $wikiId, '$wikiId' );
117
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.
122 $this->commentStore,
123 $this->nameTables->getContentModels( $wikiId ),
124 $this->nameTables->getSlotRoles( $wikiId ),
125 $this->mcrMigrationStage,
126 $this->actorMigration,
127 $wikiId
128 );
129
130 $store->setLogger( $this->loggerProvider->getLogger( 'RevisionStore' ) );
131 $store->setContentHandlerUseDB( $this->contentHandlerUseDB );
132
133 return $store;
134 }
135 }