Merge "Reuse different message in SpecialEditWatchlist"
[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 /**
71 * @param ILBFactory $dbLoadBalancerFactory
72 * @param BlobStoreFactory $blobStoreFactory
73 * @param WANObjectCache $cache
74 * @param CommentStore $commentStore
75 * @param ActorMigration $actorMigration
76 * @param int $migrationStage
77 * @param LoggerSpi $loggerProvider
78 * @param bool $contentHandlerUseDB see {@link $wgContentHandlerUseDB}. Must be the same
79 * for all wikis in the cluster. Will go away after MCR migration.
80 */
81 public function __construct(
82 ILBFactory $dbLoadBalancerFactory,
83 BlobStoreFactory $blobStoreFactory,
84 WANObjectCache $cache,
85 CommentStore $commentStore,
86 ActorMigration $actorMigration,
87 $migrationStage,
88 LoggerSpi $loggerProvider,
89 $contentHandlerUseDB
90 ) {
91 Assert::parameterType( 'integer', $migrationStage, '$migrationStage' );
92 $this->dbLoadBalancerFactory = $dbLoadBalancerFactory;
93 $this->blobStoreFactory = $blobStoreFactory;
94 $this->cache = $cache;
95 $this->commentStore = $commentStore;
96 $this->actorMigration = $actorMigration;
97 $this->mcrMigrationStage = $migrationStage;
98 $this->loggerProvider = $loggerProvider;
99 $this->contentHandlerUseDB = $contentHandlerUseDB;
100 }
101 /**
102
103 /**
104 * @since 1.32
105 *
106 * @param bool|string $wikiId false for the current domain / wikid
107 *
108 * @return RevisionStore for the given wikiId with all necessary services and a logger
109 */
110 public function getRevisionStore( $wikiId = false ) {
111 Assert::parameterType( 'string|boolean', $wikiId, '$wikiId' );
112
113 $store = new RevisionStore(
114 $this->dbLoadBalancerFactory->getMainLB( $wikiId ),
115 $this->blobStoreFactory->newSqlBlobStore( $wikiId ),
116 $this->cache, // Pass local cache instance; Leave cache sharing to RevisionStore.
117 $this->commentStore,
118 $this->getContentModelStore( $wikiId ),
119 $this->getSlotRoleStore( $wikiId ),
120 $this->mcrMigrationStage,
121 $this->actorMigration,
122 $wikiId
123 );
124
125 $store->setLogger( $this->loggerProvider->getLogger( 'RevisionStore' ) );
126 $store->setContentHandlerUseDB( $this->contentHandlerUseDB );
127
128 return $store;
129 }
130
131 /**
132 * @param string $wikiId
133 * @return NameTableStore
134 */
135 private function getContentModelStore( $wikiId ) {
136 // XXX: a dedicated ContentModelStore subclass would avoid hard-coding
137 // knowledge about the schema here.
138 return new NameTableStore(
139 $this->dbLoadBalancerFactory->getMainLB( $wikiId ),
140 $this->cache, // Pass local cache instance; Leave cache sharing to NameTableStore.
141 $this->loggerProvider->getLogger( 'NameTableSqlStore' ),
142 'content_models',
143 'model_id',
144 'model_name',
145 null,
146 $wikiId
147 );
148 }
149
150 /**
151 * @param string $wikiId
152 * @return NameTableStore
153 */
154 private function getSlotRoleStore( $wikiId ) {
155 // XXX: a dedicated ContentModelStore subclass would avoid hard-coding
156 // knowledge about the schema here.
157 return new NameTableStore(
158 $this->dbLoadBalancerFactory->getMainLB( $wikiId ),
159 $this->cache, // Pass local cache instance; Leave cache sharing to NameTableStore.
160 $this->loggerProvider->getLogger( 'NameTableSqlStore' ),
161 'slot_roles',
162 'role_id',
163 'role_name',
164 'strtolower',
165 $wikiId
166 );
167 }
168
169 }