Merge "Don't check namespace in SpecialWantedtemplates"
[lhc/web/wiklou.git] / includes / widget / ComplexNamespaceInputWidget.php
1 <?php
2 /**
3 * MediaWiki Widgets – ComplexNamespaceInputWidget class.
4 *
5 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
6 * @license The MIT License (MIT); see LICENSE.txt
7 */
8 namespace MediaWiki\Widget;
9
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.
13 */
14 class ComplexNamespaceInputWidget extends \OOUI\Widget {
15
16 protected $config;
17 protected $namespace;
18 protected $associated = null;
19 protected $associatedLabel = null;
20 protected $invert = null;
21 protected $invertLabel = null;
22
23 /**
24 * @param array $config Configuration options
25 * @param array $config['namespace'] Configuration for the NamespaceInputWidget dropdown with list
26 * of namespaces
27 * @param string $config['namespace']['includeAllValue'] If specified, add a "all namespaces"
28 * option to the dropdown, and use this as the input value for it
29 * @param array|null $config['invert'] Configuration for the "invert selection" CheckboxInputWidget. If
30 * null, the checkbox will not be generated.
31 * @param array|null $config['associated'] Configuration for the "include associated namespace"
32 * CheckboxInputWidget. If null, the checkbox will not be generated.
33 * @param array $config['invertLabel'] Configuration for the FieldLayout with label wrapping the
34 * "invert selection" checkbox
35 * @param string $config['invertLabel']['label'] Label text for the label
36 * @param array $config['associatedLabel'] Configuration for the FieldLayout with label wrapping
37 * the "include associated namespace" checkbox
38 * @param string $config['associatedLabel']['label'] Label text for the label
39 */
40 public function __construct( array $config = array() ) {
41 // Configuration initialization
42 $config = array_merge(
43 array(
44 // Config options for nested widgets
45 'namespace' => array(),
46 'invert' => array(),
47 'invertLabel' => array(),
48 'associated' => array(),
49 'associatedLabel' => array(),
50 ),
51 $config
52 );
53
54 // Parent constructor
55 parent::__construct( $config );
56
57 // Properties
58 $this->config = $config;
59
60 $this->namespace = new NamespaceInputWidget( $config['namespace'] );
61 if ( $config['associated'] !== null ) {
62 $this->associated = new \OOUI\CheckboxInputWidget( array_merge(
63 array( 'value' => '1' ),
64 $config['associated']
65 ) );
66 // TODO Should use a LabelWidget? But they don't work like HTML <label>s yet
67 $this->associatedLabel = new \OOUI\FieldLayout(
68 $this->associated,
69 array_merge(
70 array( 'align' => 'inline' ),
71 $config['associatedLabel']
72 )
73 );
74 }
75 if ( $config['invert'] !== null ) {
76 $this->invert = new \OOUI\CheckboxInputWidget( array_merge(
77 array( 'value' => '1' ),
78 $config['invert']
79 ) );
80 // TODO Should use a LabelWidget? But they don't work like HTML <label>s yet
81 $this->invertLabel = new \OOUI\FieldLayout(
82 $this->invert,
83 array_merge(
84 array( 'align' => 'inline' ),
85 $config['invertLabel']
86 )
87 );
88 }
89
90 // Initialization
91 $this
92 ->addClasses( array( 'mw-widget-complexNamespaceInputWidget' ) )
93 ->appendContent( $this->namespace, $this->associatedLabel, $this->invertLabel );
94 }
95
96 protected function getJavaScriptClassName() {
97 return 'mw.widgets.ComplexNamespaceInputWidget';
98 }
99
100 public function getConfig( &$config ) {
101 $config = array_merge(
102 $config,
103 array_intersect_key(
104 $this->config,
105 array_fill_keys( array( 'namespace', 'invert', 'invertLabel', 'associated', 'associatedLabel' ), true )
106 )
107 );
108 return parent::getConfig( $config );
109 }
110 }