Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / widget / NamespaceInputWidget.php
blob71ed0c303a0e33aaf81d0fe6cdf6763e0e926729
1 <?php
3 namespace MediaWiki\Widget;
5 use MediaWiki\Html\Html;
6 use OOUI\DropdownInputWidget;
7 use OOUI\InputWidget;
9 /**
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
13 * @license MIT
15 class NamespaceInputWidget extends DropdownInputWidget {
16 /** @var string */
17 protected $includeAllValue;
18 /** @var bool */
19 protected $userLang;
20 /** @var int[] */
21 protected $exclude;
22 /** @var int[]|null */
23 protected $include;
25 /**
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 );
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;
46 // Initialization
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 );
59 $options = [];
60 foreach ( $namespaceOptions as $id => $name ) {
61 $options[] = [
62 'data' => (string)$id,
63 'label' => $name,
67 return $options;
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 );