From c0bb3a6e2b2e85dc33dfa855598e8b8a789f1ed9 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sat, 8 Oct 2011 20:22:53 +0000 Subject: [PATCH] * Only spread blocks on page edit/move attempts via spreadAnyEditBlock(). We don't want to spread everytime the user's block status is checked as the user may just be viewing something rather than attempting to do anything. For example, if the 'edit' tab were changed to reflect block status, the autoblocks would trigger by a user just *looking* at the page. An example "in the wild" would be the UI checks in r93246. * Made spreadBlock() protected, no outside callers. --- includes/EditPage.php | 3 +++ includes/User.php | 28 ++++++++++++++++++--------- includes/specials/SpecialMovepage.php | 2 ++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 6714e0f047..e5b0fbf072 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -405,6 +405,9 @@ class EditPage { $permErrors = $this->getEditPermissionErrors(); if ( $permErrors ) { + // Auto-block user's IP if the account was "hard" blocked + $wgUser->spreadAnyEditBlock(); + wfDebug( __METHOD__ . ": User can't edit\n" ); $content = $this->getContent( null ); $content = $content === '' ? null : $content; diff --git a/includes/User.php b/includes/User.php index 455c99018a..37106941e7 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1284,9 +1284,6 @@ class User { $this->mBlockreason = $this->mBlock->mReason; $this->mHideName = $this->mBlock->mHideName; $this->mAllowUsertalk = !$this->mBlock->prevents( 'editownusertalk' ); - if ( $this->isLoggedIn() && $wgUser->getID() == $this->getID() ) { - $this->spreadBlock(); - } } # Proxy blocking @@ -2940,22 +2937,35 @@ class User { } /** - * If this (non-anonymous) user is blocked, block any IP address - * they've successfully logged in from. + * If this user is logged-in and blocked, + * block any IP address they've successfully logged in from. + * @return bool A block was spread */ - public function spreadBlock() { + public function spreadAnyEditBlock() { + if ( $this->isLoggedIn() && $this->isBlocked() ) { + return $this->spreadBlock(); + } + return false; + } + + /** + * If this (non-anonymous) user is blocked, + * block the IP address they've successfully logged in from. + * @return bool A block was spread + */ + protected function spreadBlock() { wfDebug( __METHOD__ . "()\n" ); $this->load(); if ( $this->mId == 0 ) { - return; + return false; } $userblock = Block::newFromTarget( $this->getName() ); if ( !$userblock ) { - return; + return false; } - $userblock->doAutoblock( $this->getRequest()->getIP() ); + return (bool)$userblock->doAutoblock( $this->getRequest()->getIP() ); } /** diff --git a/includes/specials/SpecialMovepage.php b/includes/specials/SpecialMovepage.php index f4cc150c67..8b52fd83da 100644 --- a/includes/specials/SpecialMovepage.php +++ b/includes/specials/SpecialMovepage.php @@ -72,6 +72,8 @@ class MovePageForm extends UnlistedSpecialPage { # Check rights $permErrors = $this->oldTitle->getUserPermissionsErrors( 'move', $user ); if( !empty( $permErrors ) ) { + // Auto-block user's IP if the account was "hard" blocked + $user->spreadAnyEditBlock(); $this->getOutput()->showPermissionsErrorPage( $permErrors ); return; } -- 2.20.1