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