From bd8da57b32aa680fa76caad9317440791bfde836 Mon Sep 17 00:00:00 2001 From: Happy-melon Date: Tue, 26 Jul 2011 19:58:26 +0000 Subject: [PATCH] Follow-up r93234: use User::getBlock() accessor rather than accessing $mBlock directly. Also fixes r85951 CR, and remove code duplication in Title::checkUserBlock(). --- includes/Action.php | 3 +- includes/OutputPage.php | 2 +- includes/SpecialPage.php | 3 +- includes/Title.php | 38 ++++---------------------- includes/User.php | 13 +++++---- includes/specials/SpecialEmailuser.php | 2 +- includes/specials/SpecialUserlogin.php | 2 +- 7 files changed, 17 insertions(+), 46 deletions(-) diff --git a/includes/Action.php b/includes/Action.php index ff0ce697d0..6a62fb69db 100644 --- a/includes/Action.php +++ b/includes/Action.php @@ -198,8 +198,7 @@ abstract class Action { } if ( $this->requiresUnblock() && $user->isBlocked() ) { - $block = $user->mBlock; - throw new UserBlockedError( $block ); + throw new UserBlockedError( $user->getBlock() ); } } diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 9db347a9fa..fb7f67ef3e 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1934,7 +1934,7 @@ class OutputPage { * @deprecated since 1.18 */ function blockedPage() { - throw new UserBlockedError( $this->getUser()->mBlock ); + throw new UserBlockedError( $this->getUser()->getBlock() ); } /** diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index a91b587646..adb408ebad 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -825,8 +825,7 @@ abstract class FormSpecialPage extends SpecialPage { } if ( $this->requiresUnblock() && $user->isBlocked() ) { - $block = $user->mBlock; - throw new UserBlockedError( $block ); + throw new UserBlockedError( $user->getBlock() ); } return true; diff --git a/includes/Title.php b/includes/Title.php index a774404f28..76519d0a33 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1565,39 +1565,11 @@ class Title { } elseif( ( $action == 'edit' || $action == 'create' ) && !$user->isBlockedFrom( $this ) ){ // Don't block the user from editing their own talk page unless they've been // explicitly blocked from that too. - } elseif( $user->isBlocked() && $user->mBlock->prevents( $action ) !== false ) { - $block = $user->mBlock; - - // This is from OutputPage::blockedPage - // Copied at r23888 by werdna - - $id = $user->blockedBy(); - $reason = $user->blockedFor(); - if ( $reason == '' ) { - $reason = wfMsg( 'blockednoreason' ); - } - $ip = wfGetIP(); - - if ( is_numeric( $id ) ) { - $name = User::whoIs( $id ); - } else { - $name = $id; - } - - $link = '[[' . $wgContLang->getNsText( NS_USER ) . ":{$name}|{$name}]]"; - $blockid = $block->getId(); - $blockExpiry = $user->mBlock->mExpiry; - $blockTimestamp = $wgLang->timeanddate( wfTimestamp( TS_MW, $user->mBlock->mTimestamp ), true ); - if ( $blockExpiry == 'infinity' ) { - $blockExpiry = wfMessage( 'infiniteblock' )->text(); - } else { - $blockExpiry = $wgLang->timeanddate( wfTimestamp( TS_MW, $blockExpiry ), true ); - } - - $intended = strval( $user->mBlock->getTarget() ); - - $errors[] = array( ( $block->mAuto ? 'autoblockedtext' : 'blockedtext' ), $link, $reason, $ip, $name, - $blockid, $blockExpiry, $intended, $blockTimestamp ); + } elseif( $user->isBlocked() && $user->getBlock()->prevents( $action ) !== false ) { + $e = new UserBlockedError( $user->getBlock() ); + $params = $e->params; + array_unshift( $params, $e->msg ); + $errors[] = $params; } return $errors; diff --git a/includes/User.php b/includes/User.php index a160e93a0d..4d9b4c74c0 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1265,13 +1265,14 @@ class User { } # User/IP blocking - $this->mBlock = Block::newFromTarget( $this->getName(), $ip, !$bFromSlave ); - if ( $this->mBlock instanceof Block ) { + $block = Block::newFromTarget( $this->getName(), $ip, !$bFromSlave ); + if ( $block instanceof Block ) { wfDebug( __METHOD__ . ": Found block.\n" ); - $this->mBlockedby = $this->mBlock->getByName(); - $this->mBlockreason = $this->mBlock->mReason; - $this->mHideName = $this->mBlock->mHideName; - $this->mAllowUsertalk = !$this->mBlock->prevents( 'editownusertalk' ); + $this->mBlock = $block; + $this->mBlockedby = $block->getByName(); + $this->mBlockreason = $block->mReason; + $this->mHideName = $block->mHideName; + $this->mAllowUsertalk = !$block->prevents( 'editownusertalk' ); if ( $this->isLoggedIn() && $wgUser->getID() == $this->getID() ) { $this->spreadBlock(); } diff --git a/includes/specials/SpecialEmailuser.php b/includes/specials/SpecialEmailuser.php index 52501e4948..509f7fc680 100644 --- a/includes/specials/SpecialEmailuser.php +++ b/includes/specials/SpecialEmailuser.php @@ -99,7 +99,7 @@ class SpecialEmailUser extends UnlistedSpecialPage { case 'badaccess': throw new PermissionsError( 'sendemail' ); case 'blockedemailuser': - throw new UserBlockedError( $this->getUser()->mBlock ); + throw new UserBlockedError( $this->getUser()->getBlock() ); case 'actionthrottledtext': throw new ThrottledError; case 'mailnologin': diff --git a/includes/specials/SpecialUserlogin.php b/includes/specials/SpecialUserlogin.php index a933041270..bed5a14f1a 100644 --- a/includes/specials/SpecialUserlogin.php +++ b/includes/specials/SpecialUserlogin.php @@ -746,7 +746,7 @@ class LoginForm extends SpecialPage { $this->resetLoginForm( wfMsg( 'resetpass_announce' ) ); break; case self::CREATE_BLOCKED: - $this->userBlockedMessage( $wgUser->mBlock ); + $this->userBlockedMessage( $wgUser->getBlock() ); break; case self::THROTTLED: $this->mainLoginForm( wfMsg( 'login-throttled' ) ); -- 2.20.1