Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
CrossWikiBlockTargetFactory | |
0.00% |
0 / 14 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getFactory | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Block; |
4 | |
5 | use MediaWiki\Config\ServiceOptions; |
6 | use MediaWiki\DAO\WikiAwareEntity; |
7 | use MediaWiki\User\ActorStoreFactory; |
8 | use MediaWiki\User\UserNameUtils; |
9 | use MediaWiki\WikiMap\WikiMap; |
10 | |
11 | /** |
12 | * Factory for BlockTargetFactory objects. This is needed for cross-wiki block |
13 | * operations, since BlockTargetFactory needs a wiki ID passed to its constructor. |
14 | * |
15 | * @since 1.44 |
16 | */ |
17 | class CrossWikiBlockTargetFactory { |
18 | private ActorStoreFactory $actorStoreFactory; |
19 | private UserNameUtils $userNameUtils; |
20 | private ServiceOptions $options; |
21 | |
22 | /** @var BlockTargetFactory[] */ |
23 | private array $storeCache = []; |
24 | |
25 | /** |
26 | * @internal Only for use by ServiceWiring |
27 | */ |
28 | public const CONSTRUCTOR_OPTIONS = BlockTargetFactory::CONSTRUCTOR_OPTIONS; |
29 | |
30 | public function __construct( |
31 | ServiceOptions $options, |
32 | ActorStoreFactory $actorStoreFactory, |
33 | UserNameUtils $userNameUtils |
34 | ) { |
35 | $this->options = $options; |
36 | $this->actorStoreFactory = $actorStoreFactory; |
37 | $this->userNameUtils = $userNameUtils; |
38 | } |
39 | |
40 | /** |
41 | * @param string|false $wikiId |
42 | * @return BlockTargetFactory |
43 | */ |
44 | public function getFactory( $wikiId = WikiAwareEntity::LOCAL ) { |
45 | if ( is_string( $wikiId ) && WikiMap::getCurrentWikiId() === $wikiId ) { |
46 | $wikiId = WikiAwareEntity::LOCAL; |
47 | } |
48 | |
49 | $storeCacheKey = $wikiId === WikiAwareEntity::LOCAL ? 'LOCAL' : 'crosswikistore-' . $wikiId; |
50 | if ( !isset( $this->storeCache[$storeCacheKey] ) ) { |
51 | $this->storeCache[$storeCacheKey] = new BlockTargetFactory( |
52 | $this->options, |
53 | $this->actorStoreFactory->getUserIdentityLookup( $wikiId ), |
54 | $this->userNameUtils, |
55 | $wikiId |
56 | ); |
57 | } |
58 | return $this->storeCache[$storeCacheKey]; |
59 | } |
60 | } |