Convert Special:BlockIP JS to jQuery/ResourceLoader. Change the order of the checkbo...
authorHappy-melon <happy-melon@users.mediawiki.org>
Thu, 3 Mar 2011 23:54:39 +0000 (23:54 +0000)
committerHappy-melon <happy-melon@users.mediawiki.org>
Thu, 3 Mar 2011 23:54:39 +0000 (23:54 +0000)
includes/specials/SpecialBlockip.php
resources/Resources.php
resources/mediawiki.special/mediawiki.special.block.js [new file with mode: 0644]
skins/common/block.js [deleted file]

index 690d3bc..4340cae 100644 (file)
@@ -199,7 +199,7 @@ class IPBlockForm extends SpecialPage {
                        wfMsgForContent( 'ipbreason-dropdown' ),
                        wfMsgForContent( 'ipbreasonotherlist' ), $this->BlockReasonList, 'wpBlockDropDown', 4 );
 
-               $wgOut->addModules( 'mediawiki.legacy.block' );
+               $wgOut->addModules( 'mediawiki.special.block' );
                $wgOut->addHTML(
                        Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'blockip' ) ) .
                        Xml::openElement( 'fieldset' ) .
@@ -269,14 +269,6 @@ class IPBlockForm extends SpecialPage {
                                ) + ( $this->BlockAddress ? array( 'autofocus' ) : array() ) ) . "
                                </td>
                        </tr>
-                       <tr id='wpAnonOnlyRow'>
-                               <td>&#160;</td>
-                               <td class='mw-input'>" .
-                               Xml::checkLabel( wfMsg( 'ipbanononly' ),
-                                               'wpAnonOnly', 'wpAnonOnly', $this->BlockAnonOnly,
-                                               array( 'tabindex' => '6' ) ) . "
-                               </td>
-                       </tr>
                        <tr id='wpCreateAccountRow'>
                                <td>&#160;</td>
                                <td class='mw-input'>" .
@@ -284,14 +276,6 @@ class IPBlockForm extends SpecialPage {
                                                'wpCreateAccount', 'wpCreateAccount', $this->BlockCreateAccount,
                                                array( 'tabindex' => '7' ) ) . "
                                </td>
-                       </tr>
-                       <tr id='wpEnableAutoblockRow'>
-                               <td>&#160;</td>
-                               <td class='mw-input'>" .
-                                       Xml::checkLabel( wfMsg( 'ipbenableautoblock' ),
-                                               'wpEnableAutoblock', 'wpEnableAutoblock', $this->BlockEnableAutoblock,
-                                               array( 'tabindex' => '8' ) ) . "
-                               </td>
                        </tr>"
                );
 
@@ -308,6 +292,32 @@ class IPBlockForm extends SpecialPage {
                        );
                }
 
+               # Can we explicitly disallow the use of user_talk?
+               global $wgBlockAllowsUTEdit;
+               if( $wgBlockAllowsUTEdit ){
+                       $wgOut->addHTML("
+                               <tr id='wpAllowUsertalkRow'>
+                                       <td>&#160;</td>
+                                       <td class='mw-input'>" .
+                                               Xml::checkLabel( wfMsg( 'ipballowusertalk' ),
+                                                       'wpAllowUsertalk', 'wpAllowUsertalk', $this->BlockAllowUsertalk,
+                                                       array( 'tabindex' => '12' ) ) . "
+                                       </td>
+                               </tr>"
+                       );
+               }
+
+               $wgOut->addHTML( "
+                       <tr id='wpEnableAutoblockRow'>
+                               <td>&#160;</td>
+                               <td class='mw-input'>" .
+                                       Xml::checkLabel( wfMsg( 'ipbenableautoblock' ),
+                                               'wpEnableAutoblock', 'wpEnableAutoblock', $this->BlockEnableAutoblock,
+                                               array( 'tabindex' => '8' ) ) . "
+                               </td>
+                       </tr>"
+               );
+
                // Allow some users to hide name from block log, blocklist and listusers
                if( $wgUser->isAllowed( 'hideuser' ) ) {
                        $wgOut->addHTML("
@@ -337,22 +347,15 @@ class IPBlockForm extends SpecialPage {
                        );
                }
 
-               # Can we explicitly disallow the use of user_talk?
-               global $wgBlockAllowsUTEdit;
-               if( $wgBlockAllowsUTEdit ){
-                       $wgOut->addHTML("
-                               <tr id='wpAllowUsertalkRow'>
-                                       <td>&#160;</td>
-                                       <td class='mw-input'>" .
-                                               Xml::checkLabel( wfMsg( 'ipballowusertalk' ),
-                                                       'wpAllowUsertalk', 'wpAllowUsertalk', $this->BlockAllowUsertalk,
-                                                       array( 'tabindex' => '12' ) ) . "
-                                       </td>
-                               </tr>"
-                       );
-               }
-
                $wgOut->addHTML("
+                       <tr id='wpAnonOnlyRow'>
+                               <td>&#160;</td>
+                               <td class='mw-input'>" .
+                                       Xml::checkLabel( wfMsg( 'ipbanononly' ),
+                                                       'wpAnonOnly', 'wpAnonOnly', $this->BlockAnonOnly,
+                                                       array( 'tabindex' => '6' ) ) . "
+                               </td>
+                       </tr>
                        <tr>
                                <td style='padding-top: 1em'>&#160;</td>
                                <td  class='mw-submit' style='padding-top: 1em'>" .
index 085462c..3e67c30 100644 (file)
@@ -424,6 +424,10 @@ return array(
        'mediawiki.special.search' => array(
                'scripts' => 'resources/mediawiki.special/mediawiki.special.search.js',
        ),
+       'mediawiki.special.block' => array(
+               'scripts' => 'resources/mediawiki.special/mediawiki.special.block.js',
+               'dependencies' => array( 'jquery.effects.blind' ),
+       ),
        'mediawiki.special.upload' => array(
                // @TODO: merge in remainder of mediawiki.legacy.upload
                'scripts' => 'resources/mediawiki.special/mediawiki.special.upload.js',
diff --git a/resources/mediawiki.special/mediawiki.special.block.js b/resources/mediawiki.special/mediawiki.special.block.js
new file mode 100644 (file)
index 0000000..4955545
--- /dev/null
@@ -0,0 +1,57 @@
+/* JavaScript for Special:Block */
+jQuery( function( $ ) {
+
+       $('#mw-bi-target').keyup(function(){
+               var isIPv4Address = function( address ) {
+                       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;
+                       return address.search( new RegExp( '^' + RE_IP_ADD + '(?:\\/(?:3[0-2]|[12]?\\d))?$' ) ) != -1;
+               };
+               var isIPv6Address = function( address ) {
+                       var RE_IPV6_ADD =
+                       '(?:' + // starts with "::" (including "::")
+                               ':(?::|(?::' + '[0-9A-Fa-f]{1,4}' + '){1,7})' +
+                       '|' + // ends with "::" (except "::")
+                               '[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}' +
+                       ')';
+                       if ( address.search( new RegExp( '^' + RE_IPV6_ADD + '(?:\\/(?:12[0-8]|1[01][0-9]|[1-9]?\\d))?$' ) ) != -1 ) {
+                               return true;
+                       }
+                       var RE_IPV6_ADD_SHORT = // 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_SHORT + '(?:\\/(?:12[0-8]|1[01][0-9]|[1-9]?\\d))?$' ) ) != -1
+                               && address.search( /::/ ) != -1 && address.search( /::.*::/ ) == -1;
+               };
+
+               var input = $('#mw-bi-target').val();
+
+               var isEmpty = ( input == "" );
+               var isIp = isIPv4Address( input ) || isIPv6Address( input );
+               var isIpRange = isIp && input.match(/\/\d+$/);
+
+               if( !isEmpty ){
+                       if( isIp ){
+                               $( '#wpAnonOnlyRow' ).stop( true, true ).delay(1000).fadeIn();
+                               $( '#wpEnableAutoblockRow, #wpEnableHideUser' ).stop( true, true ).delay(1000).fadeOut();
+                       } else {
+                               $( '#wpAnonOnlyRow' ).stop( true, true ).delay(1000).fadeOut();
+                               $( '#wpEnableAutoblockRow, #wpEnableHideUser' ).stop( true, true ).delay(1000).fadeIn();
+                       }
+                       if( isIpRange ){
+                               $( '#wpEnableWatchUser' ).stop( true, true ).delay(1000).fadeOut();
+                       } else {
+                               $( '#wpEnableWatchUser' ).stop( true, true ).delay(1000).fadeIn();
+                       }
+               }
+       }).keyup();
+
+       $('#wpBlockExpiry').change( function(){
+               if( $(this).val() == 'other' ){
+                       $('#wpBlockOther').stop( true, true ).fadeIn();
+               } else {
+                       $('#wpBlockOther').stop( true, true ).fadeOut();
+               }
+       }).change();
+} );
\ No newline at end of file
diff --git a/skins/common/block.js b/skins/common/block.js
deleted file mode 100644 (file)
index fb86cbd..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-// @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;
-       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})' +
-       '|' + // ends with "::" (except "::")
-               '[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}' +
-       ')';
-       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() {
-       if ( !document.getElementById ) {
-               return;
-       }
-       var drop = document.getElementById( 'wpBlockExpiry' );
-       if ( !drop ) {
-               return;
-       }
-       var field = document.getElementById( 'wpBlockOther' );
-       if ( !field ) {
-               return;
-       }
-       var opt = drop.value;
-       if ( opt == 'other' ) {
-               field.style.display = '';
-       } else {
-               field.style.display = 'none';
-       }
-};
-
-window.updateBlockOptions = function() {
-       if ( !document.getElementById ) {
-               return;
-       }
-
-       var target = document.getElementById( 'mw-bi-target' );
-       if ( !target ) {
-               return;
-       }
-
-       var addy = target.value.replace( /(^\s*|\s*$)/, '' ); // trim
-       var isEmpty = (addy == ""); 
-
-       var isIp = isIPv4Address( addy, true ) || isIPv6Address( addy, true );
-       var isIpRange = isIp && addy.match(/\/\d+$/);
-
-       var anonymousRow = document.getElementById( 'wpAnonOnlyRow' );
-       if( anonymousRow ) {
-               anonymousRow.style.display = ( !isIp && !isEmpty ) ? 'none' : '';
-       }
-
-       var autoblockRow = document.getElementById( 'wpEnableAutoblockRow' );
-       if( autoblockRow ) {
-               autoblockRow.style.display = isIp && !isEmpty ? 'none' : '';
-       }
-       
-       var hideuserRow = document.getElementById( 'wpEnableHideUser' );
-       if( hideuserRow ) {
-               hideuserRow.style.display = isIp && !isEmpty ? 'none' : '';
-       }
-
-       var watchuserRow = document.getElementById( 'wpEnableWatchUser' );
-       if( watchuserRow ) {
-               watchuserRow.style.display = isIpRange && !isEmpty ? 'none' : '';
-       }
-};
-
-addOnloadHook( updateBlockOptions );
-addOnloadHook( considerChangingExpiryFocus );