* I didn't even notice the extra reblock check; merged this into submit button with...
authorAaron Schulz <aaron@users.mediawiki.org>
Sun, 23 Nov 2008 09:52:29 +0000 (09:52 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Sun, 23 Nov 2008 09:52:29 +0000 (09:52 +0000)
* Break long line
* (bug 16436) Don't log if nothing changed

includes/Block.php
includes/specials/SpecialBlockip.php

index 5723dc7..f62201a 100644 (file)
@@ -60,7 +60,7 @@ class Block {
         * @param $user int User id of user
         * @param $killExpired bool Delete expired blocks on load
         */
-       static function newFromDB( $address, $user = 0, $killExpired = true ) {
+       public static function newFromDB( $address, $user = 0, $killExpired = true ) {
                $block = new Block;
                $block->load( $address, $user, $killExpired );
                if ( $block->isValid() ) {
@@ -76,7 +76,7 @@ class Block {
         * @return Block object
         * @param $id int Block id to search for
         */
-       static function newFromID( $id ) {
+       public static function newFromID( $id ) {
                $dbr = wfGetDB( DB_SLAVE );
                $res = $dbr->resultObject( $dbr->select( 'ipblocks', '*',
                        array( 'ipb_id' => $id ), __METHOD__ ) );
@@ -87,12 +87,32 @@ class Block {
                        return null;
                }
        }
+       
+       /**
+        * Check if two blocks are effectively equal
+        *
+        * @return bool
+        */
+       public function equals( Block $block ) {
+               return ( 
+                       $this->mAddress == $block->mAddress
+                       && $this->mUser == $block->mUser
+                       && $this->mAuto == $block->mAuto
+                       && $this->mAnonOnly == $block->mAnonOnly
+                       && $this->mCreateAccount == $block->mCreateAccount
+                       && $this->mExpiry == $block->mExpiry
+                       && $this->mEnableAutoblock == $block->mEnableAutoblock
+                       && $this->mHideName == $block->mHideName
+                       && $this->mBlockEmail == $block->mBlockEmail
+                       && $this->mAllowUsertalk == $block->mAllowUsertalk
+               );
+       }
 
        /**
         * Clear all member variables in the current object. Does not clear
         * the block from the DB.
         */
-       function clear() {
+       public function clear() {
                $this->mAddress = $this->mReason = $this->mTimestamp = '';
                $this->mId = $this->mAnonOnly = $this->mCreateAccount =
                        $this->mEnableAutoblock = $this->mAuto = $this->mUser =
@@ -132,7 +152,7 @@ class Block {
         * @return bool The user is blocked from editing
         *
         */
-       function load( $address = '', $user = 0, $killExpired = true ) {
+       public function load( $address = '', $user = 0, $killExpired = true ) {
                wfDebug( "Block::load: '$address', '$user', $killExpired\n" );
 
                $options = array();
@@ -870,7 +890,6 @@ class Block {
         * @return string
         */
        static function formatExpiry( $encoded_expiry ) {
-       
                static $msg = null;
                
                if( is_null( $msg ) ) {
index 7b96c40..4d82997 100644 (file)
@@ -270,29 +270,18 @@ class IPBlockForm {
                                </tr>"
                        );
                }
-               if ( $alreadyBlocked ) {
-                       $wgOut->addHTML("
-                               <tr id='wpChangeBlockRow'>
-                                       <td>&nbsp;</td>
-                                       <td class='mw-input'>" .
-                                               Xml::checkLabel( wfMsg( 'ipb-change-block' ),
-                                                       'wpChangeBlock', 'wpChangeBlock', $this->BlockReblock,
-                                                       array( 'tabindex' => '13' ) ) . "
-                                       </td>
-                               </tr>"
-                       );
-               }
 
                $wgOut->addHTML("
                        <tr>
                                <td style='padding-top: 1em'>&nbsp;</td>
                                <td  class='mw-submit' style='padding-top: 1em'>" .
-                                       Xml::submitButton( wfMsg( 'ipbsubmit' ),
+                                       Xml::submitButton( wfMsg( $alreadyBlocked ? 'ipb-change-block' : 'ipbsubmit' ),
                                                array( 'name' => 'wpBlock', 'tabindex' => '13', 'accesskey' => 's' ) ) . "
                                </td>
                        </tr>" .
                        Xml::closeElement( 'table' ) .
                        Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
+                       ( $alreadyBlocked ? Xml::hidden( 'wpChangeBlock', 1 ) : "" ) .
                        Xml::closeElement( 'fieldset' ) .
                        Xml::closeElement( 'form' ) .
                        Xml::tags( 'script', array( 'type' => 'text/javascript' ), 'updateBlockOptions()' ) . "\n"
@@ -410,8 +399,12 @@ class IPBlockForm {
                                if ( !$this->BlockReblock ) {
                                        return array( 'ipb_already_blocked' );
                                } else {
-                                       # This returns direct blocks before autoblocks/rangeblocks, since we should be sure the user is blocked by now it should work for our purposes
+                                       # This returns direct blocks before autoblocks/rangeblocks, since we should
+                                       # be sure the user is blocked by now it should work for our purposes
                                        $currentBlock = Block::newFromDB( $this->BlockAddress, $userId );
+                                       if( $block->equals( $currentBlock ) ) {
+                                               return array( 'ipb_already_blocked' );
+                                       }
                                        $currentBlock->delete();
                                        $block->insert();
                                        $log_action = 'reblock';