Jump to content

MediaWiki:Gadget-libSensitiveIPs.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 01:31, 20 September 2016 (add top comment). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*  ___________________________________________________________________________
 * |                                                                           |
 * |                    === WARNING: GLOBAL GADGET FILE ===                    |
 * |                  Changes to this page affect many users.                  |
 * | Please discuss changes on the talk page or on [[Wikipedia_talk:Gadget]]   |
 * | before editing.                                                           |
 * |___________________________________________________________________________|
 *
 * 
 * libSensitiveIPs provides an interface for accessing information about IPs or
 * IP ranges for which blocks should be handled with care. This may be because
 * the IPs belong to a politically sensitive organization, and blocks (and block
 * messages) may be reported in the press, or the IPs may belong to bots or APIs
 * on which Wikipedia depends for normal operation. (See [[WP:SIP]] for more
 * background about sensitive IPs.)
 * 
 * 
 *                              === USAGE ===
 * 
 * The library should be loaded as a MediaWiki gadget, using mw.loader.load,
 * mw.loader.using, or similar. The name of the gadget is
 * "ext.gadget.libSensitiveIPs". Once the gadget is loaded, you can access its
 * functions from mw.libs.sensitiveIPs.<function name>. Documentation for the
 * functions can be found in the JSDoc comment blocks in the library code. For
 * example:
 * 
 * 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
 *     } );
 * } );
 * 
 * 
 *                             === LICENCE ===
 *
 * Author: Mr. Stradivarius
 * Licence: MIT
 *
 * The MIT License (MIT)
 *
 * Copyright (c) 2015 Mr. Stradivarius
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

( 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 ]
			} );
		},

		isSensitive: function ( s ) {
			return sensitiveIPs.query( { test: [ s ] } ).then( function ( data ) {
				return data.sensitiveips.matches.length > 0;
			} );
		}
	};
} )( jQuery, mediaWiki );