| Index: trunk/phase3/skins/common/block.js |
| — | — | @@ -1,3 +1,29 @@ |
| | 2 | +// @TODO: find some better JS file for this |
| | 3 | +// Note: borrows from IP.php |
| | 4 | +window.isIPv4Address = function( address, allowBlock ) { |
| | 5 | + var RE_IP_BYTE = '(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|0?[0-9]?[0-9])'; |
| | 6 | + var RE_IP_ADD = '(?:' + RE_IP_BYTE + '\.){3}' + RE_IP_BYTE; |
| | 7 | + var block = allowBlock ? '(?:\/(?:3[0-2]|[12]?\\d))?' : ''; |
| | 8 | + return address.search( new RegExp( '^' + RE_IP_ADD + block + '$' ) ) != -1; |
| | 9 | +}; |
| | 10 | + |
| | 11 | +// @TODO: find some better JS file for this |
| | 12 | +// Note: borrows from IP.php |
| | 13 | +window.isIPv6Address = function( address, allowBlock ) { |
| | 14 | + var RE_IPV6_ADD = |
| | 15 | + '(?:' + // starts with "::" (including "::") |
| | 16 | + ':(?::|(?::' + '[0-9A-Fa-f]{1,4}' + '){1,7})' + |
| | 17 | + '|' + // ends with "::" (except "::") |
| | 18 | + '[0-9A-Fa-f]{1,4}' + '(?::' + '[0-9A-Fa-f]{1,4}' + '){0,6}::' + |
| | 19 | + '|' + // contains no "::" |
| | 20 | + '[0-9A-Fa-f]{1,4}' + '(?::' + '[0-9A-Fa-f]{1,4}' + '){7}' + |
| | 21 | + '|' + // contains one "::" in the middle |
| | 22 | + '[0-9A-Fa-f]{1,4}' + '(?::(:())?' + '[0-9A-Fa-f]{1,4}' + '(?!\1)){1,6}\2' + |
| | 23 | + ')'; |
| | 24 | + var block = allowBlock ? '(?:\/(?:12[0-8]|1[01][0-9]|[1-9]?\\d))?' : ''; |
| | 25 | + return address.search( new RegExp( '^' + RE_IPV6_ADD + block + '$' ) ) != -1; |
| | 26 | +}; |
| | 27 | + |
| 2 | 28 | window.considerChangingExpiryFocus = function() { |
| 3 | 29 | if ( !document.getElementById ) { |
| 4 | 30 | return; |
| — | — | @@ -17,6 +43,7 @@ |
| 18 | 44 | field.style.display = 'none'; |
| 19 | 45 | } |
| 20 | 46 | }; |
| | 47 | + |
| 21 | 48 | window.updateBlockOptions = function() { |
| 22 | 49 | if ( !document.getElementById ) { |
| 23 | 50 | return; |
| — | — | @@ -27,17 +54,10 @@ |
| 28 | 55 | return; |
| 29 | 56 | } |
| 30 | 57 | |
| 31 | | - var addy = target.value; |
| 32 | | - var isEmpty = addy.match(/^\s*$/); |
| | 58 | + var addy = target.value.replace( /(^\s*|\s*$)/, '' ); // trim |
| | 59 | + var isEmpty = (addy == ""); |
| 33 | 60 | |
| 34 | | - // @TODO: get some core JS IP functions |
| 35 | | - // Match the first IP in each list (ignore other garbage) |
| 36 | | - var isIpV4 = addy.match(/^(\d+\.\d+\.\d+\.\d+)(\/\d+)?$/); |
| 37 | | - // Regexp has 3 cases: (starts with '::',ends with '::',neither) |
| 38 | | - var isIpV6 = !addy.match(/::.*::/) // not ambiguous |
| 39 | | - && addy.match(/^(:(:[0-9A-Fa-f]{1,4}){1,7}|[0-9A-Fa-f]{1,4}(::?[0-9A-Fa-f]{1,4}){0,6}::|[0-9A-Fa-f]{1,4}(::?[0-9A-Fa-f]{1,4}){1,7})(\/\d+)?$/); |
| 40 | | - |
| 41 | | - var isIp = ( isIpV4 || isIpV6 ); |
| | 61 | + var isIp = isIPv4Address( addy, true ) || isIPv6Address( addy, true ); |
| 42 | 62 | var isIpRange = isIp && addy.match(/\/\d+$/); |
| 43 | 63 | |
| 44 | 64 | var anonymousRow = document.getElementById( 'wpAnonOnlyRow' ); |
| — | — | @@ -61,4 +81,5 @@ |
| 62 | 82 | } |
| 63 | 83 | }; |
| 64 | 84 | |
| 65 | | -addOnloadHook( considerChangingExpiryFocus ); |
| \ No newline at end of file |
| | 85 | +addOnloadHook( updateBlockOptions ); |
| | 86 | +addOnloadHook( considerChangingExpiryFocus ); |
| Index: trunk/phase3/includes/specials/SpecialBlockip.php |
| — | — | @@ -362,8 +362,7 @@ |
| 363 | 363 | Html::hidden( 'wpEditToken', $wgUser->editToken() ) . |
| 364 | 364 | ( $alreadyBlocked ? Html::hidden( 'wpChangeBlock', 1 ) : "" ) . |
| 365 | 365 | Xml::closeElement( 'fieldset' ) . |
| 366 | | - Xml::closeElement( 'form' ) . |
| 367 | | - Xml::tags( 'script', array( 'type' => 'text/javascript' ), 'updateBlockOptions()' ) . "\n" |
| | 366 | + Xml::closeElement( 'form' ) |
| 368 | 367 | ); |
| 369 | 368 | |
| 370 | 369 | $wgOut->addHTML( $this->getConvenienceLinks() ); |