Debian Codegraph @

includes/Revision/RevisionStoreFactory.php

raw symbols SCIP
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 (that file was removed entirely in 1.37,
22 * but its history can still be found in prior versions of MediaWiki).
23 *
24 * @file
25 */
26
27 namespace MediaWiki\Revision;
28
29 use MediaWiki\CommentStore\CommentStore;
30 use MediaWiki\Content\IContentHandlerFactory;
31 use MediaWiki\HookContainer\HookContainer;
32 use MediaWiki\Page\PageStoreFactory;
33 use MediaWiki\Storage\BlobStoreFactory;
34 use MediaWiki\Storage\NameTableStoreFactory;
35 use MediaWiki\Title\TitleFactory;
36 use MediaWiki\User\ActorStore;
37 use MediaWiki\User\ActorStoreFactory;
38 use Psr\Log\LoggerInterface;
39 use Wikimedia\Assert\Assert;
40 use Wikimedia\ObjectCache\BagOStuff;
41 use Wikimedia\ObjectCache\WANObjectCache;
42 use Wikimedia\Rdbms\ILBFactory;
43
44 /**
45 * Factory service for RevisionStore instances. This allows RevisionStores to be created for
46 * cross-wiki access.
47 *
48 * @warning Beware compatibility issues with schema migration in the context of cross-wiki access!
49 * This class assumes that all wikis are at compatible migration stages for all relevant schemas.
50 * Relevant schemas are: revision storage (MCR), the revision comment table, and the actor table.
51 * Migration stages are compatible as long as a) there are no wikis in the cluster that only write
52 * the old schema or b) there are no wikis that read only the new schema.
53 *
54 * @since 1.32
55 */
56 class RevisionStoreFactory {
57
58 /** @var BlobStoreFactory */
59 private $blobStoreFactory;
60 /** @var ILBFactory */
61 private $dbLoadBalancerFactory;
62 /** @var WANObjectCache */
63 private $cache;
64 /** @var BagOStuff */
65 private $localCache;
66 /** @var LoggerInterface */
67 private $logger;
68
69 /** @var CommentStore */
70 private $commentStore;
71 /** @var ActorStoreFactory */
72 private $actorStoreFactory;
73 /** @var NameTableStoreFactory */
74 private $nameTables;
75
76 /** @var SlotRoleRegistry */
77 private $slotRoleRegistry;
78
79 /** @var IContentHandlerFactory */
80 private $contentHandlerFactory;
81
82 /** @var PageStoreFactory */
83 private $pageStoreFactory;
84
85 /** @var TitleFactory */
86 private $titleFactory;
87
88 /** @var HookContainer */
89 private $hookContainer;
90
91 /**
92 * @param ILBFactory $dbLoadBalancerFactory
93 * @param BlobStoreFactory $blobStoreFactory
94 * @param NameTableStoreFactory $nameTables
95 * @param SlotRoleRegistry $slotRoleRegistry
96 * @param WANObjectCache $cache
97 * @param BagOStuff $localCache
98 * @param CommentStore $commentStore
99 * @param ActorStoreFactory $actorStoreFactory
100 * @param LoggerInterface $logger
101 * @param IContentHandlerFactory $contentHandlerFactory
102 * @param PageStoreFactory $pageStoreFactory
103 * @param TitleFactory $titleFactory
104 * @param HookContainer $hookContainer
105 */
106 public function __construct(
107 ILBFactory $dbLoadBalancerFactory,
108 BlobStoreFactory $blobStoreFactory,
109 NameTableStoreFactory $nameTables,
110 SlotRoleRegistry $slotRoleRegistry,
111 WANObjectCache $cache,
112 BagOStuff $localCache,
113 CommentStore $commentStore,
114 ActorStoreFactory $actorStoreFactory,
115 LoggerInterface $logger,
116 IContentHandlerFactory $contentHandlerFactory,
117 PageStoreFactory $pageStoreFactory,
118 TitleFactory $titleFactory,
119 HookContainer $hookContainer
120 ) {
121 $this->dbLoadBalancerFactory = $dbLoadBalancerFactory;
122 $this->blobStoreFactory = $blobStoreFactory;
123 $this->slotRoleRegistry = $slotRoleRegistry;
124 $this->nameTables = $nameTables;
125 $this->cache = $cache;
126 $this->localCache = $localCache;
127 $this->commentStore = $commentStore;
128 $this->actorStoreFactory = $actorStoreFactory;
129 $this->logger = $logger;
130 $this->contentHandlerFactory = $contentHandlerFactory;
131 $this->pageStoreFactory = $pageStoreFactory;
132 $this->titleFactory = $titleFactory;
133 $this->hookContainer = $hookContainer;
134 }
135
136 /**
137 * @since 1.32
138 *
139 * @param false|string $dbDomain DB domain of the relevant wiki or false for the current one
140 *
141 * @return RevisionStore for the given wikiId with all necessary services
142 */
143 public function getRevisionStore( $dbDomain = false ): RevisionStore {
144 return $this->getStore(
145 $dbDomain,
146 $this->actorStoreFactory->getActorStore( $dbDomain )
147 );
148 }
149
150 /**
151 * @since 1.42
152 *
153 * @param false|string $dbDomain DB domain of the relevant wiki or false for the current one
154 *
155 * @return RevisionStore for the given wikiId with all necessary services
156 */
157 public function getRevisionStoreForImport( $dbDomain = false ): RevisionStore {
158 return $this->getStore(
159 $dbDomain,
160 $this->actorStoreFactory->getActorStoreForImport( $dbDomain )
161 );
162 }
163
164 /**
165 * @since 1.43
166 *
167 * @param false|string $dbDomain DB domain of the relevant wiki or false for the current one
168 *
169 * @return RevisionStore for the given wikiId with all necessary services
170 */
171 public function getRevisionStoreForUndelete( $dbDomain = false ): RevisionStore {
172 return $this->getStore(
173 $dbDomain,
174 $this->actorStoreFactory->getActorStoreForUndelete( $dbDomain )
175 );
176 }
177
178 /**
179 * @param false|string $dbDomain
180 * @param ActorStore $actorStore
181 *
182 * @return RevisionStore
183 */
184 private function getStore( $dbDomain, ActorStore $actorStore ) {
185 Assert::parameterType( [ 'string', 'false' ], $dbDomain, '$dbDomain' );
186
187 $store = new RevisionStore(
188 $this->dbLoadBalancerFactory->getMainLB( $dbDomain ),
189 $this->blobStoreFactory->newSqlBlobStore( $dbDomain ),
190 $this->cache, // Pass cache local to wiki; Leave cache sharing to RevisionStore.
191 $this->localCache,
192 $this->commentStore,
193 $this->nameTables->getContentModels( $dbDomain ),
194 $this->nameTables->getSlotRoles( $dbDomain ),
195 $this->slotRoleRegistry,
196 $actorStore,
197 $this->contentHandlerFactory,
198 $this->pageStoreFactory->getPageStore( $dbDomain ),
199 $this->titleFactory,
200 $this->hookContainer,
201 $dbDomain
202 );
203
204 $store->setLogger( $this->logger );
205
206 return $store;
207 }
208 }