2 * MediaWiki Widgets - NamespaceInputWidget class.
4 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
10 * Namespace input widget. Displays a dropdown box with the choice of available namespaces.
13 * @extends OO.ui.DropdownInputWidget
16 * @param {Object} [config] Configuration options
17 * @cfg {string|null} [includeAllValue] Value for "all namespaces" option, if any
18 * @cfg {number[]} [exclude] List of namespace numbers to exclude from the selector
20 mw
.widgets
.NamespaceInputWidget
= function MwWidgetsNamespaceInputWidget( config
) {
21 // Configuration initialization
22 config
= $.extend( {}, config
, { options
: this.getNamespaceDropdownOptions( config
) } );
25 mw
.widgets
.NamespaceInputWidget
.parent
.call( this, config
);
28 this.$element
.addClass( 'mw-widget-namespaceInputWidget' );
33 OO
.inheritClass( mw
.widgets
.NamespaceInputWidget
, OO
.ui
.DropdownInputWidget
);
39 * @param {Object} [config] Configuration options
40 * @return {Object[]} Dropdown options
42 mw
.widgets
.NamespaceInputWidget
.prototype.getNamespaceDropdownOptions = function ( config
) {
44 exclude
= config
.exclude
|| [],
45 mainNamespace
= mw
.config
.get( 'wgNamespaceIds' )[ '' ];
47 options
= $.map( mw
.config
.get( 'wgFormattedNamespaces' ), function ( name
, ns
) {
48 if ( ns
< mainNamespace
|| exclude
.indexOf( Number( ns
) ) !== -1 ) {
52 if ( ns
=== String( mainNamespace
) ) {
53 name
= mw
.message( 'blanknamespace' ).text();
55 return { data
: ns
, label
: name
};
56 } ).sort( function ( a
, b
) {
57 // wgFormattedNamespaces is an object, and so technically doesn't have to be ordered
58 return a
.data
- b
.data
;
61 if ( config
.includeAllValue
!== null && config
.includeAllValue
!== undefined ) {
63 data
: config
.includeAllValue
,
64 label
: mw
.message( 'namespacesall' ).text()
71 }( jQuery
, mediaWiki
) );