Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
CentralAuthWikiListService | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getWikiList | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\CentralAuth; |
4 | |
5 | use MediaWiki\Config\ServiceOptions; |
6 | use MediaWiki\Extension\CentralAuth\Hooks\CentralAuthHookRunner; |
7 | use MediaWiki\HookContainer\HookContainer; |
8 | use MediaWiki\MainConfigNames; |
9 | |
10 | /** |
11 | * Handle knowledge of other wikis in this CentralAuth farm. |
12 | * |
13 | * @since 1.37 |
14 | * @author Taavi "Majavah" Väänänen |
15 | */ |
16 | class CentralAuthWikiListService { |
17 | |
18 | private ServiceOptions $options; |
19 | private CentralAuthHookRunner $hookRunner; |
20 | |
21 | /** @var string[]|null Cached array of known wikis. */ |
22 | private $wikiList = null; |
23 | |
24 | /** @internal Only public for ServiceWiring use */ |
25 | public const CONSTRUCTOR_OPTIONS = [ |
26 | MainConfigNames::LocalDatabases, |
27 | ]; |
28 | |
29 | /** |
30 | * @param ServiceOptions $options Options used by this service, containing keys in ::CONSTRUCTOR_OPTIONS |
31 | * @param HookContainer $hookContainer |
32 | */ |
33 | public function __construct( ServiceOptions $options, HookContainer $hookContainer ) { |
34 | $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS ); |
35 | $this->options = $options; |
36 | $this->hookRunner = new CentralAuthHookRunner( $hookContainer ); |
37 | } |
38 | |
39 | /** |
40 | * @return string[] all database names of wikis in this CentralAuth farm |
41 | */ |
42 | public function getWikiList(): array { |
43 | if ( $this->wikiList === null ) { |
44 | $list = null; |
45 | |
46 | $this->hookRunner->onCentralAuthWikiList( $list ); |
47 | |
48 | $this->wikiList = $list ?? $this->options->get( MainConfigNames::LocalDatabases ); |
49 | } |
50 | |
51 | return $this->wikiList; |
52 | } |
53 | } |