Debian Codegraph @

includes/widget/NamespaceInputWidget.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Widget;
4
5 use MediaWiki\Html\Html;
6 use OOUI\DropdownInputWidget;
7 use OOUI\InputWidget;
8
9 /**
10 * Namespace input widget. Displays a dropdown box with the choice of available namespaces.
11 *
12 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
13 * @license MIT
14 */
15 class NamespaceInputWidget extends DropdownInputWidget {
16 /** @var string */
17 protected $includeAllValue;
18 /** @var bool */
19 protected $userLang;
20 /** @var int[] */
21 protected $exclude;
22
23 /**
24 * @param array $config Configuration options
25 * - string $config['includeAllValue'] If specified, add a "all namespaces" option to the
26 * namespace dropdown, and use this as the input value for it
27 * - bool $config['userLang'] Display namespaces in user language
28 * - int[] $config['exclude'] List of namespace numbers to exclude from the selector
29 */
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 }