1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
<?php
namespace MediaWiki\Widget;
/**
* Namespace input widget. Displays a dropdown box with the choice of available namespaces, plus two
* checkboxes to include associated namespace or to invert selection.
*
* @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
* @license MIT
*/
class ComplexNamespaceInputWidget extends \OOUI\Widget {
protected $config;
protected $namespace;
protected $associated = null;
protected $associatedLabel = null;
protected $invert = null;
protected $invertLabel = null;
/**
* @param array $config Configuration options
* - array $config['namespace'] Configuration for the NamespaceInputWidget
* dropdown with list of namespaces
* - string $config['namespace']['includeAllValue'] If specified,
* add an "all namespaces" option to the dropdown, and use this as the input value for it
* - array|null $config['invert'] Configuration for the "invert selection"
* CheckboxInputWidget. If null, the checkbox will not be generated.
* - array|null $config['associated'] Configuration for the "include associated namespace"
* CheckboxInputWidget. If null, the checkbox will not be generated.
* - array $config['invertLabel'] Configuration for the FieldLayout with label
* wrapping the "invert selection" checkbox
* - string $config['invertLabel']['label'] Label text for the label
* - array $config['associatedLabel'] Configuration for the FieldLayout with label
* wrapping the "include associated namespace" checkbox
* - string $config['associatedLabel']['label'] Label text for the label
*/
public function __construct( array $config = [] ) {
// Configuration initialization
$config = array_merge(
[
// Config options for nested widgets
'namespace' => [],
'invert' => [],
'invertLabel' => [],
'associated' => [],
'associatedLabel' => [],
],
$config
);
parent::__construct( $config );
// Properties
$this->config = $config;
$this->namespace = new NamespaceInputWidget( $config['namespace'] );
if ( $config['associated'] !== null ) {
$this->associated = new \OOUI\CheckboxInputWidget( array_merge(
[ 'value' => '1' ],
$config['associated']
) );
// TODO Should use a LabelWidget? But they don't work like HTML <label>s yet
$this->associatedLabel = new \OOUI\FieldLayout(
$this->associated,
array_merge(
[ 'align' => 'inline' ],
$config['associatedLabel']
)
);
}
if ( $config['invert'] !== null ) {
$this->invert = new \OOUI\CheckboxInputWidget( array_merge(
[ 'value' => '1' ],
$config['invert']
) );
// TODO Should use a LabelWidget? But they don't work like HTML <label>s yet
$this->invertLabel = new \OOUI\FieldLayout(
$this->invert,
array_merge(
[ 'align' => 'inline' ],
$config['invertLabel']
)
);
}
// Initialization
$this
->addClasses( [ 'mw-widget-complexNamespaceInputWidget' ] )
->appendContent( $this->namespace, $this->associatedLabel, $this->invertLabel );
}
protected function getJavaScriptClassName() {
return 'mw.widgets.ComplexNamespaceInputWidget';
}
public function getConfig( &$config ) {
$config = array_merge(
$config,
array_intersect_key(
$this->config,
array_fill_keys(
[
'namespace',
'invert',
'invertLabel',
'associated',
'associatedLabel'
],
true
)
)
);
$config['namespace']['dropdown']['$overlay'] = true;
return parent::getConfig( $config );
}
}
|