From 7916d730ae71e08ec0858f5c4cf37e8e23b1b956 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 1 Nov 2011 00:11:53 +0000 Subject: [PATCH] (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. --- includes/Block.php | 41 ++++++++++++++++++++++++++--------------- includes/Exception.php | 9 +++++++-- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/includes/Block.php b/includes/Block.php index ed1a1920fd..3a2fa6eb96 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -59,7 +59,7 @@ class Block { */ function __construct( $address = '', $user = 0, $by = 0, $reason = '', $timestamp = 0, $auto = 0, $expiry = '', $anonOnly = 0, $createAccount = 0, $enableAutoblock = 0, - $hideName = 0, $blockEmail = 0, $allowUsertalk = 0 ) + $hideName = 0, $blockEmail = 0, $allowUsertalk = 0, $byText = '' ) { if( $timestamp === 0 ){ $timestamp = wfTimestampNow(); @@ -71,7 +71,11 @@ class Block { } $this->setTarget( $address ); - $this->setBlocker( User::newFromID( $by ) ); + if ( $by ) { // local user + $this->setBlocker( User::newFromID( $by ) ); + } else { // foreign user + $this->setBlocker( $byText ); + } $this->mReason = $reason; $this->mTimestamp = wfTimestamp( TS_MW, $timestamp ); $this->mAuto = $auto; @@ -345,7 +349,11 @@ class Block { */ protected function initFromRow( $row ) { $this->setTarget( $row->ipb_address ); - $this->setBlocker( User::newFromId( $row->ipb_by ) ); + if ( $row->ipb_by ) { // local user + $this->setBlocker( User::newFromID( $row->ipb_by ) ); + } else { // foreign user + $this->setBlocker( $row->ipb_by_text ); + } $this->mReason = $row->ipb_reason; $this->mTimestamp = wfTimestamp( TS_MW, $row->ipb_timestamp ); @@ -470,8 +478,8 @@ class Block { $a = array( 'ipb_address' => (string)$this->target, 'ipb_user' => $this->target instanceof User ? $this->target->getID() : 0, - 'ipb_by' => $this->getBlocker()->getId(), - 'ipb_by_text' => $this->getBlocker()->getName(), + 'ipb_by' => $this->getBy(), + 'ipb_by_text' => $this->getByName(), 'ipb_reason' => $this->mReason, 'ipb_timestamp' => $db->timestamp( $this->mTimestamp ), 'ipb_auto' => $this->mAuto, @@ -760,11 +768,12 @@ class Block { /** * Get the user id of the blocking sysop * - * @return Integer + * @return Integer (0 for foreign users) */ public function getBy() { - return $this->getBlocker() instanceof User - ? $this->getBlocker()->getId() + $blocker = $this->getBlocker(); + return ( $blocker instanceof User ) + ? $blocker->getId() : 0; } @@ -774,9 +783,10 @@ class Block { * @return String */ public function getByName() { - return $this->getBlocker() instanceof User - ? $this->getBlocker()->getName() - : null; + $blocker = $this->getBlocker(); + return ( $blocker instanceof User ) + ? $blocker->getName() + : (string)$blocker; // username } /** @@ -926,7 +936,8 @@ class Block { */ public static function purgeExpired() { $dbw = wfGetDB( DB_MASTER ); - $dbw->delete( 'ipblocks', array( 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), __METHOD__ ); + $dbw->delete( 'ipblocks', + array( 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ), __METHOD__ ); } /** @@ -1135,7 +1146,7 @@ class Block { /** * Get the user who implemented this block - * @return User + * @return User|string Local User object or string for a foreign user */ public function getBlocker(){ return $this->blocker; @@ -1143,9 +1154,9 @@ class Block { /** * Set the user who implemented (or will implement) this block - * @param $user User + * @param $user User|string Local User object or username string for foriegn users */ - public function setBlocker( User $user ){ + public function setBlocker( $user ){ $this->blocker = $user; } } diff --git a/includes/Exception.php b/includes/Exception.php index b01d0d0e0c..7bc3103a41 100644 --- a/includes/Exception.php +++ b/includes/Exception.php @@ -348,8 +348,13 @@ class UserBlockedError extends ErrorPageError { public function __construct( Block $block ){ global $wgLang, $wgRequest; - $blockerUserpage = $block->getBlocker()->getUserPage(); - $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]"; + $blocker = $block->getBlocker(); + if ( $blocker instanceof User ) { // local user + $blockerUserpage = $block->getBlocker()->getUserPage(); + $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]"; + } else { // foreign user + $link = $blocker; + } $reason = $block->mReason; if( $reason == '' ) { -- 2.20.1