Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Colocar esto en el CSS personal para que esas IP aparezcan de color rojo:
- a.mw-userlink.IPBlackList {background: red; font-weight: bold;}
- */
- /*
- * Utilidad para señalar los enlaces a las contribuciones de direcciones IP a partir de rangos de IP
- * Autor: Jesús Martínez Novo - [[User:Ciencia Al Poder]]
- */
- (function() {
- var reIPContrib = /^Especial:Contribuciones\/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$/;
- var IPBlackList = [
- // Definir aquí los rangos de IP a señalar.
- // Ejemplo:
- // {range: '127.0.0.0/8'},
- // {range: '172.16.0.0/12'},
- // {range: '192.168.0.0/24'} <-- El último sin la coma al final!!
- {range: '62.43.0.0/16'}
- ];
- function checkForBlacklistedIP() {
- // Init cache object
- for (var i = 0; i < IPBlackList.length; i++) {
- IPBlackList[i].oIP = splitIP(IPBlackList[i].range);
- }
- var contLinks = $('#bodyContent').find('a.mw-userlink[title^="Especial:Contribuciones/"]').filter(checkJQAnchorIPBL);
- if (contLinks.length) {
- alert('IP sospechosas encontradas');
- } else {
- alert('No se han encontrado IP sospechosas');
- }
- contLinks.addClass('IPBlackList');
- return contLinks;
- }
- function checkJQAnchorIPBL() {
- var t = this.title;
- if (reIPContrib.test(t)) {
- var oIP = splitIP(t.substr('Especial:Contribuciones/'.length));
- var oBLIP = null;
- for (var i = 0; i < IPBlackList.length; i++) {
- oBLIP = IPBlackList[i].oIP;
- if (matchIP(oIP, oBLIP)) return true;
- }
- }
- return false;
- }
- function splitIP(ip) {
- var ip_net = ip.split('/');
- var ip_parts = ip_net[0].split('.');
- var netmask = 32;
- if (ip_net.length == 2) {
- netmask = parseInt(ip_net[1], 10);
- }
- return {ip: ip_parts, mask: netmask};
- }
- function matchIP(oIP, oRange) {
- var mask = oRange.mask;
- for (var i = 0; i < 4; i++) {
- if (mask / 8 > 1) {
- if (oIP.ip[i] != oRange.ip[i]) {
- return false;
- }
- } else {
- var bitmask = 8 - mask;
- if (bitmask == 0) return true;
- bitmask = Math.pow(2,bitmask);
- if ( (parseInt(oIP.ip[i], 10) & bitmask) == (parseInt(oRange.ip[i], 10) & bitmask) ) return true;
- return false;
- }
- mask -= 8;
- }
- }
- window.checkForBlacklistedIP = checkForBlacklistedIP;
- }());
- // Añadir enlace de chequeo en Especial:Contribuciones
- if (window.wgNamespaceNumber == -1 && window.wgCanonicalSpecialPageName == 'Recentchanges') {
- $(function() {
- addPortletLink('p-cactions', 'javascript:window.checkForBlacklistedIP();void(0);', 'Comprobar IP en ListaNegra');
- });
- // En vez de lo anterior, se puede hacer automáticamente así
- //$(checkForBlacklistedIP);
- // O incluso ponerlo fuera de este if, o cambiándolo para que funcione en otras páginas o en todas.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement