Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
CrossWikiBlockTargetFactory
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 2
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 getFactory
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2
3namespace MediaWiki\Block;
4
5use MediaWiki\Config\ServiceOptions;
6use MediaWiki\DAO\WikiAwareEntity;
7use MediaWiki\User\ActorStoreFactory;
8use MediaWiki\User\UserNameUtils;
9use 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 */
17class 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    public function getFactory( string|false $wikiId = WikiAwareEntity::LOCAL ) {
41        if ( is_string( $wikiId ) && WikiMap::getCurrentWikiId() === $wikiId ) {
42            $wikiId = WikiAwareEntity::LOCAL;
43        }
44
45        $storeCacheKey = $wikiId === WikiAwareEntity::LOCAL ? 'LOCAL' : 'crosswikistore-' . $wikiId;
46        if ( !isset( $this->storeCache[$storeCacheKey] ) ) {
47            $this->storeCache[$storeCacheKey] = new BlockTargetFactory(
48                $this->options,
49                $this->actorStoreFactory->getUserIdentityLookup( $wikiId ),
50                $this->userNameUtils,
51                $wikiId
52            );
53        }
54        return $this->storeCache[$storeCacheKey];
55    }
56}