Merge "Remove references to Popularpages alias"
[lhc/web/wiklou.git] / includes / widget / NamespaceInputWidget.php
1 <?php
2 /**
3 * MediaWiki Widgets – NamespaceInputWidget 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.
12 */
13 class NamespaceInputWidget extends \OOUI\DropdownInputWidget {
14
15 protected $includeAllValue = null;
16
17 /**
18 * @param array $config Configuration options
19 * @param string $config['includeAllValue'] If specified, add a "all namespaces" option to the
20 * namespace dropdown, and use this as the input value for it
21 */
22 public function __construct( array $config = array() ) {
23 // Configuration initialization
24 $config['options'] = $this->getNamespaceDropdownOptions( $config );
25
26 // Parent constructor
27 parent::__construct( $config );
28
29 // Properties
30 $this->includeAllValue = isset( $config['includeAllValue'] ) ? $config['includeAllValue'] : null;
31
32 // Initialization
33 $this->addClasses( array( 'mw-widget-namespaceInputWidget' ) );
34 }
35
36 protected function getNamespaceDropdownOptions( array $config ) {
37 $namespaceOptionsParams = isset( $config['includeAllValue'] ) ?
38 array( 'all' => $config['includeAllValue'] ) : array();
39 $namespaceOptions = \Html::namespaceSelectorOptions( $namespaceOptionsParams );
40
41 $options = array();
42 foreach ( $namespaceOptions as $id => $name ) {
43 $options[] = array(
44 'data' => (string)$id,
45 'label' => $name,
46 );
47 }
48
49 return $options;
50 }
51
52 protected function getJavaScriptClassName() {
53 return 'mw.widgets.NamespaceInputWidget';
54 }
55
56 public function getConfig( &$config ) {
57 $config['includeAllValue'] = $this->includeAllValue;
58 // Skip DropdownInputWidget's getConfig(), we don't need 'options' config
59 return \OOUI\InputWidget::getConfig( $config );
60 }
61 }