MediaWiki master
ComplexNamespaceInputWidget.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Widget;
4
5use OOUI\CheckboxInputWidget;
6use OOUI\FieldLayout;
7use OOUI\Widget;
8
16class ComplexNamespaceInputWidget extends Widget {
17
19 protected $config;
21 protected $namespace;
23 protected $associated = null;
25 protected $associatedLabel = null;
27 protected $invert = null;
29 protected $invertLabel = null;
30
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 ],
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
96 protected function getJavaScriptClassName() {
97 return 'mw.widgets.ComplexNamespaceInputWidget';
98 }
99
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}