69427c502e1c77d34fd3c24f5db7f48e914cc73f
3 * MediaWiki Widgets – NamespaceInputWidget class.
5 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
6 * @license The MIT License (MIT); see LICENSE.txt
8 namespace MediaWiki\Widget
;
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 class NamespaceInputWidget
extends \OOUI\Widget
{
16 protected $namespace = null;
17 protected $associated = null;
18 protected $invert = null;
19 protected $allValue = null;
22 * @param array $config Configuration options
23 * @param string $config['nameNamespace'] HTML input name for the namespace dropdown box (default:
25 * @param string $config['nameInvert'] HTML input name for the "invert selection" checkbox. If
26 * null, the checkbox will not be generated. (default: 'invert')
27 * @param string $config['nameAssociated'] HTML input name for the "include associated namespace"
28 * checkbox. If null, the checkbox will not be generated. (default: 'associated')
29 * @param string $config['includeAllValue'] If specified, add a "all namespaces" option to the
30 * namespace dropdown, and use this as the input value for it
31 * @param int|string $config['valueNamespace'] Input value of the namespace dropdown box. May be a
32 * string only if 'includeAllValue' is set.
33 * @param boolean $config['valueInvert'] Input value of the "invert selection" checkbox (default:
35 * @param boolean $config['valueAssociated'] Input value of the "include associated namespace"
36 * checkbox (default: false)
37 * @param string $config['labelInvert'] Text of label to use for "invert selection" checkbox
38 * @param string $config['labelAssociated'] Text of label to use for "include associated
41 public function __construct( array $config = array() ) {
42 // Configuration initialization
44 $config = array_merge(
46 'nameNamespace' => 'namespace',
47 'nameInvert' => 'invert',
48 'nameAssociated' => 'associated',
49 // Choose first available: either main namespace or the "all namespaces" option
50 'valueNamespace' => null,
51 'valueInvert' => false,
52 'valueAssociated' => false,
58 parent
::__construct( $config );
61 $this->allValue
= isset( $config['includeAllValue'] ) ?
$config['includeAllValue'] : null;
62 $this->namespace = new \OOUI\
DropdownInputWidget( array(
63 'name' => $config['nameNamespace'],
64 'value' => $config['valueNamespace'],
65 'options' => $this->getNamespaceDropdownOptions( $config ),
67 if ( $config['nameAssociated'] !== null ) {
68 // FIXME Should use a LabelWidget? But they don't work like HTML <label>s yet
69 $this->associated
= new \OOUI\
FieldLayout(
70 new \OOUI\
CheckboxInputWidget( array(
71 'name' => $config['nameAssociated'],
72 'selected' => $config['valueAssociated'],
77 'label' => $config['labelAssociated'],
81 if ( $config['nameInvert'] !== null ) {
82 $this->invert
= new \OOUI\
FieldLayout(
83 new \OOUI\
CheckboxInputWidget( array(
84 'name' => $config['nameInvert'],
85 'selected' => $config['valueInvert'],
90 'label' => $config['labelInvert'],
97 ->addClasses( array( 'mw-widget-namespaceInputWidget' ) )
98 ->appendContent( $this->namespace, $this->associated
, $this->invert
);
101 protected function getNamespaceDropdownOptions( array $config ) {
102 $namespaceOptionsParams = isset( $config['includeAllValue'] ) ?
103 array( 'all' => $config['includeAllValue'] ) : array();
104 $namespaceOptions = \Html
::namespaceSelectorOptions( $namespaceOptionsParams );
107 foreach( $namespaceOptions as $id => $name ) {
109 'data' => (string)$id,
117 protected function getJavaScriptClassName() {
118 return 'mw.widgets.NamespaceInputWidget';
121 public function getConfig( &$config ) {
122 $config['namespace'] = $this->namespace;
123 $config['associated'] = $this->associated
;
124 $config['invert'] = $this->invert
;
125 $config['allValue'] = $this->allValue
;
126 return parent
::getConfig( $config );