3 namespace MediaWiki\Widget
;
6 * Namespace input widget. Displays a dropdown box with the choice of available namespaces.
8 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
11 class NamespaceInputWidget
extends \OOUI\DropdownInputWidget
{
13 protected $includeAllValue = null;
16 * @param array $config Configuration options
17 * - string $config['includeAllValue'] If specified, add a "all namespaces" option to the
18 * namespace dropdown, and use this as the input value for it
19 * - int[] $config['exclude'] List of namespace numbers to exclude from the selector
21 public function __construct( array $config = [] ) {
22 // Configuration initialization
23 $config['options'] = $this->getNamespaceDropdownOptions( $config );
25 parent
::__construct( $config );
28 $this->includeAllValue
= $config['includeAllValue'] ??
null;
29 $this->exclude
= $config['exclude'] ??
[];
32 $this->addClasses( [ 'mw-widget-namespaceInputWidget' ] );
35 protected function getNamespaceDropdownOptions( array $config ) {
36 $namespaceOptionsParams = [
37 'all' => $config['includeAllValue'] ??
null,
38 'exclude' => $config['exclude'] ??
null
40 $namespaceOptions = \Html
::namespaceSelectorOptions( $namespaceOptionsParams );
43 foreach ( $namespaceOptions as $id => $name ) {
45 'data' => (string)$id,
53 protected function getJavaScriptClassName() {
54 return 'mw.widgets.NamespaceInputWidget';
57 public function getConfig( &$config ) {
58 $config['includeAllValue'] = $this->includeAllValue
;
59 $config['exclude'] = $this->exclude
;
60 // Skip DropdownInputWidget's getConfig(), we don't need 'options' config
61 $config['dropdown']['$overlay'] = true;
62 return \OOUI\InputWidget
::getConfig( $config );