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 );
40 mw.widgets.NamespaceInputWidget.prototype.getNamespaceDropdownOptions = function ( config ) {
42 exclude = config.exclude || [],
45 options = $.map( mw.config.get( 'wgFormattedNamespaces' ), function ( name, ns ) {
46 if ( ns < NS_MAIN || exclude.indexOf( Number( ns ) ) !== -1 ) {
50 if ( ns === String( NS_MAIN ) ) {
51 name = mw.message( 'blanknamespace' ).text();
53 return { data: ns, label: name };
54 } ).sort( function ( a, b ) {
55 // wgFormattedNamespaces is an object, and so technically doesn't have to be ordered
56 return a.data - b.data;
59 if ( config.includeAllValue !== null && config.includeAllValue !== undefined ) {
61 data: config.includeAllValue,
62 label: mw.message( 'namespacesall' ).text()
69 }( jQuery, mediaWiki ) );