MediaWiki:Gadget-libSensitiveIPs.js: Difference between revisions

Content deleted Content added
add top comment
 
(7 intermediate revisions by the same user not shown)
Line 26:
*
* mw.loader.using( [ 'ext.gadget.libSensitiveIPs' ], function () {
* mw.libs.sensitiveIPs.query( {
* test: [ '1.2.3.4', '5.6.7.8' ]
* } ).then( function ( result ) {
* // Do something with the result
* } );
Line 39 ⟶ 41:
* The MIT License (MIT)
*
* Copyright (c) 20152016 Mr. Stradivarius
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Line 62 ⟶ 64:
( function ( $, mw, undefined ) {
'use strict';
var mw.libs.sensitiveIPs; = {
 
sensitiveIPs = mw.libs.sensitiveIPs = {
/**
* Query the API
},*
* @param {Object} params - API query parameters
*
* @param {string[]} options.test - IP addresses or IP ranges to test for
* sensitivity.
*
* @param {string[]} options.entities - Entity IDs to display data for.
* "Entities" are countries or organizations whose IPs are deemed
* sensitive by Wikipedia. Entity IDs are defined in
* https://en.wikipedia.org/wiki/Module:Sensitive_IP_addresses/list.
*
* @return {$.Promise}
* A jQuery Promise that is resolved with the query result, as a
* JavaScript object. For the structure of the query results, see
* https://en.wikipedia.org/wiki/Module:Sensitive_IP_addresses/API#Results.
*
@example
// Find whether the IP "1.2.3.4" is sensitive.
mw.loader.using( 'ext.gadget.libSensitiveIPs', function () {
sensitiveIPs = mw.libs.sensitiveIPs =.query( {
"test": [ "1.2.3.4" ]
} ).done( function( data ) {
console.log( data.sensitiveips.matches.length > 0 );
} );
} );
*
*/
query: function ( params ) {
if ( !( params instanceof Object ) ) {
Line 74 ⟶ 105:
func: 'query',
args: [ params ]
isSensitive: } ).then( function ( sdata ) {
} );
// Return a rejected promise if the Lua API reported an error.
},
return $.Deferred( function ( deferred ) {
 
if ( data.sensitiveips ) {
isSensitive: function ( s ) {
return sensitiveIPsdeferred.query( { test: [ s ] } ).then( function resolve( data ) {;
return } else if ( data.sensitiveips.matches.lengtherror >) 0;{
return deferred.reject( data.error.code, data );
} else {
return deferred.reject(
'libsips-unknown-api-error',
{ error: {
code: 'libsips-unknown-api-error',
info: 'unexpected API response from mw.libs.lua'
} }
);
}
} ).promise();
} );
}