MediaWiki REL1_39
NamespaceInputWidget.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Widget;
4
11class NamespaceInputWidget extends \OOUI\DropdownInputWidget {
15 protected $userLang;
17 protected $exclude;
18
26 public function __construct( array $config = [] ) {
27 // Configuration initialization
28 $config['options'] = $this->getNamespaceDropdownOptions( $config );
29
30 parent::__construct( $config );
31
32 // Properties
33 $this->includeAllValue = $config['includeAllValue'] ?? null;
34 $this->userLang = $config['userLang'] ?? false;
35 $this->exclude = $config['exclude'] ?? [];
36
37 // Initialization
38 $this->addClasses( [ 'mw-widget-namespaceInputWidget' ] );
39 }
40
41 protected function getNamespaceDropdownOptions( array $config ) {
42 $namespaceOptionsParams = [
43 'all' => $config['includeAllValue'] ?? null,
44 'in-user-lang' => $config['userLang'] ?? false,
45 'exclude' => $config['exclude'] ?? null
46 ];
47 $namespaceOptions = \Html::namespaceSelectorOptions( $namespaceOptionsParams );
48
49 $options = [];
50 foreach ( $namespaceOptions as $id => $name ) {
51 $options[] = [
52 'data' => (string)$id,
53 'label' => $name,
54 ];
55 }
56
57 return $options;
58 }
59
60 protected function getJavaScriptClassName() {
61 return 'mw.widgets.NamespaceInputWidget';
62 }
63
64 public function getConfig( &$config ) {
65 $config['includeAllValue'] = $this->includeAllValue;
66 $config['userLang'] = $this->userLang;
67 $config['exclude'] = $this->exclude;
68 // Skip DropdownInputWidget's getConfig(), we don't need 'options' config
69 $config['dropdown']['$overlay'] = true;
70 return \OOUI\InputWidget::getConfig( $config );
71 }
72}