r49685 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49684‎ | r49685 | r49686 >
Date:04:43, 21 April 2009
Author:aaron
Status:ok (Comments)
Tags:
Comment:
* Fixed unblocking of hidden names (bug 18543)
* Added permission check
Modified paths:
  • /trunk/phase3/includes/specials/SpecialBlockip.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialIpblocklist.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialIpblocklist.php
@@ -162,7 +162,7 @@
163163 * @return array array(message key, parameters) on failure, empty array on success
164164 */
165165
166 - static function doUnblock(&$id, &$ip, &$reason, &$range = null) {
 166+ static function doUnblock(&$id, &$ip, &$reason, &$range = null, $blocker=null) {
167167 if ( $id ) {
168168 $block = Block::newFromID( $id );
169169 if ( !$block ) {
@@ -184,8 +184,7 @@
185185 if ( !$block ) {
186186 return array('ipb_cant_unblock', htmlspecialchars($id));
187187 }
188 - if( $block->mRangeStart != $block->mRangeEnd
189 - && !strstr( $ip, "/" ) ) {
 188+ if( $block->mRangeStart != $block->mRangeEnd && !strstr( $ip, "/" ) ) {
190189 /* If the specified IP is a single address, and the block is
191190 * a range block, don't unblock the range. */
192191 $range = $block->mAddress;
@@ -195,11 +194,22 @@
196195 }
197196 // Yes, this is really necessary
198197 $id = $block->mId;
 198+
 199+ # If the name was hidden and the blocking user cannot hide
 200+ # names, then don't allow any block removals...
 201+ if( $blocker && $block->mHideName && !$blocker->isAllowed('hideuser') ) {
 202+ return array('ipb_cant_unblock', htmlspecialchars($id));
 203+ }
199204
200205 # Delete block
201206 if ( !$block->delete() ) {
202207 return array('ipb_cant_unblock', htmlspecialchars($id));
203208 }
 209+
 210+ # Unset _deleted fields as needed
 211+ if( $block->mHideName ) {
 212+ IPBlockForm::unsuppressUserName( $block->mAddress, $block->mUser );
 213+ }
204214
205215 # Make log entry
206216 $log = new LogPage( 'block' );
@@ -208,10 +218,9 @@
209219 }
210220
211221 function doSubmit() {
212 - global $wgOut;
213 - $retval = self::doUnblock($this->id, $this->ip, $this->reason, $range);
214 - if(!empty($retval))
215 - {
 222+ global $wgOut, $wgUser;
 223+ $retval = self::doUnblock($this->id, $this->ip, $this->reason, $range, $wgUser);
 224+ if( !empty($retval) ) {
216225 $key = array_shift($retval);
217226 $this->showForm(wfMsgReal($key, $retval));
218227 return;
Index: trunk/phase3/includes/specials/SpecialBlockip.php
@@ -445,7 +445,7 @@
446446 $log_action = 'reblock';
447447 # Unset _deleted fields if requested
448448 if( $currentBlock->mHideName && !$this->BlockHideName ) {
449 - $this->unsuppressUserName( $this->BlockAddress, $userId );
 449+ self::unsuppressUserName( $this->BlockAddress, $userId );
450450 }
451451 }
452452 } else {
@@ -455,7 +455,7 @@
456456
457457 # Set *_deleted fields if requested
458458 if( $this->BlockHideName ) {
459 - $this->suppressUserName( $this->BlockAddress, $userId );
 459+ self::suppressUserName( $this->BlockAddress, $userId );
460460 }
461461
462462 if ( $this->BlockWatchUser &&
@@ -486,17 +486,17 @@
487487 }
488488 }
489489
490 - private function suppressUserName( $name, $userId ) {
 490+ public static function suppressUserName( $name, $userId ) {
491491 $op = '|'; // bitwise OR
492 - return $this->setUsernameBitfields( $name, $userId, $op );
 492+ return self::setUsernameBitfields( $name, $userId, $op );
493493 }
494494
495 - private function unsuppressUserName( $name, $userId ) {
 495+ public static function unsuppressUserName( $name, $userId ) {
496496 $op = '&'; // bitwise AND
497 - return $this->setUsernameBitfields( $name, $userId, $op );
 497+ return self::setUsernameBitfields( $name, $userId, $op );
498498 }
499499
500 - private function setUsernameBitfields( $name, $userId, $op ) {
 500+ private static function setUsernameBitfields( $name, $userId, $op ) {
501501 if( $op !== '|' && $op !== '&' ) return false; // sanity check
502502 $dbw = wfGetDB( DB_MASTER );
503503 $delUser = Revision::DELETED_USER | Revision::DELETED_RESTRICTED;
@@ -509,8 +509,10 @@
510510 # current bitfields with the inverse of Revision::DELETED_USER. The
511511 # username bit is made to 0 (x & 0 = 0), while others are unchanged (x & 1 = x).
512512 # The same goes for the sysop-restricted *_deleted bit.
513 - if( $op == '&' ) $delUser = "~{$delUser}";
514 - if( $op == '&' ) $delAction = "~{$delAction}";
 513+ if( $op == '&' ) {
 514+ $delUser = "~{$delUser}";
 515+ $delAction = "~{$delAction}";
 516+ }
515517 # Hide name from live edits
516518 $dbw->update( 'revision', array("rev_deleted = rev_deleted $op $delUser"),
517519 array('rev_user' => $userId), __METHOD__ );

Follow-up revisions

RevisionCommit summaryAuthorDate
r50162Backports for the hide user feature:...tstarling07:58, 4 May 2009

Comments

#Comment by Werdna (talk | contribs)   05:05, 21 April 2009

$blocker is a poor name for that variable. Otherwise seems ok to deploy (which I've done).

Status & tagging log