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