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