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
43 $config = array_merge(
45 'nameNamespace' => 'namespace',
46 'nameInvert' => 'invert',
47 'nameAssociated' => 'associated',
48 // Choose first available: either main namespace or the "all namespaces" option
49 'valueNamespace' => null,
50 'valueInvert' => false,
51 'valueAssociated' => false,
57 parent
::__construct( $config );
60 $this->allValue
= isset( $config['includeAllValue'] ) ?
$config['includeAllValue'] : null;
61 $this->namespace = new \OOUI\
DropdownInputWidget( array(
62 'name' => $config['nameNamespace'],
63 'value' => $config['valueNamespace'],
64 'options' => $this->getNamespaceDropdownOptions( $config ),
66 if ( $config['nameAssociated'] !== null ) {
67 // FIXME Should use a LabelWidget? But they don't work like HTML <label>s yet
68 $this->associated
= new \OOUI\
FieldLayout(
69 new \OOUI\
CheckboxInputWidget( array(
70 'name' => $config['nameAssociated'],
71 'selected' => $config['valueAssociated'],
76 'label' => $config['labelAssociated'],
80 if ( $config['nameInvert'] !== null ) {
81 $this->invert
= new \OOUI\
FieldLayout(
82 new \OOUI\
CheckboxInputWidget( array(
83 'name' => $config['nameInvert'],
84 'selected' => $config['valueInvert'],
89 'label' => $config['labelInvert'],
96 ->addClasses( array( 'mw-widget-namespaceInputWidget' ) )
97 ->appendContent( $this->namespace, $this->associated
, $this->invert
);
100 protected function getNamespaceDropdownOptions( array $config ) {
101 $namespaceOptionsParams = isset( $config['includeAllValue'] ) ?
102 array( 'all' => $config['includeAllValue'] ) : array();
103 $namespaceOptions = \Html
::namespaceSelectorOptions( $namespaceOptionsParams );
106 foreach ( $namespaceOptions as $id => $name ) {
108 'data' => (string)$id,
116 protected function getJavaScriptClassName() {
117 return 'mw.widgets.NamespaceInputWidget';
120 public function getConfig( &$config ) {
121 $config['namespace'] = $this->namespace;
122 $config['associated'] = $this->associated
;
123 $config['invert'] = $this->invert
;
124 $config['allValue'] = $this->allValue
;
125 return parent
::getConfig( $config );