Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / widget / ComplexNamespaceInputWidget.php
blobbe43ec1fd813a8ada924b8ae31135f2b06f83272
1 <?php
3 namespace MediaWiki\Widget;
5 use OOUI\CheckboxInputWidget;
6 use OOUI\Exception;
7 use OOUI\FieldLayout;
8 use OOUI\Widget;
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.
14 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
15 * @license MIT
17 class ComplexNamespaceInputWidget extends Widget {
19 /** @var array */
20 protected $config;
21 /** @var NamespaceInputWidget */
22 protected $namespace;
23 /** @var CheckboxInputWidget|null */
24 protected $associated = null;
25 /** @var FieldLayout|null */
26 protected $associatedLabel = null;
27 /** @var CheckboxInputWidget|null */
28 protected $invert = null;
29 /** @var FieldLayout|null */
30 protected $invertLabel = null;
32 /**
33 * @param array $config Configuration options
34 * - array $config['namespace'] Configuration for the NamespaceInputWidget
35 * dropdown with list of namespaces
36 * - string $config['namespace']['includeAllValue'] If specified,
37 * add an "all namespaces" option to the dropdown, and use this as the input value for it
38 * - array|null $config['invert'] Configuration for the "invert selection"
39 * CheckboxInputWidget. If null, the checkbox will not be generated.
40 * - array|null $config['associated'] Configuration for the "include associated namespace"
41 * CheckboxInputWidget. If null, the checkbox will not be generated.
42 * - array $config['invertLabel'] Configuration for the FieldLayout with label
43 * wrapping the "invert selection" checkbox
44 * - string $config['invertLabel']['label'] Label text for the label
45 * - array $config['associatedLabel'] Configuration for the FieldLayout with label
46 * wrapping the "include associated namespace" checkbox
47 * - string $config['associatedLabel']['label'] Label text for the label
49 * @throws Exception
51 public function __construct( array $config = [] ) {
52 // Configuration initialization
53 $config = array_merge(
55 // Config options for nested widgets
56 'namespace' => [],
57 'invert' => [],
58 'invertLabel' => [],
59 'associated' => [],
60 'associatedLabel' => [],
62 $config
65 parent::__construct( $config );
67 // Properties
68 $this->config = $config;
70 $this->namespace = new NamespaceInputWidget( $config['namespace'] );
71 if ( $config['associated'] !== null ) {
72 $this->associated = new CheckboxInputWidget( array_merge(
73 [ 'value' => '1' ],
74 $config['associated']
75 ) );
76 // TODO Should use a LabelWidget? But they don't work like HTML <label>s yet
77 $this->associatedLabel = new FieldLayout(
78 $this->associated,
79 array_merge(
80 [ 'align' => 'inline' ],
81 $config['associatedLabel']
85 if ( $config['invert'] !== null ) {
86 $this->invert = new CheckboxInputWidget( array_merge(
87 [ 'value' => '1' ],
88 $config['invert']
89 ) );
90 // TODO Should use a LabelWidget? But they don't work like HTML <label>s yet
91 $this->invertLabel = new FieldLayout(
92 $this->invert,
93 array_merge(
94 [ 'align' => 'inline' ],
95 $config['invertLabel']
100 // Initialization
101 $this
102 ->addClasses( [ 'mw-widget-complexNamespaceInputWidget' ] )
103 ->appendContent( $this->namespace, $this->associatedLabel, $this->invertLabel );
106 protected function getJavaScriptClassName() {
107 return 'mw.widgets.ComplexNamespaceInputWidget';
110 public function getConfig( &$config ) {
111 $config = array_merge(
112 $config,
113 array_intersect_key(
114 $this->config,
115 array_fill_keys(
117 'namespace',
118 'invert',
119 'invertLabel',
120 'associated',
121 'associatedLabel'
123 true
127 $config['namespace']['dropdown']['$overlay'] = true;
128 return parent::getConfig( $config );