From fea912acf25f35b96fa43c7ccb18290ffeed4767 Mon Sep 17 00:00:00 2001 From: Happy-melon Date: Wed, 30 Mar 2011 18:00:11 +0000 Subject: [PATCH] (bug 23408) give admins a warning before letting them block themselves. Also tweak the logic so that loading the interface for one already-blocked user, then actually submitting a block on a different user, shows the confirmation again if the second user is already blocked. --- includes/specials/SpecialBlock.php | 16 ++++++++++++++-- languages/messages/MessagesEn.php | 1 + maintenance/language/messages.inc | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/includes/specials/SpecialBlock.php b/includes/specials/SpecialBlock.php index 92658e03eb..48ec00c149 100644 --- a/includes/specials/SpecialBlock.php +++ b/includes/specials/SpecialBlock.php @@ -221,7 +221,7 @@ class SpecialBlock extends SpecialPage { $fields['DisableUTEdit']['default'] = $block->prevents( 'editownusertalk' ); } $fields['Reason']['default'] = $block->mReason; - $fields['AlreadyBlocked']['default'] = true; + $fields['AlreadyBlocked']['default'] = htmlspecialchars( $block->getTarget() ); if( $block->mExpiry == 'infinity' ) { $fields['Expiry']['default'] = 'indefinite'; @@ -486,11 +486,23 @@ class SpecialBlock extends SpecialPage { $user = $target; $target = $user->getName(); $userId = $user->getId(); + + # Give admins a heads-up before they go and block themselves. Much messier + # to do this for IPs, but it's pretty unlikely they'd ever get the 'block' + # permission anyway, although the code does allow for it + if( $target == $wgUser->getName() + && $data['AlreadyBlocked'] != htmlspecialchars( $wgUser->getName() ) ) + { + return array( 'ipb-blockingself' ); + } + } elseif( $type == Block::TYPE_RANGE ){ $userId = 0; + } elseif( $type == Block::TYPE_IP ){ $target = $target->getName(); $userId = 0; + } else { # This should have been caught in the form field validation return array( 'badipaddress' ); @@ -556,7 +568,7 @@ class SpecialBlock extends SpecialPage { $status = $block->insert(); if( !$status ) { # Show form unless the user is already aware of this... - if( !$data['AlreadyBlocked'] ) { + if( $data['AlreadyBlocked'] != htmlspecialchars( $block->getTarget() ) ) { return array( array( 'ipb_already_blocked', $block->getTarget() ) ); # Otherwise, try to update the block... } else { diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index b671331f86..46164d6019 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -3060,6 +3060,7 @@ Fill in a specific reason below (for example, citing particular pages that were 'blockipsuccesssub' => 'Block succeeded', 'blockipsuccesstext' => '[[Special:Contributions/$1|$1]] has been blocked.
See [[Special:IPBlockList|IP block list]] to review blocks.', +'ipb-blockingself' => 'You are about to block yourself! Are you sure you want to do that?', 'ipb-edit-dropdown' => 'Edit block reasons', 'ipb-unblock-addr' => 'Unblock $1', 'ipb-unblock' => 'Unblock a username or IP address', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 6b025ee379..e942c45e69 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -2073,6 +2073,7 @@ $wgMessageStructure = array( 'badipaddress', 'blockipsuccesssub', 'blockipsuccesstext', + 'ipb-blockingself', 'ipb-edit-dropdown', 'ipb-unblock-addr', 'ipb-unblock', -- 2.20.1