r102434 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102433‎ | r102434 | r102435 >
Date:20:05, 8 November 2011
Author:aaron
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.18wmf1/includes/Block.php (modified) (history)
  • /branches/wmf/1.18wmf1/includes/Exception.php (modified) (history)
  • /branches/wmf/1.18wmf1/includes/specials/SpecialUserlogin.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/includes/specials/SpecialUserlogin.php
@@ -907,7 +907,7 @@
908908 'cantcreateaccount-text',
909909 $block->getTarget(),
910910 $block_reason,
911 - $block->getBlocker()->getName()
 911+ $block->getByName()
912912 );
913913
914914 $wgOut->returnToMain( false );
Index: branches/wmf/1.18wmf1/includes/Block.php
@@ -59,7 +59,7 @@
6060 */
6161 function __construct( $address = '', $user = 0, $by = 0, $reason = '',
6262 $timestamp = 0, $auto = 0, $expiry = '', $anonOnly = 0, $createAccount = 0, $enableAutoblock = 0,
63 - $hideName = 0, $blockEmail = 0, $allowUsertalk = 0 )
 63+ $hideName = 0, $blockEmail = 0, $allowUsertalk = 0, $byText = '' )
6464 {
6565 if( $timestamp === 0 ){
6666 $timestamp = wfTimestampNow();
@@ -71,7 +71,11 @@
7272 }
7373
7474 $this->setTarget( $address );
75 - $this->setBlocker( User::newFromID( $by ) );
 75+ if ( $by ) { // local user
 76+ $this->setBlocker( User::newFromID( $by ) );
 77+ } else { // foreign user
 78+ $this->setBlocker( $byText );
 79+ }
7680 $this->mReason = $reason;
7781 $this->mTimestamp = wfTimestamp( TS_MW, $timestamp );
7882 $this->mAuto = $auto;
@@ -345,7 +349,11 @@
346350 */
347351 protected function initFromRow( $row ) {
348352 $this->setTarget( $row->ipb_address );
349 - $this->setBlocker( User::newFromId( $row->ipb_by ) );
 353+ if ( $row->ipb_by ) { // local user
 354+ $this->setBlocker( User::newFromID( $row->ipb_by ) );
 355+ } else { // foreign user
 356+ $this->setBlocker( $row->ipb_by_text );
 357+ }
350358
351359 $this->mReason = $row->ipb_reason;
352360 $this->mTimestamp = wfTimestamp( TS_MW, $row->ipb_timestamp );
@@ -471,8 +479,8 @@
472480 $a = array(
473481 'ipb_address' => (string)$this->target,
474482 'ipb_user' => $this->target instanceof User ? $this->target->getID() : 0,
475 - 'ipb_by' => $this->getBlocker()->getId(),
476 - 'ipb_by_text' => $this->getBlocker()->getName(),
 483+ 'ipb_by' => $this->getBy(),
 484+ 'ipb_by_text' => $this->getByName(),
477485 'ipb_reason' => $this->mReason,
478486 'ipb_timestamp' => $db->timestamp( $this->mTimestamp ),
479487 'ipb_auto' => $this->mAuto,
@@ -761,11 +769,12 @@
762770 /**
763771 * Get the user id of the blocking sysop
764772 *
765 - * @return Integer
 773+ * @return Integer (0 for foreign users)
766774 */
767775 public function getBy() {
768 - return $this->getBlocker() instanceof User
769 - ? $this->getBlocker()->getId()
 776+ $blocker = $this->getBlocker();
 777+ return ( $blocker instanceof User )
 778+ ? $blocker->getId()
770779 : 0;
771780 }
772781
@@ -775,9 +784,10 @@
776785 * @return String
777786 */
778787 public function getByName() {
779 - return $this->getBlocker() instanceof User
780 - ? $this->getBlocker()->getName()
781 - : null;
 788+ $blocker = $this->getBlocker();
 789+ return ( $blocker instanceof User )
 790+ ? $blocker->getName()
 791+ : (string)$blocker; // username
782792 }
783793
784794 /**
@@ -927,7 +937,8 @@
928938 */
929939 public static function purgeExpired() {
930940 $dbw = wfGetDB( DB_MASTER );
931 - $dbw->delete( 'ipblocks', array( 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), __METHOD__ );
 941+ $dbw->delete( 'ipblocks',
 942+ array( 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), __METHOD__ );
932943 }
933944
934945 /**
@@ -1136,7 +1147,7 @@
11371148
11381149 /**
11391150 * Get the user who implemented this block
1140 - * @return User
 1151+ * @return User|string Local User object or string for a foreign user
11411152 */
11421153 public function getBlocker(){
11431154 return $this->blocker;
@@ -1144,9 +1155,9 @@
11451156
11461157 /**
11471158 * Set the user who implemented (or will implement) this block
1148 - * @param $user User
 1159+ * @param $user User|string Local User object or username string for foriegn users
11491160 */
1150 - public function setBlocker( User $user ){
 1161+ public function setBlocker( $user ){
11511162 $this->blocker = $user;
11521163 }
11531164 }
Index: branches/wmf/1.18wmf1/includes/Exception.php
@@ -337,8 +337,13 @@
338338 public function __construct( Block $block ){
339339 global $wgLang;
340340
341 - $blockerUserpage = $block->getBlocker()->getUserPage();
342 - $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]";
 341+ $blocker = $block->getBlocker();
 342+ if ( $blocker instanceof User ) { // local user
 343+ $blockerUserpage = $block->getBlocker()->getUserPage();
 344+ $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]";
 345+ } else { // foreign user
 346+ $link = $blocker;
 347+ }
343348
344349 $reason = $block->mReason;
345350 if( $reason == '' ) {
@@ -356,7 +361,7 @@
357362 $link,
358363 $reason,
359364 wfGetIP(),
360 - $block->getBlocker()->getName(),
 365+ $block->getByName(),
361366 $block->getId(),
362367 $wgLang->formatExpiry( $block->mExpiry ),
363368 $intended,

Sign-offs

UserFlagDate
Brion VIBBERinspected20:37, 8 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r101434Made some callers of getBlocker()->getName() just use getByName()aaron23:37, 31 October 2011
r101442(bug 31739) Made Block code support ipb_by = 0 convention with for foreign us...aaron00:11, 1 November 2011
r101444FR r101442: forgot to replace another getBlocker()->getName() with getByName()aaron00:16, 1 November 2011
r102422Added bug 32198 scriptsaaron19:00, 8 November 2011

Status & tagging log