Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 51
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 / 51
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 / 32
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(
70                $config['associated'] + [ 'value' => '1' ]
71            );
72            // TODO Should use a LabelWidget? But they don't work like HTML <label>s yet
73            $this->associatedLabel = new FieldLayout(
74                $this->associated,
75                $config['associatedLabel'] + [ 'align' => 'inline' ]
76            );
77        }
78        if ( $config['invert'] !== null ) {
79            $this->invert = new CheckboxInputWidget(
80                $config['invert'] + [ 'value' => '1' ]
81            );
82            // TODO Should use a LabelWidget? But they don't work like HTML <label>s yet
83            $this->invertLabel = new FieldLayout(
84                $this->invert,
85                $config['invertLabel'] + [ 'align' => 'inline' ]
86            );
87        }
88
89        // Initialization
90        $this
91            ->addClasses( [ 'mw-widget-complexNamespaceInputWidget' ] )
92            ->appendContent( $this->namespace, $this->associatedLabel, $this->invertLabel );
93    }
94
95    /** @inheritDoc */
96    protected function getJavaScriptClassName() {
97        return 'mw.widgets.ComplexNamespaceInputWidget';
98    }
99
100    /** @inheritDoc */
101    public function getConfig( &$config ) {
102        $config = array_merge(
103            $config,
104            array_intersect_key(
105                $this->config,
106                array_fill_keys(
107                    [
108                        'namespace',
109                        'invert',
110                        'invertLabel',
111                        'associated',
112                        'associatedLabel'
113                    ],
114                    true
115                )
116            )
117        );
118        $config['namespace']['dropdown']['$overlay'] = true;
119        return parent::getConfig( $config );
120    }
121}