MediaWiki  master
NamespaceInputWidget.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Widget;
4 
11 class NamespaceInputWidget extends \OOUI\DropdownInputWidget {
13  protected $includeAllValue;
15  protected $exclude;
16 
23  public function __construct( array $config = [] ) {
24  // Configuration initialization
25  $config['options'] = $this->getNamespaceDropdownOptions( $config );
26 
27  parent::__construct( $config );
28 
29  // Properties
30  $this->includeAllValue = $config['includeAllValue'] ?? null;
31  $this->exclude = $config['exclude'] ?? [];
32 
33  // Initialization
34  $this->addClasses( [ 'mw-widget-namespaceInputWidget' ] );
35  }
36 
37  protected function getNamespaceDropdownOptions( array $config ) {
38  $namespaceOptionsParams = [
39  'all' => $config['includeAllValue'] ?? null,
40  'exclude' => $config['exclude'] ?? null
41  ];
42  $namespaceOptions = \Html::namespaceSelectorOptions( $namespaceOptionsParams );
43 
44  $options = [];
45  foreach ( $namespaceOptions as $id => $name ) {
46  $options[] = [
47  'data' => (string)$id,
48  'label' => $name,
49  ];
50  }
51 
52  return $options;
53  }
54 
55  protected function getJavaScriptClassName() {
56  return 'mw.widgets.NamespaceInputWidget';
57  }
58 
59  public function getConfig( &$config ) {
60  $config['includeAllValue'] = $this->includeAllValue;
61  $config['exclude'] = $this->exclude;
62  // Skip DropdownInputWidget's getConfig(), we don't need 'options' config
63  $config['dropdown']['$overlay'] = true;
64  return \OOUI\InputWidget::getConfig( $config );
65  }
66 }
MediaWiki\Widget\NamespaceInputWidget\$exclude
int[] $exclude
Definition: NamespaceInputWidget.php:15
MediaWiki\Widget\NamespaceInputWidget\getJavaScriptClassName
getJavaScriptClassName()
Definition: NamespaceInputWidget.php:55
MediaWiki\Widget\NamespaceInputWidget\$includeAllValue
string $includeAllValue
Definition: NamespaceInputWidget.php:13
MediaWiki\Widget\NamespaceInputWidget
Namespace input widget.
Definition: NamespaceInputWidget.php:11
MediaWiki\Widget\NamespaceInputWidget\getNamespaceDropdownOptions
getNamespaceDropdownOptions(array $config)
Definition: NamespaceInputWidget.php:37
MediaWiki\Widget\NamespaceInputWidget\__construct
__construct(array $config=[])
Definition: NamespaceInputWidget.php:23
MediaWiki\Widget\NamespaceInputWidget\getConfig
getConfig(&$config)
Definition: NamespaceInputWidget.php:59
MediaWiki\Widget
Definition: CheckMatrixWidget.php:3
MediaWiki\$config
Config $config
Definition: MediaWiki.php:39