MediaWiki:Gadget-libSensitiveIPs.js
Appearance
![]() | This page is loaded as a part of the libSensitiveIPs gadget, a hidden gadget. |
( function ( $, mw, undefined ) {
'use strict';
var sensitiveIPs;
sensitiveIPs = mw.libs.sensitiveIPs = {
query: function ( params ) {
if ( !( params instanceof Object ) ) {
throw new TypeError( "type error in arg #1 to 'query' (object expected)" );
}
params.format = 'json';
return mw.libs.lua.call( {
format: 'json',
module: 'Sensitive IP addresses/API',
func: 'query',
args: [ params ]
} ).then( function ( data ) {
// Add blank arrays and objects for queries that didn't return
// a match. This can't be done in Lua, as Scribunto's
// mw.text.jsonEncode can't distinguish between empty arrays
// and empty objects due to the nature of Lua tables.
data.sensitiveips.matches = data.sensitiveips.matches || [];
data.sensitiveips['matched-ranges'] = data.sensitiveips['matched-ranges'] || {};
data.sensitiveips.entities = data.sensitiveips.entities || {};
data.sensitiveips['entity-ids'] = data.sensitiveips['entity-ids'] || [];
return data;
} );
},
isSensitive: function ( s ) {
return sensitiveIPs.query( { test: [ s ] } ).then( function ( data ) {
return data.sensitiveips.matches.length > 0;
} );
}
};
} )( jQuery, mediaWiki );