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;
23 protected $include;
24
34 public function __construct( array $config = [] ) {
35 // Configuration initialization
36 $config['options'] = $this->getNamespaceDropdownOptions( $config );
37
38 parent::__construct( $config );
39
40 // Properties
41 $this->includeAllValue = $config['includeAllValue'] ?? null;
42 $this->userLang = $config['userLang'] ?? false;
43 $this->exclude = $config['exclude'] ?? [];
44 $this->include = $config['include'] ?? null;
45
46 // Initialization
47 $this->addClasses( [ 'mw-widget-namespaceInputWidget' ] );
48 }
49
50 protected function getNamespaceDropdownOptions( array $config ) {
51 $namespaceOptionsParams = [
52 'all' => $config['includeAllValue'] ?? null,
53 'in-user-lang' => $config['userLang'] ?? false,
54 'exclude' => $config['exclude'] ?? null,
55 'include' => $config['include'] ?? null,
56 ];
57 $namespaceOptions = Html::namespaceSelectorOptions( $namespaceOptionsParams );
58
59 $options = [];
60 foreach ( $namespaceOptions as $id => $name ) {
61 $options[] = [
62 'data' => (string)$id,
63 'label' => $name,
64 ];
65 }
66
67 return $options;
68 }
69
70 protected function getJavaScriptClassName() {
71 return 'mw.widgets.NamespaceInputWidget';
72 }
73
74 public function getConfig( &$config ) {
75 $config['includeAllValue'] = $this->includeAllValue;
76 $config['userLang'] = $this->userLang;
77 $config['exclude'] = $this->exclude;
78 $config['include'] = $this->include;
79 $config['dropdown']['$overlay'] = true;
80 // Skip DropdownInputWidget's getConfig(), we don't need 'options' config
81 return InputWidget::getConfig( $config );
82 }
83}
This class is a collection of static functions that serve two purposes:
Definition Html.php:56