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;
18 * @param array $config Configuration options
19 * - string $config['includeAllValue'] If specified, add a "all namespaces" option to the
20 * namespace dropdown, and use this as the input value for it
21 * - int[] $config['exclude'] List of namespace numbers to exclude from the selector
23 public function __construct( array $config = [] ) {
24 // Configuration initialization
25 $config['options'] = $this->getNamespaceDropdownOptions( $config );
27 parent
::__construct( $config );
30 $this->includeAllValue
= $config['includeAllValue'] ??
null;
31 $this->exclude
= $config['exclude'] ??
[];
34 $this->addClasses( [ 'mw-widget-namespaceInputWidget' ] );
37 protected function getNamespaceDropdownOptions( array $config ) {
38 $namespaceOptionsParams = [
39 'all' => $config['includeAllValue'] ??
null,
40 'exclude' => $config['exclude'] ??
null
42 $namespaceOptions = \Html
::namespaceSelectorOptions( $namespaceOptionsParams );
45 foreach ( $namespaceOptions as $id => $name ) {
47 'data' => (string)$id,
55 protected function getJavaScriptClassName() {
56 return 'mw.widgets.NamespaceInputWidget';
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 );