*Follow-up r78099,r76275:
authorAaron Schulz <aaron@users.mediawiki.org>
Fri, 10 Dec 2010 00:16:28 +0000 (00:16 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Fri, 10 Dec 2010 00:16:28 +0000 (00:16 +0000)
**Converted CheckUser to use RL
**Made checkuser.js borrow block.js IP functions to avoid ugly duplication (and fix the IP recognition)
**Added missing backslashes to block.js regex strings and avoided backreferences (which work the opposite of PCRE when referencing an unmatched group)
*Made CU not give a common prefix if both v6 and v4 addresses are on the list

skins/common/block.js

index bba40a0..fb86cbd 100644 (file)
@@ -1,15 +1,16 @@
 // @TODO: find some better JS file for this
 // Note: borrows from IP.php
 window.isIPv4Address = function( address, allowBlock ) {
+       var block = allowBlock ? '(?:\\/(?:3[0-2]|[12]?\\d))?' : '';
        var RE_IP_BYTE = '(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|0?[0-9]?[0-9])';
-       var RE_IP_ADD = '(?:' + RE_IP_BYTE + '\.){3}' + RE_IP_BYTE;
-       var block = allowBlock ? '(?:\/(?:3[0-2]|[12]?\\d))?' : '';
+       var RE_IP_ADD = '(?:' + RE_IP_BYTE + '\\.){3}' + RE_IP_BYTE;
        return address.search( new RegExp( '^' + RE_IP_ADD + block + '$' ) ) != -1;
 };
 
 // @TODO: find some better JS file for this
 // Note: borrows from IP.php
 window.isIPv6Address = function( address, allowBlock ) {
+       var block = allowBlock ? '(?:\\/(?:12[0-8]|1[01][0-9]|[1-9]?\\d))?' : '';
        var RE_IPV6_ADD =
        '(?:' + // starts with "::" (including "::")
                ':(?::|(?::' + '[0-9A-Fa-f]{1,4}' + '){1,7})' +
@@ -17,11 +18,14 @@ window.isIPv6Address = function( address, allowBlock ) {
                '[0-9A-Fa-f]{1,4}' + '(?::' + '[0-9A-Fa-f]{1,4}' + '){0,6}::' +
        '|' + // contains no "::"
                '[0-9A-Fa-f]{1,4}' + '(?::' + '[0-9A-Fa-f]{1,4}' + '){7}' +
-       '|' + // contains one "::" in the middle
-               '[0-9A-Fa-f]{1,4}' + '(?::(:())?' + '[0-9A-Fa-f]{1,4}' + '(?!\1)){1,6}\2' +
        ')';
-       var block = allowBlock ? '(?:\/(?:12[0-8]|1[01][0-9]|[1-9]?\\d))?' : '';
-       return address.search( new RegExp( '^' + RE_IPV6_ADD + block + '$' ) ) != -1;
+       if ( address.search( new RegExp( '^' + RE_IPV6_ADD + block + '$' ) ) != -1 ) {
+               return true;
+       }
+       var RE_IPV6_ADD = // contains one "::" in the middle (single '::' check below)
+               '[0-9A-Fa-f]{1,4}' + '(?:::?' + '[0-9A-Fa-f]{1,4}' + '){1,6}';
+       return address.search( new RegExp( '^' + RE_IPV6_ADD + block + '$' ) ) != -1
+               && address.search( /::/ ) != -1 && address.search( /::.*::/ ) == -1;
 };
 
 window.considerChangingExpiryFocus = function() {