1 // @TODO: find some better JS file for this
2 // Note: borrows from IP.php
3 window
.isIPv4Address = function( address
, allowBlock
) {
4 var block
= allowBlock
? '(?:\\/(?:3[0-2]|[12]?\\d))?' : '';
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 return address
.search( new RegExp( '^' + RE_IP_ADD
+ block
+ '$' ) ) != -1;
10 // @TODO: find some better JS file for this
11 // Note: borrows from IP.php
12 window
.isIPv6Address = function( address
, allowBlock
) {
13 var block
= allowBlock
? '(?:\\/(?:12[0-8]|1[01][0-9]|[1-9]?\\d))?' : '';
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}' +
22 if ( address
.search( new RegExp( '^' + RE_IPV6_ADD
+ block
+ '$' ) ) != -1 ) {
25 var RE_IPV6_ADD
= // contains one "::" in the middle (single '::' check below)
26 '[0-9A-Fa-f]{1,4}' + '(?:::?' + '[0-9A-Fa-f]{1,4}' + '){1,6}';
27 return address
.search( new RegExp( '^' + RE_IPV6_ADD
+ block
+ '$' ) ) != -1
28 && address
.search( /::/ ) != -1 && address
.search( /::.*::/ ) == -1;
31 window
.considerChangingExpiryFocus = function() {
32 if ( !document
.getElementById
) {
35 var drop
= document
.getElementById( 'wpBlockExpiry' );
39 var field
= document
.getElementById( 'wpBlockOther' );
44 if ( opt
== 'other' ) {
45 field
.style
.display
= '';
47 field
.style
.display
= 'none';
51 window
.updateBlockOptions = function() {
52 if ( !document
.getElementById
) {
56 var target
= document
.getElementById( 'mw-bi-target' );
61 var addy
= target
.value
.replace( /(^\s*|\s*$)/, '' ); // trim
62 var isEmpty
= (addy
== "");
64 var isIp
= isIPv4Address( addy
, true ) || isIPv6Address( addy
, true );
65 var isIpRange
= isIp
&& addy
.match(/\/\d+$/);
67 var anonymousRow
= document
.getElementById( 'wpAnonOnlyRow' );
69 anonymousRow
.style
.display
= ( !isIp
&& !isEmpty
) ? 'none' : '';
72 var autoblockRow
= document
.getElementById( 'wpEnableAutoblockRow' );
74 autoblockRow
.style
.display
= isIp
&& !isEmpty
? 'none' : '';
77 var hideuserRow
= document
.getElementById( 'wpEnableHideUser' );
79 hideuserRow
.style
.display
= isIp
&& !isEmpty
? 'none' : '';
82 var watchuserRow
= document
.getElementById( 'wpEnableWatchUser' );
84 watchuserRow
.style
.display
= isIpRange
&& !isEmpty
? 'none' : '';
88 addOnloadHook( updateBlockOptions
);
89 addOnloadHook( considerChangingExpiryFocus
);