Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
WikibaseSearchConfig | |
0.00% |
0 / 14 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
newFromGlobals | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
has | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
enabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Wikibase\Search\Elastic; |
4 | |
5 | use MediaWiki\Config\Config; |
6 | use MediaWiki\Config\ConfigException; |
7 | use MediaWiki\Config\GlobalVarConfig; |
8 | |
9 | /** |
10 | * Config class for Wikibase search configs. |
11 | * Provides BC wrapper for old Wikibase search configs. |
12 | */ |
13 | class WikibaseSearchConfig implements Config { |
14 | |
15 | private const WIKIBASE_SEARCH_CONFIG_PREFIX = 'wgWBCS'; |
16 | |
17 | /** |
18 | * Global config. |
19 | * @var GlobalVarConfig |
20 | */ |
21 | private $globals; |
22 | |
23 | /** |
24 | * Wikibase entitySearch config - for BC. |
25 | * @var array |
26 | */ |
27 | private $wikibaseSettings; |
28 | |
29 | public function __construct( array $wikibaseSettings ) { |
30 | $this->globals = new GlobalVarConfig( self::WIKIBASE_SEARCH_CONFIG_PREFIX ); |
31 | $this->wikibaseSettings = $wikibaseSettings; |
32 | } |
33 | |
34 | /** |
35 | * Create config from globals |
36 | * @return WikibaseSearchConfig |
37 | */ |
38 | public static function newFromGlobals() { |
39 | // BC with Wikidata settings |
40 | return new static( $GLOBALS['wgWBRepoSettings']['entitySearch'] ?? [] ); |
41 | } |
42 | |
43 | /** |
44 | * Get a configuration variable such as "Sitename" or "UploadMaintenance." |
45 | * @param string $name Name of configuration option |
46 | * @param mixed $default Return if value not found. |
47 | * @return mixed Value configured |
48 | * @throws ConfigException |
49 | */ |
50 | public function get( $name, $default = null ) { |
51 | $compat_name = lcfirst( $name ); |
52 | // TODO: deprecate and remove these BC settings |
53 | if ( array_key_exists( $compat_name, $this->wikibaseSettings ) ) { |
54 | return $this->wikibaseSettings[$compat_name]; |
55 | } |
56 | if ( $this->globals->has( $name ) ) { |
57 | $value = $this->globals->get( $name ); |
58 | if ( $value !== null ) { |
59 | return $value; |
60 | } |
61 | } |
62 | return $default; |
63 | } |
64 | |
65 | /** |
66 | * Check whether a configuration option is set for the given name |
67 | * |
68 | * @param string $name Name of configuration option |
69 | * @return bool |
70 | */ |
71 | public function has( $name ) { |
72 | return $this->globals->has( $name ) || |
73 | array_key_exists( lcfirst( $name ), $this->wikibaseSettings ); |
74 | } |
75 | |
76 | /** |
77 | * Check whether search functionality for this extension is enabled. |
78 | * |
79 | * @return bool |
80 | */ |
81 | public function enabled() { |
82 | // Ignore Wikibase setting, it should not disable this one |
83 | return $this->globals->get( 'UseCirrus' ); |
84 | } |
85 | |
86 | } |