r47301 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47300‎ | r47301 | r47302 >
Date:22:15, 15 February 2009
Author:aaron
Status:resolved
Tags:
Comment:
* Removed some duplication of IP.php stuff
* Various IPv6 fixes
* Minor UI tweaks
Modified paths:
  • /trunk/extensions/CheckUser/CheckUser.php (modified) (history)
  • /trunk/extensions/CheckUser/CheckUser_body.php (modified) (history)
  • /trunk/extensions/CheckUser/checkuser.js (modified) (history)

Diff [purge]

Index: trunk/extensions/CheckUser/CheckUser_body.php
@@ -68,32 +68,20 @@
6969 $tag = $wgRequest->getBool('usetag') ? trim( $wgRequest->getVal( 'tag' ) ) : "";
7070 $talkTag = $wgRequest->getBool('usettag') ? trim( $wgRequest->getVal( 'talktag' ) ) : "";
7171
72 - # An IPv4?
73 - if( preg_match( '#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(/\d{1,2}|)$#', $user ) ) {
74 - $ip = $user;
75 - $name = '';
 72+ # An IPv4? An IPv6? CIDR included?
 73+ if( IP::isIPAddress($user) ) {
 74+ $ip = IP::sanitizeIP($user);
 75+ $name = '';
7676 $xff = '';
77 - # An IPv6?
78 - } else if( preg_match( '#^[0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})+(/\d{1,3}|)$#', $user ) ) {
79 - $ip = IP::sanitizeIP($user);
80 - $name = '';
81 - $xff = '';
82 - # An IPv4 XFF string?
83 - } else if( preg_match( '#^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(/\d{1,2}|)/xff$#', $user, $matches ) ) {
84 - list( $junk, $xffip, $xffbit) = $matches;
85 - $ip = '';
86 - $name = '';
87 - $xff = $xffip . $xffbit;
88 - # An IPv6 XFF string?
89 - } else if( preg_match( '#^([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4})+)(/\d{1,3}|)/xff$#', $user, $matches ) ) {
90 - list( $junk, $xffip, $xffbit ) = $matches;
91 - $ip = '';
92 - $name = '';
93 - $xff = IP::sanitizeIP( $xffip ) . $xffbit;
 77+ # An IPv4/IPv6 XFF string? CIDR included?
 78+ } else if( preg_match('/(.+)\/xff$/',$user,$m) && IP::isIPAddress($m[1]) ) {
 79+ $ip = '';
 80+ $name = '';
 81+ $xff = IP::sanitizeIP($m[1]) . '/xff';
9482 # A user?
9583 } else {
96 - $ip = '';
97 - $name = $user;
 84+ $ip = '';
 85+ $name = $user;
9886 $xff = '';
9987 }
10088
@@ -227,7 +215,7 @@
228216 $s .= '<textarea id="mw-checkuser-iplist" rows="5" cols="50" onkeyup="updateCIDRresult()" onclick="updateCIDRresult()"></textarea><br/>';
229217 $s .= wfMsgHtml('checkuser-cidr-res') . '&nbsp;' .
230218 Xml::input( 'mw-checkuser-cidr-res',35,'',array('id'=>'mw-checkuser-cidr-res') ) .
231 - '<span id="mw-checkuser-ipnote"></span>';
 219+ '&nbsp;<strong id="mw-checkuser-ipnote"></strong>';
232220 $s .= '</fieldset>';
233221 $wgOut->addHTML( $s );
234222 }
@@ -294,7 +282,7 @@
295283 $lastEditTime = $wgLang->time( wfTimestamp(TS_MW,$lastEdit), true );
296284 return wfMsgHtml( 'checkuser-nomatch-edits', $lastEditDate, $lastEditTime );
297285 }
298 - return wfMsgHtml('checkuser-nomatch');
 286+ return wfMsgExt('checkuser-nomatch','parse');
299287 }
300288
301289 /**
Index: trunk/extensions/CheckUser/CheckUser.php
@@ -34,7 +34,7 @@
3535 # Mass block limits
3636 $wgCheckUserMaxBlocks = 200;
3737
38 -$wgCheckUserStyleVersion = 3;
 38+$wgCheckUserStyleVersion = 4;
3939
4040 # Recent changes data hook
4141 global $wgHooks;
Index: trunk/extensions/CheckUser/checkuser.js
@@ -30,8 +30,6 @@
3131 // Go through each IP in the list, get it's binary form, and track
3232 // the largest binary prefix among them
3333 for( var i=0; i<ips.length; i++ ) {
34 - // Rebuilt formatted bin_prefix for each IP
35 - var prefix = "";
3634 // ...in the spirit of block.js, call this "addy"
3735 var addy = ips[i];
3836 // Match the first IP in each list (ignore other garbage)
@@ -39,6 +37,8 @@
4038 var ipV6 = addy.match(/(^|\b)(:(:[0-9A-Fa-f]{1,4}){1,7}|[0-9A-Fa-f]{1,4}(:{1,2}[0-9A-Fa-f]{1,4}|::$){1,7})(\/\d+)?\b/);
4139 // Binary form
4240 var bin = new String( "" );
 41+ // Rebuilt formatted bin_prefix for each IP
 42+ if( ipV4 || ipV6 ) prefix = '';
4343 // Convert the IP to binary form: IPv4
4444 if( ipV4 ) {
4545 var ip = ipV4[2];
@@ -77,7 +77,7 @@
7878 // CIDR too small?
7979 if( prefix_cidr < 16 ) {
8080 document.getElementById( 'mw-checkuser-cidr-res' ).value = "!";
81 - document.getElementById( 'mw-checkuser-ipnote' ).innerHTML = '';
 81+ document.getElementById( 'mw-checkuser-ipnote' ).innerHTML = "&gt;"+Math.pow(2,32-prefix_cidr);
8282 return; // too big
8383 }
8484 // Build the IP in dotted-quad form
@@ -98,7 +98,22 @@
9999 // Convert the IP to binary form: IPv6
100100 } else if( ipV6 ) {
101101 var ip = ipV6[2];
102 - var cidr = ipV6[3];
 102+ var cidr = ipV6[0].match( /\/\d+$/ );
 103+ var abbrevs = ip.match( /::/g );
 104+ if( abbrevs.length > 1 ) continue; // bad IP!
 105+ // Expand out "::"s
 106+ if( abbrevs.length > 0 ) {
 107+ var colons = ip.match( /:/g );
 108+ var needed = 7 - (colons.length - 2); // 2 from "::"
 109+ var insert = '';
 110+ while( needed > 1 ) {
 111+ insert += ':0';
 112+ needed--;
 113+ }
 114+ ip = ip.replace( '::', insert + ':' );
 115+ // For IPs that start with "::", correct the final IP so that it starts with '0' and not ':'
 116+ if( ip[0] == ':' ) ip = '0' + ip;
 117+ }
103118 // Get each hex octant
104119 var blocs = ip.split(':');
105120 for( var x=0; x<=7; x++ ) {
@@ -134,7 +149,7 @@
135150 // CIDR too small?
136151 if( prefix_cidr < 96 ) {
137152 document.getElementById( 'mw-checkuser-cidr-res' ).value = "!";
138 - document.getElementById( 'mw-checkuser-ipnote' ).innerHTML = '';
 153+ document.getElementById( 'mw-checkuser-ipnote' ).innerHTML = "&gt;"+Math.pow(2,128-prefix_cidr);
139154 return; // too big
140155 }
141156 // Build the IP in dotted-quad form
@@ -148,11 +163,11 @@
149164 }
150165 bloc = bloc.toString(16); // convert to hex
151166 prefix += ( z == 7 ) ? bloc : bloc + ':';
152 - // Is the CIDR meaningful?
153 - if( prefix_cidr == 128 ) prefix_cidr = false;
154167 }
155168 // Get IPs affected
156169 ip_count = Math.pow(2,128-prefix_cidr);
 170+ // Is the CIDR meaningful?
 171+ if( prefix_cidr == 128 ) prefix_cidr = false;
157172 }
158173 }
159174 // Update form
@@ -162,7 +177,10 @@
163178 } else {
164179 document.getElementById( 'mw-checkuser-cidr-res' ).value = prefix;
165180 }
166 - document.getElementById( 'mw-checkuser-ipnote' ).innerHTML = '&nbsp;~' + ip_count;
 181+ document.getElementById( 'mw-checkuser-ipnote' ).innerHTML = '~' + ip_count;
 182+ } else {
 183+ document.getElementById( 'mw-checkuser-cidr-res' ).value = '?';
 184+ document.getElementById( 'mw-checkuser-ipnote' ).innerHTML = '';
167185 }
168186
169187 }

Status & tagging log