From 1176cd5ad0513591723b93c7df669949127a54e7 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sun, 23 Nov 2008 09:52:29 +0000 Subject: [PATCH] * I didn't even notice the extra reblock check; merged this into submit button with hidden input. * Break long line * (bug 16436) Don't log if nothing changed --- includes/Block.php | 29 +++++++++++++++++++++++----- includes/specials/SpecialBlockip.php | 21 +++++++------------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/includes/Block.php b/includes/Block.php index 5723dc77b2..f62201ad7a 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -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 ) ) { diff --git a/includes/specials/SpecialBlockip.php b/includes/specials/SpecialBlockip.php index 7b96c40c1b..4d82997fdc 100644 --- a/includes/specials/SpecialBlockip.php +++ b/includes/specials/SpecialBlockip.php @@ -270,29 +270,18 @@ class IPBlockForm { " ); } - if ( $alreadyBlocked ) { - $wgOut->addHTML(" - -   - " . - Xml::checkLabel( wfMsg( 'ipb-change-block' ), - 'wpChangeBlock', 'wpChangeBlock', $this->BlockReblock, - array( 'tabindex' => '13' ) ) . " - - " - ); - } $wgOut->addHTML("   " . - Xml::submitButton( wfMsg( 'ipbsubmit' ), + Xml::submitButton( wfMsg( $alreadyBlocked ? 'ipb-change-block' : 'ipbsubmit' ), array( 'name' => 'wpBlock', 'tabindex' => '13', 'accesskey' => 's' ) ) . " " . 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'; -- 2.20.1