| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
( function () { |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
mw.widgets.NamespaceInputWidget = function MwWidgetsNamespaceInputWidget( config ) { |
| 23 |
|
| 24 |
config = Object.assign( {}, config, { options: this.constructor.static.getNamespaceDropdownOptions( config ) } ); |
| 25 |
|
| 26 |
|
| 27 |
mw.widgets.NamespaceInputWidget.super.call( this, config ); |
| 28 |
|
| 29 |
|
| 30 |
this.$element.addClass( 'mw-widget-namespaceInputWidget' ); |
| 31 |
}; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
OO.inheritClass( mw.widgets.NamespaceInputWidget, OO.ui.DropdownInputWidget ); |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
mw.widgets.NamespaceInputWidget.static.getNamespaceDropdownOptions = function ( config ) { |
| 54 |
const exclude = config.exclude || [], |
| 55 |
mainNamespace = mw.config.get( 'wgNamespaceIds' )[ '' ]; |
| 56 |
|
| 57 |
const namespaces = config.userLang ? |
| 58 |
require( './data.json' ).formattedNamespaces : |
| 59 |
mw.config.get( 'wgFormattedNamespaces' ); |
| 60 |
|
| 61 |
|
| 62 |
const options = $.map( namespaces, ( name, ns ) => { |
| 63 |
if ( ns < mainNamespace || exclude.indexOf( Number( ns ) ) !== -1 ) { |
| 64 |
return null; |
| 65 |
} |
| 66 |
ns = String( ns ); |
| 67 |
if ( ns === String( mainNamespace ) ) { |
| 68 |
name = mw.msg( 'blanknamespace' ); |
| 69 |
} |
| 70 |
return { data: ns, label: name }; |
| 71 |
} ).sort( |
| 72 |
|
| 73 |
( a, b ) => a.data - b.data |
| 74 |
); |
| 75 |
|
| 76 |
if ( config.includeAllValue !== null && config.includeAllValue !== undefined ) { |
| 77 |
options.unshift( { |
| 78 |
data: config.includeAllValue, |
| 79 |
label: mw.msg( 'namespacesall' ) |
| 80 |
} ); |
| 81 |
} |
| 82 |
|
| 83 |
return options; |
| 84 |
}; |
| 85 |
|
| 86 |
}() ); |