http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88730
Revision: 88730
Author: brion
Date: 2011-05-24 18:12:26 +0000 (Tue, 24 May 2011)
Log Message:
-----------
JS fixes & a little cleanup/modernization on CheckUser
Was throwing errors due to trying to use addOnloadHook() from what's now loaded
by ResourceLoader before wikibits classic stuff.
Switched a few things to use jQuery, and factored out a couple common bits of
output formatting code.
Also tried to fix some bogus undeclared globals and duplicate var declarations.
Modified Paths:
--------------
trunk/extensions/CheckUser/CheckUser_body.php
trunk/extensions/CheckUser/checkuser.js
Modified: trunk/extensions/CheckUser/CheckUser_body.php
===================================================================
--- trunk/extensions/CheckUser/CheckUser_body.php 2011-05-24 17:48:22 UTC
(rev 88729)
+++ trunk/extensions/CheckUser/CheckUser_body.php 2011-05-24 18:12:26 UTC
(rev 88730)
@@ -224,7 +224,7 @@
global $wgOut;
$s = '<fieldset id="mw-checkuser-cidrform" style="display:none;
clear:both;">' .
'<legend>' . wfMsgHtml( 'checkuser-cidr-label' ) .
'</legend>';
- $s .= '<textarea id="mw-checkuser-iplist" rows="5" cols="50"
onkeyup="updateCIDRresult()" onclick="updateCIDRresult()"></textarea><br />';
+ $s .= '<textarea id="mw-checkuser-iplist" rows="5"
cols="50"></textarea><br />';
$s .= wfMsgHtml( 'checkuser-cidr-res' ) . ' ' .
Xml::input( 'mw-checkuser-cidr-res', 35, '', array(
'id' => 'mw-checkuser-cidr-res' ) ) .
' <strong id="mw-checkuser-ipnote"></strong>';
Modified: trunk/extensions/CheckUser/checkuser.js
===================================================================
--- trunk/extensions/CheckUser/checkuser.js 2011-05-24 17:48:22 UTC (rev
88729)
+++ trunk/extensions/CheckUser/checkuser.js 2011-05-24 18:12:26 UTC (rev
88730)
@@ -2,11 +2,16 @@
/* Every time you change this JS please bump $wgCheckUserStyleVersion in
CheckUser.php */
+var showResults = function(size, cidr) {
+ $( '#mw-checkuser-cidr-res' ).val( size );
+ $( '#mw-checkuser-ipnote' ).text( cidr );
+};
+
/*
* This function calculates the common range of a list of
* IPs. It should be set to update on keyUp.
*/
-window.updateCIDRresult = function() {
+var updateCIDRresult = function() {
var form = document.getElementById( 'mw-checkuser-cidrform' );
if( !form ) {
return; // no JS form
@@ -16,27 +21,28 @@
if( !iplist ) {
return; // no JS form
}
- var text = iplist.value;
+ var text = iplist.value, ips;
// Each line should have one IP or range
if( text.indexOf("\n") != -1 ) {
- var ips = text.split("\n");
+ ips = text.split("\n");
// Try some other delimiters too...
} else if( text.indexOf("\t") != -1 ) {
- var ips = text.split("\t");
+ ips = text.split("\t");
} else if( text.indexOf(",") != -1 ) {
- var ips = text.split(",");
+ ips = text.split(",");
} else if( text.indexOf("-") != -1 ) {
- var ips = text.split("-");
+ ips = text.split("-");
} else if( text.indexOf(" ") != -1 ) {
- var ips = text.split(" ");
+ ips = text.split(" ");
} else {
- var ips = text.split(";");
+ ips = text.split(";");
}
var bin_prefix = 0;
var prefix_cidr = 0;
var prefix = new String( '' );
var foundV4 = false;
var foundV6 = false;
+ var ip_count;
// Go through each IP in the list, get its binary form, and
// track the largest binary prefix among them...
for( var i = 0; i < ips.length; i++ ) {
@@ -63,7 +69,7 @@
if( blocs[0] <= 2 ) continue;
for( var x = 0; x < blocs.length; x++ ) {
bloc = parseInt( blocs[x], 10 );
- bin_block = bloc.toString( 2 ); // concat bin
with binary form of bloc
+ var bin_block = bloc.toString( 2 ); // concat
bin with binary form of bloc
while( bin_block.length < 8 ) {
bin_block = '0' + bin_block; // pad out
as needed
}
@@ -88,12 +94,10 @@
}
}
// Build the IP in CIDR form
- var prefix_cidr = bin_prefix.length;
+ prefix_cidr = bin_prefix.length;
// CIDR too small?
if( prefix_cidr < 16 ) {
- document.getElementById(
'mw-checkuser-cidr-res' ).value = '!';
- document.getElementById( 'mw-checkuser-ipnote'
).innerHTML = '>' +
- Math.pow( 2, 32 - prefix_cidr );
+ showResults( '!', '>' + Math.pow( 2, 32 -
prefix_cidr ) );
return; // too big
}
// Build the IP in dotted-quad form
@@ -145,7 +149,7 @@
var blocs = ip.split(':');
for( var x = 0; x <= 7; x++ ) {
bloc = blocs[x] ? blocs[x] : '0';
- int_block = hex2int( bloc ); // convert hex ->
int
+ var int_block = hex2int( bloc ); // convert hex
-> int
bin_block = int_block.toString( 2 ); // concat
bin with binary form of bloc
while( bin_block.length < 16 ) {
bin_block = '0' + bin_block; // pad out
as needed
@@ -174,9 +178,7 @@
var prefix_cidr = bin_prefix.length;
// CIDR too small?
if( prefix_cidr < 96 ) {
- document.getElementById(
'mw-checkuser-cidr-res' ).value = '!';
- document.getElementById( 'mw-checkuser-ipnote'
).innerHTML = '>'
- + Math.pow( 2, 128 - prefix_cidr );
+ showResults('!', '>' + Math.pow( 2, 128 -
prefix_cidr ) );
return; // too big
}
// Build the IP in dotted-quad form
@@ -203,22 +205,19 @@
}
// Update form
if( prefix != '' ) {
+ var full = prefix;
if( prefix_cidr != false ) {
- document.getElementById( 'mw-checkuser-cidr-res'
).value = prefix + '/' + prefix_cidr;
- } else {
- document.getElementById( 'mw-checkuser-cidr-res'
).value = prefix;
+ full += '/' + prefix_cidr;
}
- document.getElementById( 'mw-checkuser-ipnote' ).innerHTML =
'~' + ip_count;
+ showResults( '~' + ip_count, full );
} else {
- document.getElementById( 'mw-checkuser-cidr-res' ).value = '?';
- document.getElementById( 'mw-checkuser-ipnote' ).innerHTML = '';
+ showResults( '?', '' );
}
};
-addOnloadHook( updateCIDRresult );
// Utility function to convert hex to integers
-window.hex2int = function( hex ) {
+var hex2int = function( hex ) {
hex = new String( hex );
hex = hex.toLowerCase();
var intform = 0;
@@ -251,3 +250,10 @@
}
return intform;
};
+
+$( function() {
+ updateCIDRresult();
+ $('#mw-checkuser-iplist').bind('keyup click', function() {
+ updateCIDRresult();
+ });
+});
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs