r47255 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47254‎ | r47255 | r47256 >
Date:09:41, 14 February 2009
Author:aaron
Status:deferred
Tags:
Comment:
IP match fix and enhancements
Modified paths:
  • /trunk/extensions/CheckUser/CheckUser.php (modified) (history)
  • /trunk/extensions/CheckUser/checkuser.js (modified) (history)

Diff [purge]

Index: trunk/extensions/CheckUser/CheckUser.php
@@ -34,7 +34,7 @@
3535 # Mass block limits
3636 $wgCheckUserMaxBlocks = 200;
3737
38 -$wgCheckUserStyleVersion = 2;
 38+$wgCheckUserStyleVersion = 3;
3939
4040 # Recent changes data hook
4141 global $wgHooks;
Index: trunk/extensions/CheckUser/checkuser.js
@@ -12,8 +12,18 @@
1313 form.style.display = 'inline'; // unhide form (JS active)
1414 var iplist = document.getElementById( 'mw-checkuser-iplist' );
1515 if( !iplist ) return; // no JS form
16 - // Each line has one IP or range
17 - var ips = iplist.value.split("\n");
 16+ var text = iplist.value;
 17+ // Each line should have one IP or range
 18+ if( text.indexOf("\n") != -1 ) {
 19+ var ips = text.split("\n");
 20+ // Try some other delimiters too
 21+ } else if( text.indexOf("\t") != -1 ) {
 22+ var ips = text.split("\t");
 23+ } else if( text.indexOf(",") != -1 ) {
 24+ var ips = text.split(",");
 25+ } else {
 26+ var ips = text.split(";");
 27+ }
1828 var bin_prefix = 0;
1929 var prefix_cidr = 0;
2030 var prefix = new String( "" );
@@ -25,14 +35,14 @@
2636 // ...in the spirit of block.js, call this "addy"
2737 var addy = ips[i];
2838 // Match the first IP in each list (ignore other garbage)
29 - var ipV4 = addy.match(/\b(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(\/\d+)?\b/);
30 - 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/);
 39+ var ipV4 = addy.match(/(^|\b)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(\/\d+)?\b/);
 40+ 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/);
3141 // Binary form
3242 var bin = new String( "" );
3343 // Convert the IP to binary form: IPv4
3444 if( ipV4 ) {
35 - var ip = ipV4[1];
36 - var cidr = ipV4[2]; // CIDR, if it exists
 45+ var ip = ipV4[2];
 46+ var cidr = ipV4[3]; // CIDR, if it exists
3747 // Get each quad integer
3848 var blocs = ip.split('.');
3949 for( var x=0; x<blocs.length; x++ ) {
@@ -87,8 +97,8 @@
8898 if( prefix_cidr == 32 ) prefix_cidr = false;
8999 // Convert the IP to binary form: IPv6
90100 } else if( ipV6 ) {
91 - var ip = ipV6[1];
92 - var cidr = ipV6[2];
 101+ var ip = ipV6[2];
 102+ var cidr = ipV6[3];
93103 // Get each hex octant
94104 var blocs = ip.split(':');
95105 for( var x=0; x<=7; x++ ) {

Status & tagging log