1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* Attribution notice: when this file was created, much of its content was taken
* from the Revision.php file as present in release 1.30. Refer to the history
* of that file for original authorship (that file was removed entirely in 1.37,
* but its history can still be found in prior versions of MediaWiki).
*
* @file
*/
namespace MediaWiki\Revision;
use MediaWiki\CommentStore\CommentStore;
use MediaWiki\Content\IContentHandlerFactory;
use MediaWiki\HookContainer\HookContainer;
use MediaWiki\Page\PageStoreFactory;
use MediaWiki\Storage\BlobStoreFactory;
use MediaWiki\Storage\NameTableStoreFactory;
use MediaWiki\Title\TitleFactory;
use MediaWiki\User\ActorStore;
use MediaWiki\User\ActorStoreFactory;
use Psr\Log\LoggerInterface;
use Wikimedia\Assert\Assert;
use Wikimedia\ObjectCache\BagOStuff;
use Wikimedia\ObjectCache\WANObjectCache;
use Wikimedia\Rdbms\ILBFactory;
/**
* Factory service for RevisionStore instances. This allows RevisionStores to be created for
* cross-wiki access.
*
* @warning Beware compatibility issues with schema migration in the context of cross-wiki access!
* This class assumes that all wikis are at compatible migration stages for all relevant schemas.
* Relevant schemas are: revision storage (MCR), the revision comment table, and the actor table.
* Migration stages are compatible as long as a) there are no wikis in the cluster that only write
* the old schema or b) there are no wikis that read only the new schema.
*
* @since 1.32
*/
class RevisionStoreFactory {
/** @var BlobStoreFactory */
private $blobStoreFactory;
/** @var ILBFactory */
private $dbLoadBalancerFactory;
/** @var WANObjectCache */
private $cache;
/** @var BagOStuff */
private $localCache;
/** @var LoggerInterface */
private $logger;
/** @var CommentStore */
private $commentStore;
/** @var ActorStoreFactory */
private $actorStoreFactory;
/** @var NameTableStoreFactory */
private $nameTables;
/** @var SlotRoleRegistry */
private $slotRoleRegistry;
/** @var IContentHandlerFactory */
private $contentHandlerFactory;
/** @var PageStoreFactory */
private $pageStoreFactory;
/** @var TitleFactory */
private $titleFactory;
/** @var HookContainer */
private $hookContainer;
/**
* @param ILBFactory $dbLoadBalancerFactory
* @param BlobStoreFactory $blobStoreFactory
* @param NameTableStoreFactory $nameTables
* @param SlotRoleRegistry $slotRoleRegistry
* @param WANObjectCache $cache
* @param BagOStuff $localCache
* @param CommentStore $commentStore
* @param ActorStoreFactory $actorStoreFactory
* @param LoggerInterface $logger
* @param IContentHandlerFactory $contentHandlerFactory
* @param PageStoreFactory $pageStoreFactory
* @param TitleFactory $titleFactory
* @param HookContainer $hookContainer
*/
public function __construct(
ILBFactory $dbLoadBalancerFactory,
BlobStoreFactory $blobStoreFactory,
NameTableStoreFactory $nameTables,
SlotRoleRegistry $slotRoleRegistry,
WANObjectCache $cache,
BagOStuff $localCache,
CommentStore $commentStore,
ActorStoreFactory $actorStoreFactory,
LoggerInterface $logger,
IContentHandlerFactory $contentHandlerFactory,
PageStoreFactory $pageStoreFactory,
TitleFactory $titleFactory,
HookContainer $hookContainer
) {
$this->dbLoadBalancerFactory = $dbLoadBalancerFactory;
$this->blobStoreFactory = $blobStoreFactory;
$this->slotRoleRegistry = $slotRoleRegistry;
$this->nameTables = $nameTables;
$this->cache = $cache;
$this->localCache = $localCache;
$this->commentStore = $commentStore;
$this->actorStoreFactory = $actorStoreFactory;
$this->logger = $logger;
$this->contentHandlerFactory = $contentHandlerFactory;
$this->pageStoreFactory = $pageStoreFactory;
$this->titleFactory = $titleFactory;
$this->hookContainer = $hookContainer;
}
/**
* @since 1.32
*
* @param false|string $dbDomain DB domain of the relevant wiki or false for the current one
*
* @return RevisionStore for the given wikiId with all necessary services
*/
public function getRevisionStore( $dbDomain = false ): RevisionStore {
return $this->getStore(
$dbDomain,
$this->actorStoreFactory->getActorStore( $dbDomain )
);
}
/**
* @since 1.42
*
* @param false|string $dbDomain DB domain of the relevant wiki or false for the current one
*
* @return RevisionStore for the given wikiId with all necessary services
*/
public function getRevisionStoreForImport( $dbDomain = false ): RevisionStore {
return $this->getStore(
$dbDomain,
$this->actorStoreFactory->getActorStoreForImport( $dbDomain )
);
}
/**
* @since 1.43
*
* @param false|string $dbDomain DB domain of the relevant wiki or false for the current one
*
* @return RevisionStore for the given wikiId with all necessary services
*/
public function getRevisionStoreForUndelete( $dbDomain = false ): RevisionStore {
return $this->getStore(
$dbDomain,
$this->actorStoreFactory->getActorStoreForUndelete( $dbDomain )
);
}
/**
* @param false|string $dbDomain
* @param ActorStore $actorStore
*
* @return RevisionStore
*/
private function getStore( $dbDomain, ActorStore $actorStore ) {
Assert::parameterType( [ 'string', 'false' ], $dbDomain, '$dbDomain' );
$store = new RevisionStore(
$this->dbLoadBalancerFactory->getMainLB( $dbDomain ),
$this->blobStoreFactory->newSqlBlobStore( $dbDomain ),
$this->cache, // Pass cache local to wiki; Leave cache sharing to RevisionStore.
$this->localCache,
$this->commentStore,
$this->nameTables->getContentModels( $dbDomain ),
$this->nameTables->getSlotRoles( $dbDomain ),
$this->slotRoleRegistry,
$actorStore,
$this->contentHandlerFactory,
$this->pageStoreFactory->getPageStore( $dbDomain ),
$this->titleFactory,
$this->hookContainer,
$dbDomain
);
$store->setLogger( $this->logger );
return $store;
}
}
|