Merge "HTMLMultiSelectField: Add 'dropdown' option for 'mw-chosen' behavior and document"
[lhc/web/wiklou.git] / resources / src / mediawiki.widgets / mw.widgets.NamespaceInputWidget.js
index ef42dc1..c88395e 100644 (file)
@@ -14,7 +14,8 @@
         *
         * @constructor
         * @param {Object} [config] Configuration options
-        * @cfg {string|null} includeAllValue Value for "all namespaces" option, if any
+        * @cfg {string|null} [includeAllValue] Value for "all namespaces" option, if any
+        * @cfg {number[]} [exclude] List of namespace numbers to exclude from the selector
         */
        mw.widgets.NamespaceInputWidget = function MwWidgetsNamespaceInputWidget( config ) {
                // Configuration initialization
         */
        mw.widgets.NamespaceInputWidget.prototype.getNamespaceDropdownOptions = function ( config ) {
                var options,
-                       NS_MAIN = 0;
+                       exclude = config.exclude || [],
+                       mainNamespace = mw.config.get( 'wgNamespaceIds' )[ '' ];
 
                options = $.map( mw.config.get( 'wgFormattedNamespaces' ), function ( name, ns ) {
-                       if ( ns < NS_MAIN ) {
+                       if ( ns < mainNamespace || exclude.indexOf( Number( ns ) ) !== -1 ) {
                                return null; // skip
                        }
                        ns = String( ns );
-                       if ( ns === String( NS_MAIN ) ) {
+                       if ( ns === String( mainNamespace ) ) {
                                name = mw.message( 'blanknamespace' ).text();
                        }
                        return { data: ns, label: name };