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