r101442 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101441‎ | r101442 | r101443 >
Date:00:11, 1 November 2011
Author:aaron
Status:ok (Comments)
Tags:
Comment:
(bug 31739) Made Block code support ipb_by = 0 convention with for foreign users again, as it did pre 1.18. The byText param has been restored in the Block() constructor as CentralAuth still uses it. Some callers have been updated to reflect the fact that getBlocker() may be a local User or a string username.

Ideally, we might have a ForeignUser class and a generic User interface...but this will do for now.
Modified paths:
  • /trunk/phase3/includes/Block.php (modified) (history)
  • /trunk/phase3/includes/Exception.php (modified) (history)

Diff [purge]

Index: trunk/phase3/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 );
@@ -470,8 +478,8 @@
471479 $a = array(
472480 'ipb_address' => (string)$this->target,
473481 'ipb_user' => $this->target instanceof User ? $this->target->getID() : 0,
474 - 'ipb_by' => $this->getBlocker()->getId(),
475 - 'ipb_by_text' => $this->getBlocker()->getName(),
 482+ 'ipb_by' => $this->getBy(),
 483+ 'ipb_by_text' => $this->getByName(),
476484 'ipb_reason' => $this->mReason,
477485 'ipb_timestamp' => $db->timestamp( $this->mTimestamp ),
478486 'ipb_auto' => $this->mAuto,
@@ -760,11 +768,12 @@
761769 /**
762770 * Get the user id of the blocking sysop
763771 *
764 - * @return Integer
 772+ * @return Integer (0 for foreign users)
765773 */
766774 public function getBy() {
767 - return $this->getBlocker() instanceof User
768 - ? $this->getBlocker()->getId()
 775+ $blocker = $this->getBlocker();
 776+ return ( $blocker instanceof User )
 777+ ? $blocker->getId()
769778 : 0;
770779 }
771780
@@ -774,9 +783,10 @@
775784 * @return String
776785 */
777786 public function getByName() {
778 - return $this->getBlocker() instanceof User
779 - ? $this->getBlocker()->getName()
780 - : null;
 787+ $blocker = $this->getBlocker();
 788+ return ( $blocker instanceof User )
 789+ ? $blocker->getName()
 790+ : (string)$blocker; // username
781791 }
782792
783793 /**
@@ -926,7 +936,8 @@
927937 */
928938 public static function purgeExpired() {
929939 $dbw = wfGetDB( DB_MASTER );
930 - $dbw->delete( 'ipblocks', array( 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), __METHOD__ );
 940+ $dbw->delete( 'ipblocks',
 941+ array( 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), __METHOD__ );
931942 }
932943
933944 /**
@@ -1135,7 +1146,7 @@
11361147
11371148 /**
11381149 * Get the user who implemented this block
1139 - * @return User
 1150+ * @return User|string Local User object or string for a foreign user
11401151 */
11411152 public function getBlocker(){
11421153 return $this->blocker;
@@ -1143,9 +1154,9 @@
11441155
11451156 /**
11461157 * Set the user who implemented (or will implement) this block
1147 - * @param $user User
 1158+ * @param $user User|string Local User object or username string for foriegn users
11481159 */
1149 - public function setBlocker( User $user ){
 1160+ public function setBlocker( $user ){
11501161 $this->blocker = $user;
11511162 }
11521163 }
Index: trunk/phase3/includes/Exception.php
@@ -348,8 +348,13 @@
349349 public function __construct( Block $block ){
350350 global $wgLang, $wgRequest;
351351
352 - $blockerUserpage = $block->getBlocker()->getUserPage();
353 - $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]";
 352+ $blocker = $block->getBlocker();
 353+ if ( $blocker instanceof User ) { // local user
 354+ $blockerUserpage = $block->getBlocker()->getUserPage();
 355+ $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]";
 356+ } else { // foreign user
 357+ $link = $blocker;
 358+ }
354359
355360 $reason = $block->mReason;
356361 if( $reason == '' ) {

Sign-offs

UserFlagDate
Brion VIBBERinspected20:37, 8 November 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r101444FR r101442: forgot to replace another getBlocker()->getName() with getByName()aaron00:16, 1 November 2011
r102434MFT r101434,r101442,r101444: fix for bug 32198aaron20:05, 8 November 2011

Comments

#Comment by Aaron Schulz (talk | contribs)   00:12, 1 November 2011

Related: r101434.

#Comment by G.Hagedorn (talk | contribs)   10:03, 9 November 2011

Please consider applying this and the related fixes to 1.18 as well.

Status & tagging log