summaryrefslogtreecommitdiff
path: root/resources/src/mediawiki.widgets/mw.widgets.NamespaceInputWidget.js
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2015-12-17 09:15:42 +0100
committerPierre Schmitz <pierre@archlinux.de>2015-12-17 09:44:51 +0100
commita1789ddde42033f1b05cc4929491214ee6e79383 (patch)
tree63615735c4ddffaaabf2428946bb26f90899f7bf /resources/src/mediawiki.widgets/mw.widgets.NamespaceInputWidget.js
parent9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff)
Update to MediaWiki 1.26.0
Diffstat (limited to 'resources/src/mediawiki.widgets/mw.widgets.NamespaceInputWidget.js')
-rw-r--r--resources/src/mediawiki.widgets/mw.widgets.NamespaceInputWidget.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/resources/src/mediawiki.widgets/mw.widgets.NamespaceInputWidget.js b/resources/src/mediawiki.widgets/mw.widgets.NamespaceInputWidget.js
new file mode 100644
index 00000000..4f1b8749
--- /dev/null
+++ b/resources/src/mediawiki.widgets/mw.widgets.NamespaceInputWidget.js
@@ -0,0 +1,69 @@
+/*!
+ * MediaWiki Widgets - NamespaceInputWidget class.
+ *
+ * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
+ * @license The MIT License (MIT); see LICENSE.txt
+ */
+( function ( $, mw ) {
+
+ /**
+ * Namespace input widget. Displays a dropdown box with the choice of available namespaces.
+ *
+ * @class
+ * @extends OO.ui.DropdownInputWidget
+ *
+ * @constructor
+ * @param {Object} [config] Configuration options
+ * @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
+ config = $.extend( {}, config, { options: this.getNamespaceDropdownOptions( config ) } );
+
+ // Parent constructor
+ mw.widgets.NamespaceInputWidget.parent.call( this, config );
+
+ // Initialization
+ this.$element.addClass( 'mw-widget-namespaceInputWidget' );
+ };
+
+ /* Setup */
+
+ OO.inheritClass( mw.widgets.NamespaceInputWidget, OO.ui.DropdownInputWidget );
+
+ /* Methods */
+
+ /**
+ * @private
+ */
+ mw.widgets.NamespaceInputWidget.prototype.getNamespaceDropdownOptions = function ( config ) {
+ var options,
+ exclude = config.exclude || [],
+ NS_MAIN = 0;
+
+ options = $.map( mw.config.get( 'wgFormattedNamespaces' ), function ( name, ns ) {
+ if ( ns < NS_MAIN || exclude.indexOf( Number( ns ) ) !== -1 ) {
+ return null; // skip
+ }
+ ns = String( ns );
+ if ( ns === String( NS_MAIN ) ) {
+ name = mw.message( 'blanknamespace' ).text();
+ }
+ return { data: ns, label: name };
+ } ).sort( function ( a, b ) {
+ // wgFormattedNamespaces is an object, and so technically doesn't have to be ordered
+ return a.data - b.data;
+ } );
+
+ if ( config.includeAllValue !== null && config.includeAllValue !== undefined ) {
+ options.unshift( {
+ data: config.includeAllValue,
+ label: mw.message( 'namespacesall' ).text()
+ } );
+ }
+
+ return options;
+ };
+
+}( jQuery, mediaWiki ) );