r78099 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78098‎ | r78099 | r78100 >
Date:22:33, 8 December 2010
Author:aaron
Status:ok (Comments)
Tags:
Comment:
*Follow-up r76275: regexp improvement akin to IP.php
*Fixed "Error: updateBlockOptions is not defined
Source File: http://localhost/wiki/Special:Block/Lightning_Angel
Line: 121"
*TODO: get these functions to a nice JS file and let checkuser.js use then via RL
Modified paths:
  • /trunk/phase3/includes/specials/SpecialBlockip.php (modified) (history)
  • /trunk/phase3/skins/common/block.js (modified) (history)

Diff [purge]

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+
228 window.considerChangingExpiryFocus = function() {
329 if ( !document.getElementById ) {
430 return;
@@ -17,6 +43,7 @@
1844 field.style.display = 'none';
1945 }
2046 };
 47+
2148 window.updateBlockOptions = function() {
2249 if ( !document.getElementById ) {
2350 return;
@@ -27,17 +54,10 @@
2855 return;
2956 }
3057
31 - var addy = target.value;
32 - var isEmpty = addy.match(/^\s*$/);
 58+ var addy = target.value.replace( /(^\s*|\s*$)/, '' ); // trim
 59+ var isEmpty = (addy == "");
3360
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 );
4262 var isIpRange = isIp && addy.match(/\/\d+$/);
4363
4464 var anonymousRow = document.getElementById( 'wpAnonOnlyRow' );
@@ -61,4 +81,5 @@
6282 }
6383 };
6484
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 @@
363363 Html::hidden( 'wpEditToken', $wgUser->editToken() ) .
364364 ( $alreadyBlocked ? Html::hidden( 'wpChangeBlock', 1 ) : "" ) .
365365 Xml::closeElement( 'fieldset' ) .
366 - Xml::closeElement( 'form' ) .
367 - Xml::tags( 'script', array( 'type' => 'text/javascript' ), 'updateBlockOptions()' ) . "\n"
 366+ Xml::closeElement( 'form' )
368367 );
369368
370369 $wgOut->addHTML( $this->getConvenienceLinks() );

Follow-up revisions

RevisionCommit summaryAuthorDate
r78161*Follow-up r78099,r76275:...aaron00:16, 10 December 2010
r79129MFT r78011 r78014 r78015 r78016 r78099 r78117 r78161 r78170 r78172 r78199 r78......platonides19:58, 28 December 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r76275Similar to r76267 but for JS. Should finish bug 24293.aaron22:46, 7 November 2010

Comments

#Comment by Catrope (talk | contribs)   21:58, 14 December 2010

Why is this tagged 1.17? The regex change, the JS error or both? Do r78275 and r78161 need to be backported too?

#Comment by Aaron Schulz (talk | contribs)   22:22, 14 December 2010

Block options changed based on whether the username is an IP or not. Since the IP check is a little over-inclusive for v6 rather than under, perhaps it could just be left broken in 1.17.

I'm not sure what rev r78275 was a typo for. r78161 already has the same backport tag is this. r78099 should go with r78161 or not at all.

#Comment by Catrope (talk | contribs)   12:57, 15 December 2010

r78275 was a typo for r76275, which of course doesn't need to be backported as it predates the branch.

Status & tagging log