Merge "Drop zh-tw message "saveprefs""
[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 * @param number[] $config['exclude'] List of namespace numbers to exclude from the selector
22 */
23 public function __construct( array $config = array() ) {
24 // Configuration initialization
25 $config['options'] = $this->getNamespaceDropdownOptions( $config );
26
27 // Parent constructor
28 parent::__construct( $config );
29
30 // Properties
31 $this->includeAllValue = isset( $config['includeAllValue'] ) ? $config['includeAllValue'] : null;
32 $this->exclude = isset( $config['exclude'] ) ? $config['exclude'] : array();
33
34 // Initialization
35 $this->addClasses( array( 'mw-widget-namespaceInputWidget' ) );
36 }
37
38 protected function getNamespaceDropdownOptions( array $config ) {
39 $namespaceOptionsParams = array(
40 'all' => isset( $config['includeAllValue'] ) ? $config['includeAllValue'] : null,
41 'exclude' => isset( $config['exclude'] ) ? $config['exclude'] : null
42 );
43 $namespaceOptions = \Html::namespaceSelectorOptions( $namespaceOptionsParams );
44
45 $options = array();
46 foreach ( $namespaceOptions as $id => $name ) {
47 $options[] = array(
48 'data' => (string)$id,
49 'label' => $name,
50 );
51 }
52
53 return $options;
54 }
55
56 protected function getJavaScriptClassName() {
57 return 'mw.widgets.NamespaceInputWidget';
58 }
59
60 public function getConfig( &$config ) {
61 $config['includeAllValue'] = $this->includeAllValue;
62 $config['exclude'] = $this->exclude;
63 // Skip DropdownInputWidget's getConfig(), we don't need 'options' config
64 return \OOUI\InputWidget::getConfig( $config );
65 }
66 }