Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
92.68% |
38 / 41 |
|
66.67% |
4 / 6 |
CRAP | |
0.00% |
0 / 1 |
HTMLSelectNamespace | |
95.00% |
38 / 40 |
|
66.67% |
4 / 6 |
9 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
4 | |||
getInputHTML | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
getInputOOUI | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
getInputCodex | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
getOOUIModules | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
shouldInfuseOOUI | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\HTMLForm\Field; |
4 | |
5 | use MediaWiki\Html\Html; |
6 | use MediaWiki\HTMLForm\HTMLFormField; |
7 | |
8 | /** |
9 | * Wrapper for Html::namespaceSelector to use in HTMLForm |
10 | * |
11 | * @stable to extend |
12 | */ |
13 | class HTMLSelectNamespace extends HTMLFormField { |
14 | |
15 | /** @var string|null */ |
16 | protected $mAllValue; |
17 | /** @var bool */ |
18 | protected $mUserLang; |
19 | /** @var int[]|null */ |
20 | protected $mInclude; |
21 | |
22 | /** |
23 | * @stable to call |
24 | * @inheritDoc |
25 | */ |
26 | public function __construct( $params ) { |
27 | parent::__construct( $params ); |
28 | |
29 | $this->mAllValue = array_key_exists( 'all', $params ) |
30 | ? $params['all'] |
31 | : 'all'; |
32 | $this->mUserLang = array_key_exists( 'in-user-lang', $params ) |
33 | ? $params['in-user-lang'] |
34 | : false; |
35 | |
36 | $this->mInclude = array_key_exists( 'include', $params ) |
37 | ? $params['include'] |
38 | : null; |
39 | } |
40 | |
41 | /** |
42 | * @inheritDoc |
43 | * @stable to override |
44 | */ |
45 | public function getInputHTML( $value ) { |
46 | return Html::namespaceSelector( |
47 | [ |
48 | 'selected' => $value, |
49 | 'all' => $this->mAllValue, |
50 | 'in-user-lang' => $this->mUserLang, |
51 | 'include' => $this->mInclude |
52 | ], [ |
53 | 'name' => $this->mName, |
54 | 'id' => $this->mID, |
55 | 'class' => 'namespaceselector', |
56 | ] |
57 | ); |
58 | } |
59 | |
60 | /** |
61 | * @inheritDoc |
62 | * @stable to override |
63 | */ |
64 | public function getInputOOUI( $value ) { |
65 | return new \MediaWiki\Widget\NamespaceInputWidget( [ |
66 | 'value' => $value, |
67 | 'name' => $this->mName, |
68 | 'id' => $this->mID, |
69 | 'includeAllValue' => $this->mAllValue, |
70 | 'userLang' => $this->mUserLang, |
71 | 'include' => $this->mInclude, |
72 | ] ); |
73 | } |
74 | |
75 | /** |
76 | * @inheritDoc |
77 | * @stable to override |
78 | */ |
79 | public function getInputCodex( $value, $hasErrors ) { |
80 | $optionParams = [ |
81 | 'all' => $this->mAllValue, |
82 | 'in-user-lang' => $this->mUserLang |
83 | ]; |
84 | $select = new HTMLSelectField( [ |
85 | 'options' => array_flip( Html::namespaceSelectorOptions( $optionParams ) ) |
86 | ] + $this->mParams ); |
87 | return $select->getInputCodex( $value, $hasErrors ); |
88 | } |
89 | |
90 | /** |
91 | * @inheritDoc |
92 | * @stable to override |
93 | */ |
94 | protected function getOOUIModules() { |
95 | // FIXME: NamespaceInputWidget should be in its own module (probably?) |
96 | return [ 'mediawiki.widgets' ]; |
97 | } |
98 | |
99 | /** |
100 | * @inheritDoc |
101 | * @stable to override |
102 | */ |
103 | protected function shouldInfuseOOUI() { |
104 | return true; |
105 | } |
106 | } |
107 | |
108 | /** @deprecated class alias since 1.42 */ |
109 | class_alias( HTMLSelectNamespace::class, 'HTMLSelectNamespace' ); |