/*!
* MediaWiki Widgets - UsersMultiselectWidget class.
*
* @copyright 2017 MediaWiki Widgets Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
( function () {
/**
* @classdesc Input list of users in a single line.
*
* If used inside HTML form the results will be sent as the list of
* newline-separated usernames.
*
* This can be configured to accept IP addresses and/or ranges as well as
* usernames.
*
* @class
* @extends OO.ui.MenuTagMultiselectWidget
*
* @constructor
* @description Create an instance of `mw.widgets.UsersMultiselectWidget`.
* @param {Object} [config] Configuration options
* @param {mw.Api} [config.api] Instance of mw.Api (or subclass thereof) to use for queries
* @param {number} [config.limit=10] Number of results to show in autocomplete menu
* @param {string} [config.name] Name of input to submit results (when used in HTML forms)
* @param {boolean} [config.ipAllowed=false] Show IP addresses in autocomplete menu
* If false, single IP addresses are not allowed, even if IP ranges are allowed.
* @param {boolean} [config.ipRangeAllowed=false] Show IP ranges in autocomplete menu
* @param {Object} [config.ipRangeLimits] Maximum allowed IP ranges (defaults match HTMLUserTextField.php)
* @param {number} [config.ipRangeLimits.IPv4 = 16] Maximum allowed IPv4 range
* @param {number} [config.ipRangeLimits.IPv6 = 32] Maximum allowed IPv6 range
* @param {boolean} [config.excludenamed] Whether to exclude named users or not
* @param {boolean} [config.excludetemp] Whether to exclude temporary users or not
*/
mw.widgets.UsersMultiselectWidget = function MwWidgetsUsersMultiselectWidget( config ) {
// Config initialization
config = Object.assign( {
limit: 10,
ipAllowed: false,
ipRangeAllowed: false,
ipRangeLimits: {
IPv4: 16,
IPv6: 32
},
excludeNamed: false,
excludeTemp: false
}, config );
// Parent constructor
mw.widgets.UsersMultiselectWidget.super.call( this, Object.assign( {}, config, {} ) );
// Mixin constructors
OO.ui.mixin.PendingElement.call( this, Object.assign( {}, config, { $pending: this.$handle } ) );
// Properties
this.limit = config.limit;
this.ipAllowed = config.ipAllowed;
this.ipRangeAllowed = config.ipRangeAllowed;
this.ipRangeLimits = config.ipRangeLimits;
this.excludeNamed = config.excludeNamed;
this.excludeTemp = config.excludeTemp;
if ( 'name' in config ) {
// Use this instead of , because hidden inputs do not have separate
// 'value' and 'defaultValue' properties. The script on Special:Preferences
// (mw.special.preferences.confirmClose) checks this property to see if a field was changed.
this.$hiddenInput = $( '