Index: trunk/extensions/CheckUser/CheckUser_body.php |
— | — | @@ -224,7 +224,7 @@ |
225 | 225 | global $wgOut; |
226 | 226 | $s = '<fieldset id="mw-checkuser-cidrform" style="display:none; clear:both;">' . |
227 | 227 | '<legend>' . wfMsgHtml( 'checkuser-cidr-label' ) . '</legend>'; |
228 | | - $s .= '<textarea id="mw-checkuser-iplist" rows="5" cols="50" onkeyup="updateCIDRresult()" onclick="updateCIDRresult()"></textarea><br />'; |
| 228 | + $s .= '<textarea id="mw-checkuser-iplist" rows="5" cols="50"></textarea><br />'; |
229 | 229 | $s .= wfMsgHtml( 'checkuser-cidr-res' ) . ' ' . |
230 | 230 | Xml::input( 'mw-checkuser-cidr-res', 35, '', array( 'id' => 'mw-checkuser-cidr-res' ) ) . |
231 | 231 | ' <strong id="mw-checkuser-ipnote"></strong>'; |
Index: trunk/extensions/CheckUser/checkuser.js |
— | — | @@ -2,11 +2,16 @@ |
3 | 3 | |
4 | 4 | /* Every time you change this JS please bump $wgCheckUserStyleVersion in CheckUser.php */ |
5 | 5 | |
| 6 | +var showResults = function(size, cidr) { |
| 7 | + $( '#mw-checkuser-cidr-res' ).val( size ); |
| 8 | + $( '#mw-checkuser-ipnote' ).text( cidr ); |
| 9 | +}; |
| 10 | + |
6 | 11 | /* |
7 | 12 | * This function calculates the common range of a list of |
8 | 13 | * IPs. It should be set to update on keyUp. |
9 | 14 | */ |
10 | | -window.updateCIDRresult = function() { |
| 15 | +var updateCIDRresult = function() { |
11 | 16 | var form = document.getElementById( 'mw-checkuser-cidrform' ); |
12 | 17 | if( !form ) { |
13 | 18 | return; // no JS form |
— | — | @@ -16,27 +21,28 @@ |
17 | 22 | if( !iplist ) { |
18 | 23 | return; // no JS form |
19 | 24 | } |
20 | | - var text = iplist.value; |
| 25 | + var text = iplist.value, ips; |
21 | 26 | // Each line should have one IP or range |
22 | 27 | if( text.indexOf("\n") != -1 ) { |
23 | | - var ips = text.split("\n"); |
| 28 | + ips = text.split("\n"); |
24 | 29 | // Try some other delimiters too... |
25 | 30 | } else if( text.indexOf("\t") != -1 ) { |
26 | | - var ips = text.split("\t"); |
| 31 | + ips = text.split("\t"); |
27 | 32 | } else if( text.indexOf(",") != -1 ) { |
28 | | - var ips = text.split(","); |
| 33 | + ips = text.split(","); |
29 | 34 | } else if( text.indexOf("-") != -1 ) { |
30 | | - var ips = text.split("-"); |
| 35 | + ips = text.split("-"); |
31 | 36 | } else if( text.indexOf(" ") != -1 ) { |
32 | | - var ips = text.split(" "); |
| 37 | + ips = text.split(" "); |
33 | 38 | } else { |
34 | | - var ips = text.split(";"); |
| 39 | + ips = text.split(";"); |
35 | 40 | } |
36 | 41 | var bin_prefix = 0; |
37 | 42 | var prefix_cidr = 0; |
38 | 43 | var prefix = new String( '' ); |
39 | 44 | var foundV4 = false; |
40 | 45 | var foundV6 = false; |
| 46 | + var ip_count; |
41 | 47 | // Go through each IP in the list, get its binary form, and |
42 | 48 | // track the largest binary prefix among them... |
43 | 49 | for( var i = 0; i < ips.length; i++ ) { |
— | — | @@ -63,7 +69,7 @@ |
64 | 70 | if( blocs[0] <= 2 ) continue; |
65 | 71 | for( var x = 0; x < blocs.length; x++ ) { |
66 | 72 | bloc = parseInt( blocs[x], 10 ); |
67 | | - bin_block = bloc.toString( 2 ); // concat bin with binary form of bloc |
| 73 | + var bin_block = bloc.toString( 2 ); // concat bin with binary form of bloc |
68 | 74 | while( bin_block.length < 8 ) { |
69 | 75 | bin_block = '0' + bin_block; // pad out as needed |
70 | 76 | } |
— | — | @@ -88,12 +94,10 @@ |
89 | 95 | } |
90 | 96 | } |
91 | 97 | // Build the IP in CIDR form |
92 | | - var prefix_cidr = bin_prefix.length; |
| 98 | + prefix_cidr = bin_prefix.length; |
93 | 99 | // CIDR too small? |
94 | 100 | if( prefix_cidr < 16 ) { |
95 | | - document.getElementById( 'mw-checkuser-cidr-res' ).value = '!'; |
96 | | - document.getElementById( 'mw-checkuser-ipnote' ).innerHTML = '>' + |
97 | | - Math.pow( 2, 32 - prefix_cidr ); |
| 101 | + showResults( '!', '>' + Math.pow( 2, 32 - prefix_cidr ) ); |
98 | 102 | return; // too big |
99 | 103 | } |
100 | 104 | // Build the IP in dotted-quad form |
— | — | @@ -145,7 +149,7 @@ |
146 | 150 | var blocs = ip.split(':'); |
147 | 151 | for( var x = 0; x <= 7; x++ ) { |
148 | 152 | bloc = blocs[x] ? blocs[x] : '0'; |
149 | | - int_block = hex2int( bloc ); // convert hex -> int |
| 153 | + var int_block = hex2int( bloc ); // convert hex -> int |
150 | 154 | bin_block = int_block.toString( 2 ); // concat bin with binary form of bloc |
151 | 155 | while( bin_block.length < 16 ) { |
152 | 156 | bin_block = '0' + bin_block; // pad out as needed |
— | — | @@ -174,9 +178,7 @@ |
175 | 179 | var prefix_cidr = bin_prefix.length; |
176 | 180 | // CIDR too small? |
177 | 181 | if( prefix_cidr < 96 ) { |
178 | | - document.getElementById( 'mw-checkuser-cidr-res' ).value = '!'; |
179 | | - document.getElementById( 'mw-checkuser-ipnote' ).innerHTML = '>' |
180 | | - + Math.pow( 2, 128 - prefix_cidr ); |
| 182 | + showResults('!', '>' + Math.pow( 2, 128 - prefix_cidr ) ); |
181 | 183 | return; // too big |
182 | 184 | } |
183 | 185 | // Build the IP in dotted-quad form |
— | — | @@ -203,22 +205,19 @@ |
204 | 206 | } |
205 | 207 | // Update form |
206 | 208 | if( prefix != '' ) { |
| 209 | + var full = prefix; |
207 | 210 | if( prefix_cidr != false ) { |
208 | | - document.getElementById( 'mw-checkuser-cidr-res' ).value = prefix + '/' + prefix_cidr; |
209 | | - } else { |
210 | | - document.getElementById( 'mw-checkuser-cidr-res' ).value = prefix; |
| 211 | + full += '/' + prefix_cidr; |
211 | 212 | } |
212 | | - document.getElementById( 'mw-checkuser-ipnote' ).innerHTML = '~' + ip_count; |
| 213 | + showResults( '~' + ip_count, full ); |
213 | 214 | } else { |
214 | | - document.getElementById( 'mw-checkuser-cidr-res' ).value = '?'; |
215 | | - document.getElementById( 'mw-checkuser-ipnote' ).innerHTML = ''; |
| 215 | + showResults( '?', '' ); |
216 | 216 | } |
217 | 217 | |
218 | 218 | }; |
219 | | -addOnloadHook( updateCIDRresult ); |
220 | 219 | |
221 | 220 | // Utility function to convert hex to integers |
222 | | -window.hex2int = function( hex ) { |
| 221 | +var hex2int = function( hex ) { |
223 | 222 | hex = new String( hex ); |
224 | 223 | hex = hex.toLowerCase(); |
225 | 224 | var intform = 0; |
— | — | @@ -251,3 +250,10 @@ |
252 | 251 | } |
253 | 252 | return intform; |
254 | 253 | }; |
| 254 | + |
| 255 | +$( function() { |
| 256 | + updateCIDRresult(); |
| 257 | + $('#mw-checkuser-iplist').bind('keyup click', function() { |
| 258 | + updateCIDRresult(); |
| 259 | + }); |
| 260 | +}); |