3 namespace MediaWiki\Widget
;
5 use OOUI\CheckboxInputWidget
;
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
17 class ComplexNamespaceInputWidget
extends Widget
{
21 /** @var NamespaceInputWidget */
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;
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
51 public function __construct( array $config = [] ) {
52 // Configuration initialization
53 $config = array_merge(
55 // Config options for nested widgets
60 'associatedLabel' => [],
65 parent
::__construct( $config );
68 $this->config
= $config;
70 $this->namespace = new NamespaceInputWidget( $config['namespace'] );
71 if ( $config['associated'] !== null ) {
72 $this->associated
= new CheckboxInputWidget( array_merge(
76 // TODO Should use a LabelWidget? But they don't work like HTML <label>s yet
77 $this->associatedLabel
= new FieldLayout(
80 [ 'align' => 'inline' ],
81 $config['associatedLabel']
85 if ( $config['invert'] !== null ) {
86 $this->invert
= new CheckboxInputWidget( array_merge(
90 // TODO Should use a LabelWidget? But they don't work like HTML <label>s yet
91 $this->invertLabel
= new FieldLayout(
94 [ 'align' => 'inline' ],
95 $config['invertLabel']
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(
127 $config['namespace']['dropdown']['$overlay'] = true;
128 return parent
::getConfig( $config );