3 namespace MediaWiki\Widget
;
5 use MediaWiki\Html\Html
;
6 use OOUI\DropdownInputWidget
;
10 * Namespace input widget. Displays a dropdown box with the choice of available namespaces.
12 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
15 class NamespaceInputWidget
extends DropdownInputWidget
{
17 protected $includeAllValue;
22 /** @var int[]|null */
26 * @param array $config Configuration options
27 * - string $config['includeAllValue'] If specified, add a "all namespaces" option to the
28 * namespace dropdown, and use this as the input value for it
29 * - bool $config['userLang'] Display namespaces in user language
30 * - int[] $config['exclude'] List of namespace numbers to exclude from the selector
31 * - int[]|null $config['include'] List of namespace numbers to only include in the selector, or null
32 * to not apply this filter.
34 public function __construct( array $config = [] ) {
35 // Configuration initialization
36 $config['options'] = $this->getNamespaceDropdownOptions( $config );
38 parent
::__construct( $config );
41 $this->includeAllValue
= $config['includeAllValue'] ??
null;
42 $this->userLang
= $config['userLang'] ??
false;
43 $this->exclude
= $config['exclude'] ??
[];
44 $this->include = $config['include'] ??
null;
47 $this->addClasses( [ 'mw-widget-namespaceInputWidget' ] );
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,
57 $namespaceOptions = Html
::namespaceSelectorOptions( $namespaceOptionsParams );
60 foreach ( $namespaceOptions as $id => $name ) {
62 'data' => (string)$id,
70 protected function getJavaScriptClassName() {
71 return 'mw.widgets.NamespaceInputWidget';
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 );