r42843 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42842‎ | r42843 | r42844 >
Date:21:45, 30 October 2008
Author:mrzman
Status:old (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:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/LogPage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialBlockip.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -1745,6 +1745,7 @@
17461746 'ipbhidename',
17471747 'ipbwatchuser',
17481748 'ipballowusertalk',
 1749+ 'ipb-change-block',
17491750 'badipaddress',
17501751 'blockipsuccesssub',
17511752 'blockipsuccesstext',
@@ -1784,6 +1785,7 @@
17851786 'blocklogpage',
17861787 'blocklog-fulllog',
17871788 'blocklogentry',
 1789+ 'reblock-logentry',
17881790 'blocklogtext',
17891791 'unblocklogentry',
17901792 'block-log-flags-anononly',
@@ -1796,6 +1798,7 @@
17971799 'ipb_expiry_invalid',
17981800 'ipb_expiry_temp',
17991801 'ipb_already_blocked',
 1802+ 'ipb-needreblock',
18001803 'ipb_cant_unblock',
18011804 'ipb_blocked_as_range',
18021805 'ip_range_invalid',
Index: trunk/phase3/includes/DefaultSettings.php
@@ -2762,6 +2762,7 @@
27632763 $wgLogActions = array(
27642764 'block/block' => 'blocklogentry',
27652765 'block/unblock' => 'unblocklogentry',
 2766+ 'block/reblock' => 'reblock-logentry',
27662767 'protect/protect' => 'protectedarticle',
27672768 'protect/modify' => 'modifiedarticleprotection',
27682769 'protect/unprotect' => 'unprotectedarticle',
Index: trunk/phase3/includes/LogPage.php
@@ -196,7 +196,7 @@
197197 } else {
198198 $details = '';
199199 array_unshift( $params, $titleLink );
200 - if ( $key == 'block/block' || $key == 'suppress/block' ) {
 200+ if ( $key == 'block/block' || $key == 'suppress/block' || $key == 'block/reblock' ) {
201201 if ( $skin ) {
202202 $params[1] = '<span title="' . htmlspecialchars( $params[1] ). '">' .
203203 $wgLang->translateBlockExpiry( $params[1] ) . '</span>';
Index: trunk/phase3/includes/specials/SpecialBlockip.php
@@ -67,6 +67,7 @@
6868 # Re-check user's rights to hide names, very serious, defaults to 0
6969 $this->BlockHideName = ( $wgRequest->getBool( 'wpHideName', 0 ) && $wgUser->isAllowed( 'hideuser' ) ) ? 1 : 0;
7070 $this->BlockAllowUsertalk = ( $wgRequest->getBool( 'wpAllowUsertalk', $byDefault ) && $wgBlockAllowsUTEdit );
 71+ $this->BlockReblock = $wgRequest->getBool( 'wpChangeBlock', false );
7172 }
7273
7374 function showForm( $err ) {
@@ -86,10 +87,19 @@
8788 $mIpbreason = Xml::label( wfMsg( 'ipbotherreason' ), 'mw-bi-reason' );
8889
8990 $titleObj = SpecialPage::getTitleFor( 'Blockip' );
90 -
91 - if ( "" != $err ) {
 91+
 92+ $alreadyBlocked = false;
 93+ if ( $err && $err[0] != 'ipb_already_blocked' ) {
 94+ $key = array_shift($err);
 95+ $msg = wfMsgReal($key, $err);
9296 $wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
93 - $wgOut->addHTML( Xml::tags( 'p', array( 'class' => 'error' ), $err ) );
 97+ $wgOut->addHTML( Xml::tags( 'p', array( 'class' => 'error' ), $msg ) );
 98+ } elseif ( $this->BlockAddress ) {
 99+ $currentBlock = Block::newFromDB( $this->BlockAddress );
 100+ if ( !is_null($currentBlock) && !$currentBlock->mAuto && !($currentBlock->mRangeStart && $currentBlock->mAddress != $this->BlockAddress) ) {
 101+ $wgOut->addWikiMsg( 'ipb-needreblock', $this->BlockAddress );
 102+ $alreadyBlocked = true;
 103+ }
94104 }
95105
96106 $scBlockExpiryOptions = wfMsgForContent( 'ipboptions' );
@@ -253,6 +263,18 @@
254264 </tr>"
255265 );
256266 }
 267+ if ( $alreadyBlocked ) {
 268+ $wgOut->addHTML("
 269+ <tr id='wpChangeBlockRow'>
 270+ <td>&nbsp;</td>
 271+ <td class='mw-input'>" .
 272+ Xml::checkLabel( wfMsg( 'ipb-change-block' ),
 273+ 'wpChangeBlock', 'wpChangeBlock', $this->BlockReblock,
 274+ array( 'tabindex' => '13' ) ) . "
 275+ </td>
 276+ </tr>"
 277+ );
 278+ }
257279
258280 $wgOut->addHTML("
259281 <tr>
@@ -379,9 +401,18 @@
380402 if ( wfRunHooks('BlockIp', array(&$block, &$wgUser)) ) {
381403
382404 if ( !$block->insert() ) {
383 - return array('ipb_already_blocked', htmlspecialchars($this->BlockAddress));
 405+ if ( !$this->BlockReblock ) {
 406+ return array( 'ipb_already_blocked' );
 407+ } else {
 408+ # This returns direct blocks before autoblocks/rangeblocks, since we should be sure the user is blocked by now it should work for our purposes
 409+ $currentBlock = Block::newFromDB( $this->BlockAddress );
 410+ $currentBlock->delete();
 411+ $block->insert();
 412+ $log_action = 'reblock';
 413+ }
 414+ } else {
 415+ $log_action = 'block';
384416 }
385 -
386417 wfRunHooks('BlockIpComplete', array($block, $wgUser));
387418
388419 if ( $this->BlockWatchUser ) {
@@ -396,7 +427,7 @@
397428 # Make log entry, if the name is hidden, put it in the oversight log
398429 $log_type = ($this->BlockHideName) ? 'suppress' : 'block';
399430 $log = new LogPage( $log_type );
400 - $log->addEntry( 'block', Title::makeTitle( NS_USER, $this->BlockAddress ),
 431+ $log->addEntry( $log_action, Title::makeTitle( NS_USER, $this->BlockAddress ),
401432 $reasonstr, $logParams );
402433
403434 # Report to the user
@@ -420,8 +451,7 @@
421452 urlencode( $this->BlockAddress ) ) );
422453 return;
423454 }
424 - $key = array_shift($retval);
425 - $this->showForm(wfMsgReal($key, $retval));
 455+ $this->showForm( $retval );
426456 }
427457
428458 function showSuccess() {
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2552,6 +2552,7 @@
25532553 'ipbhidename' => 'Hide username from the block log, active block list and user list',
25542554 'ipbwatchuser' => "Watch this user's user and talk pages",
25552555 'ipballowusertalk' => 'Allow this user to edit own talk page while blocked',
 2556+'ipb-change-block' => 'Re-block the user with these settings',
25562557 'badipaddress' => 'Invalid IP address',
25572558 'blockipsuccesssub' => 'Block succeeded',
25582559 'blockipsuccesstext' => '[[Special:Contributions/$1|$1]] has been blocked.<br />
@@ -2593,6 +2594,7 @@
25942595 'blocklogpage' => 'Block log',
25952596 'blocklog-fulllog' => 'Full block log',
25962597 'blocklogentry' => 'blocked [[$1]] with an expiry time of $2 $3',
 2598+'reblock-logentry' => 'changed block settings for [[$1]] with an expiry time of $2 $3',
25972599 'blocklogtext' => 'This is a log of user blocking and unblocking actions.
25982600 Automatically blocked IP addresses are not listed.
25992601 See the [[Special:IPBlockList|IP block list]] for the list of currently operational bans and blocks.',
@@ -2607,6 +2609,8 @@
26082610 'ipb_expiry_invalid' => 'Expiry time invalid.',
26092611 'ipb_expiry_temp' => 'Hidden username blocks must be permanent.',
26102612 'ipb_already_blocked' => '"$1" is already blocked',
 2613+'ipb-needreblock' => '== Already blocked ==
 2614+$1 is already blocked. Do you want to change the settings?',
26112615 'ipb_cant_unblock' => 'Error: Block ID $1 not found.
26122616 It may have been unblocked already.',
26132617 'ipb_blocked_as_range' => 'Error: The IP $1 is not blocked directly and cannot be unblocked.
Index: trunk/phase3/RELEASE-NOTES
@@ -179,6 +179,9 @@
180180 * Make search matches bold only, not red as well
181181 * Added 'UserRights::showEditUserGroupsForm' hook to allow extensions to alter
182182 the groups that the user can be added to or removed from in Special:UserRights
 183+* (bug 10080) Blocks can be modified without unblocking first
 184+* (bug 15820) Special:BlockIP shows a notice if the user being blocked is already
 185+ directly blocked
183186
184187 === Bug fixes in 1.14 ===
185188

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 API...catrope15:21, 18 November 2008

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r35901Bug 10080 - Sysops can now modify a block without unblocking first. Patch by ...demon00:11, 5 June 2008
r36076Bug 10080 - Finally fixed. No longer mis-detects an individual IP as blocked ...demon13:03, 9 June 2008
r36109Alrighty, now we properly remove old blocks before inserting the new one. (Bu...demon22:03, 9 June 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.

Status & tagging log