Merge "Warn if stateful ParserOutput transforms are used"
[lhc/web/wiklou.git] / includes / widget / NamespaceInputWidget.php
1 <?php
2
3 namespace MediaWiki\Widget;
4
5 /**
6 * Namespace input widget. Displays a dropdown box with the choice of available namespaces.
7 *
8 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
9 * @license MIT
10 */
11 class NamespaceInputWidget extends \OOUI\DropdownInputWidget {
12
13 protected $includeAllValue = null;
14
15 /**
16 * @param array $config Configuration options
17 * - string $config['includeAllValue'] If specified, add a "all namespaces" option to the
18 * namespace dropdown, and use this as the input value for it
19 * - int[] $config['exclude'] List of namespace numbers to exclude from the selector
20 */
21 public function __construct( array $config = [] ) {
22 // Configuration initialization
23 $config['options'] = $this->getNamespaceDropdownOptions( $config );
24
25 parent::__construct( $config );
26
27 // Properties
28 $this->includeAllValue = isset( $config['includeAllValue'] ) ? $config['includeAllValue'] : null;
29 $this->exclude = isset( $config['exclude'] ) ? $config['exclude'] : [];
30
31 // Initialization
32 $this->addClasses( [ 'mw-widget-namespaceInputWidget' ] );
33 }
34
35 protected function getNamespaceDropdownOptions( array $config ) {
36 $namespaceOptionsParams = [
37 'all' => isset( $config['includeAllValue'] ) ? $config['includeAllValue'] : null,
38 'exclude' => isset( $config['exclude'] ) ? $config['exclude'] : null
39 ];
40 $namespaceOptions = \Html::namespaceSelectorOptions( $namespaceOptionsParams );
41
42 $options = [];
43 foreach ( $namespaceOptions as $id => $name ) {
44 $options[] = [
45 'data' => (string)$id,
46 'label' => $name,
47 ];
48 }
49
50 return $options;
51 }
52
53 protected function getJavaScriptClassName() {
54 return 'mw.widgets.NamespaceInputWidget';
55 }
56
57 public function getConfig( &$config ) {
58 $config['includeAllValue'] = $this->includeAllValue;
59 $config['exclude'] = $this->exclude;
60 // Skip DropdownInputWidget's getConfig(), we don't need 'options' config
61 $config['dropdown']['$overlay'] = true;
62 return \OOUI\InputWidget::getConfig( $config );
63 }
64 }