r42843 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r42842 | r42843 (on ViewVC) | r42844 >
Date:21:45, 30 October 2008
Author:mrzman
Status:resolved (Comments)
Tags:
Comment:(bug 10080) (bug 15820) - Allow modification of blocks without unblocking, and show a notice if the user is already blocked when first visiting the form (if a user is specified).
Modified paths:

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
===================================================================
--- trunk/phase3/maintenance/language/messages.inc	(revision 42842)
+++ trunk/phase3/maintenance/language/messages.inc	(revision 42843)
@@ -1745,6 +1745,7 @@
 		'ipbhidename',
 		'ipbwatchuser',
 		'ipballowusertalk',
+		'ipb-change-block',
 		'badipaddress',
 		'blockipsuccesssub',
 		'blockipsuccesstext',
@@ -1784,6 +1785,7 @@
 		'blocklogpage',
 		'blocklog-fulllog',
 		'blocklogentry',
+		'reblock-logentry',
 		'blocklogtext',
 		'unblocklogentry',
 		'block-log-flags-anononly',
@@ -1796,6 +1798,7 @@
 		'ipb_expiry_invalid',
 		'ipb_expiry_temp',
 		'ipb_already_blocked',
+		'ipb-needreblock',
 		'ipb_cant_unblock',
 		'ipb_blocked_as_range',
 		'ip_range_invalid',
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 42842)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 42843)
@@ -2762,6 +2762,7 @@
 $wgLogActions = array(
 	'block/block'       => 'blocklogentry',
 	'block/unblock'     => 'unblocklogentry',
+	'block/reblock'     => 'reblock-logentry',
 	'protect/protect'   => 'protectedarticle',
 	'protect/modify'    => 'modifiedarticleprotection',
 	'protect/unprotect' => 'unprotectedarticle',
Index: trunk/phase3/includes/specials/SpecialBlockip.php
===================================================================
--- trunk/phase3/includes/specials/SpecialBlockip.php	(revision 42842)
+++ trunk/phase3/includes/specials/SpecialBlockip.php	(revision 42843)
@@ -67,6 +67,7 @@
 		# Re-check user's rights to hide names, very serious, defaults to 0
 		$this->BlockHideName = ( $wgRequest->getBool( 'wpHideName', 0 ) && $wgUser->isAllowed( 'hideuser' ) ) ? 1 : 0;
 		$this->BlockAllowUsertalk = ( $wgRequest->getBool( 'wpAllowUsertalk', $byDefault ) && $wgBlockAllowsUTEdit );
+		$this->BlockReblock = $wgRequest->getBool( 'wpChangeBlock', false );
 	}
 
 	function showForm( $err ) {
@@ -86,10 +87,19 @@
 		$mIpbreason = Xml::label( wfMsg( 'ipbotherreason' ), 'mw-bi-reason' );
 
 		$titleObj = SpecialPage::getTitleFor( 'Blockip' );
-
-		if ( "" != $err ) {
+		
+		$alreadyBlocked = false;
+		if ( $err && $err[0] != 'ipb_already_blocked' ) {
+			$key = array_shift($err);
+			$msg = wfMsgReal($key, $err);
 			$wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
-			$wgOut->addHTML( Xml::tags( 'p', array( 'class' => 'error' ), $err ) );
+			$wgOut->addHTML( Xml::tags( 'p', array( 'class' => 'error' ), $msg ) );
+		} elseif ( $this->BlockAddress ) {
+			$currentBlock = Block::newFromDB( $this->BlockAddress );
+			if ( !is_null($currentBlock) && !$currentBlock->mAuto && !($currentBlock->mRangeStart && $currentBlock->mAddress != $this->BlockAddress) ) {
+				$wgOut->addWikiMsg( 'ipb-needreblock', $this->BlockAddress );
+				$alreadyBlocked = true;
+			}
 		}
 
 		$scBlockExpiryOptions = wfMsgForContent( 'ipboptions' );
@@ -253,6 +263,18 @@
 				</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>
@@ -379,9 +401,18 @@
 		if ( wfRunHooks('BlockIp', array(&$block, &$wgUser)) ) {
 
 			if ( !$block->insert() ) {
-				return array('ipb_already_blocked', htmlspecialchars($this->BlockAddress));
+				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
+					$currentBlock = Block::newFromDB( $this->BlockAddress );
+					$currentBlock->delete();
+					$block->insert();
+					$log_action = 'reblock';
+				}
+			} else {
+				$log_action = 'block';
 			}
-
 			wfRunHooks('BlockIpComplete', array($block, $wgUser));
 
 			if ( $this->BlockWatchUser ) { 
@@ -396,7 +427,7 @@
 			# Make log entry, if the name is hidden, put it in the oversight log
 			$log_type = ($this->BlockHideName) ? 'suppress' : 'block';
 			$log = new LogPage( $log_type );
-			$log->addEntry( 'block', Title::makeTitle( NS_USER, $this->BlockAddress ),
+			$log->addEntry( $log_action, Title::makeTitle( NS_USER, $this->BlockAddress ),
 			  $reasonstr, $logParams );
 
 			# Report to the user
@@ -420,8 +451,7 @@
 				urlencode( $this->BlockAddress ) ) );
 			return;
 		}
-		$key = array_shift($retval);
-		$this->showForm(wfMsgReal($key, $retval));
+		$this->showForm( $retval );
 	}
 
 	function showSuccess() {
Index: trunk/phase3/includes/LogPage.php
===================================================================
--- trunk/phase3/includes/LogPage.php	(revision 42842)
+++ trunk/phase3/includes/LogPage.php	(revision 42843)
@@ -196,7 +196,7 @@
 				} else {
 					$details = '';
 					array_unshift( $params, $titleLink );
-					if ( $key == 'block/block' || $key == 'suppress/block' ) {
+					if ( $key == 'block/block' || $key == 'suppress/block' || $key == 'block/reblock' ) {
 						if ( $skin ) {
 							$params[1] = '<span title="' . htmlspecialchars( $params[1] ). '">' . 
 								$wgLang->translateBlockExpiry( $params[1] ) . '</span>';
Index: trunk/phase3/languages/messages/MessagesEn.php
===================================================================
--- trunk/phase3/languages/messages/MessagesEn.php	(revision 42842)
+++ trunk/phase3/languages/messages/MessagesEn.php	(revision 42843)
@@ -2552,6 +2552,7 @@
 'ipbhidename'                     => 'Hide username from the block log, active block list and user list',
 'ipbwatchuser'                    => "Watch this user's user and talk pages",
 'ipballowusertalk'                => 'Allow this user to edit own talk page while blocked',
+'ipb-change-block'                => 'Re-block the user with these settings',
 'badipaddress'                    => 'Invalid IP address',
 'blockipsuccesssub'               => 'Block succeeded',
 'blockipsuccesstext'              => '[[Special:Contributions/$1|$1]] has been blocked.<br />
@@ -2593,6 +2594,7 @@
 'blocklogpage'                    => 'Block log',
 'blocklog-fulllog'                => 'Full block log',
 'blocklogentry'                   => 'blocked [[$1]] with an expiry time of $2 $3',
+'reblock-logentry'                => 'changed block settings for [[$1]] with an expiry time of $2 $3',
 'blocklogtext'                    => 'This is a log of user blocking and unblocking actions.
 Automatically blocked IP addresses are not listed.
 See the [[Special:IPBlockList|IP block list]] for the list of currently operational bans and blocks.',
@@ -2607,6 +2609,8 @@
 'ipb_expiry_invalid'              => 'Expiry time invalid.',
 'ipb_expiry_temp'                 => 'Hidden username blocks must be permanent.',
 'ipb_already_blocked'             => '"$1" is already blocked',
+'ipb-needreblock'                 => '== Already blocked ==
+$1 is already blocked. Do you want to change the settings?',
 'ipb_cant_unblock'                => 'Error: Block ID $1 not found.
 It may have been unblocked already.',
 'ipb_blocked_as_range'            => 'Error: The IP $1 is not blocked directly and cannot be unblocked.
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 42842)
+++ trunk/phase3/RELEASE-NOTES	(revision 42843)
@@ -179,6 +179,9 @@
 * Make search matches bold only, not red as well
 * Added 'UserRights::showEditUserGroupsForm' hook to allow extensions to alter
   the groups that the user can be added to or removed from in Special:UserRights
+* (bug 10080) Blocks can be modified without unblocking first
+* (bug 15820) Special:BlockIP shows a notice if the user being blocked is already
+  directly blocked
 
 === Bug fixes in 1.14 ===
 

Follow-up revisions

RevisionCommit summaryAuthorDate
r43006pass user ID to Block::newFromDB in case of renames per comments on r42843.mrzman18:15, 1 November 2008
r43677API: Make reblocking (introduced in r42843) possible through the APIcatrope15:21, 18 November 2008

Comments

#Comment by Aaron Schulz (Talk | contribs)   16:47, 1 November 2008

This should pass the user ID to newFromDB(), in case of renames.

Also, '!($currentBlock->mRangeStart && $currentBlock->mAddress != $this->BlockAddress)' looks very messy. Perhaps '$block->mRangeStart == $block->mRangeEnd' is better?

#Comment by Mr.Z-man (Talk | contribs)   18:17, 1 November 2008

Changed to pass user ID in r43006.

The point of the '!($currentBlock->mRangeStart && $currentBlock->mAddress != $this->BlockAddress)' is so that it won't pick up rangeblocks, unless we're blocking a range and the exact range we're blocking is already blocked. It returns true if its not a rangeblock or if it is a rangeblock, its the exact range being blocked.

#Comment by Aaron Schulz (Talk | contribs)   19:12, 1 November 2008

Does that actually work? The block.php code for new blocks has:

if ( $this->mUser == 0 ) {

  list( $this->mRangeStart, $this->mRangeEnd ) = IP::parseRange( $this->mAddress );

}

If there is no CIDR, parseRange() returns the end and start value both as the hex of the IP. So it would seem that even single IP blocks have the fields filled. Inspecting my DB data also has them filled for single IP blocks.

#Comment by Mr.Z-man (Talk | contribs)   21:47, 1 November 2008

Rangeblock detection fixed in r43032.

#Comment by Aaron Schulz (Talk | contribs)   15:40, 3 November 2008

Marking resolved.

Views
Toolbox