Follow-up r85025: fix the you're-trying-to-block-yourself-you-twit warning, and make...
authorHappy-melon <happy-melon@users.mediawiki.org>
Fri, 1 Apr 2011 23:13:15 +0000 (23:13 +0000)
committerHappy-melon <happy-melon@users.mediawiki.org>
Fri, 1 Apr 2011 23:13:15 +0000 (23:13 +0000)
includes/HTMLForm.php
includes/specials/SpecialBlock.php
languages/messages/MessagesEn.php
maintenance/language/messages.inc

index 58c8bbf..d8d83e8 100644 (file)
@@ -522,7 +522,7 @@ class HTMLForm {
         * @param $errors Array of message keys/values
         * @return String HTML, a <ul> list of errors
         */
-       static function formatErrors( $errors ) {
+       public static function formatErrors( $errors ) {
                $errorstr = '';
 
                foreach ( $errors as $error ) {
index fc97c01..a721ab6 100644 (file)
@@ -40,8 +40,17 @@ class SpecialBlock extends SpecialPage {
        /// @var Block::TYPE_ constant
        protected $type;
 
+       /// @var  User|String the previous block target
+       protected $previousTarget;
+
+       /// @var Bool whether the previous submission of the form asked for HideUser
+       protected $requestedHideUser;
+
        /// @var Bool
        protected $alreadyBlocked;
+       
+       /// @var Array
+       protected $preErrors = array();
 
        public function __construct() {
                parent::__construct( 'Block', 'block' );
@@ -71,6 +80,9 @@ class SpecialBlock extends SpecialPage {
                        $wgUser->getSkin()->setRelevantUser( $this->target );
                }
 
+               list( $this->previousTarget, /*...*/ ) = Block::parseTarget( $wgRequest->getVal( 'wpPreviousTarget' ) );
+               $this->requestedHideUser = $wgRequest->getBool( 'wpHideUser' );
+
                # bug 15810: blocked admins should have limited access here
                $status = self::checkUnblockSelf( $this->target );
                if ( $status !== true ) {
@@ -81,7 +93,7 @@ class SpecialBlock extends SpecialPage {
                $wgOut->addModules( 'mediawiki.special', 'mediawiki.special.block' );
 
                $fields = self::getFormFields();
-               $this->alreadyBlocked = $this->maybeAlterFormDefaults( $fields );
+               $this->maybeAlterFormDefaults( $fields );
 
                $form = new HTMLForm( $fields );
                $form->setTitle( $this->getTitle() );
@@ -94,6 +106,7 @@ class SpecialBlock extends SpecialPage {
                $form->setSubmitText( $t );
 
                $this->doPreText( $form );
+               $this->doHeadertext( $form );
                $this->doPostText( $form );
 
                if( $form->show() ){
@@ -183,11 +196,20 @@ class SpecialBlock extends SpecialPage {
                        'default' => false,
                );
 
-               $a['AlreadyBlocked'] = array(
+               # This is basically a copy of the Target field, but the user can't change it, so we
+               # can see if the warnings we maybe showed to the user before still apply
+               $a['PreviousTarget'] = array(
                        'type' => 'hidden',
                        'default' => false,
                );
 
+               # We'll turn this into a checkbox if we need to
+               $a['Confirm'] = array(
+                       'type' => 'hidden',
+                       'default' => '',
+                       'label-message' => 'ipb-confirm',
+               );
+
                return $a;
        }
 
@@ -199,8 +221,14 @@ class SpecialBlock extends SpecialPage {
         *     already blocked)
         */
        protected function maybeAlterFormDefaults( &$fields ){
+               global $wgRequest, $wgUser;
+
+               # This will be overwritten by request data
                $fields['Target']['default'] = (string)$this->target;
 
+               # This won't be
+               $fields['PreviousTarget']['default'] = (string)$this->target;
+
                $block = Block::newFromTarget( $this->target );
 
                if( $block instanceof Block && !$block->mAuto # The block exists and isn't an autoblock
@@ -221,7 +249,17 @@ class SpecialBlock extends SpecialPage {
                                $fields['DisableUTEdit']['default'] = $block->prevents( 'editownusertalk' );
                        }
                        $fields['Reason']['default'] = $block->mReason;
-                       $fields['AlreadyBlocked']['default'] = htmlspecialchars( $block->getTarget() );
+
+                       if( $wgRequest->wasPosted() ){
+                               # Ok, so we got a POST submission asking us to reblock a user.  So show the
+                               # confirm checkbox; the user will only see it if they haven't previously
+                               $fields['Confirm']['type'] = 'check';
+                       } else {
+                               # We got a target, but it wasn't a POST request, so the user must have gone
+                               # to a link like [[Special:Block/User]].  We don't need to show the checkbox
+                               # as long as they go ahead and block *that* user
+                               $fields['Confirm']['default'] = 1;
+                       }
 
                        if( $block->mExpiry == 'infinity' ) {
                                $fields['Expiry']['default'] = 'indefinite';
@@ -229,9 +267,23 @@ class SpecialBlock extends SpecialPage {
                                $fields['Expiry']['default'] = wfTimestamp( TS_RFC2822, $block->mExpiry );
                        }
 
-                       return true;
+                       $this->alreadyBlocked = true;
+                       $this->preErrors[] = array( 'ipb-needreblock', (string)$block->getTarget() );
+               }
+
+               # We always need confirmation to do HideUser
+               if( $this->requestedHideUser ){
+                       $fields['Confirm']['type'] = 'check';
+                       unset( $fields['Confirm']['default'] );
+                       $this->preErrors[] = 'ipb-confirmhideuser';
+               }
+
+               # Or if the user is trying to block themselves
+               if( (string)$this->target === $wgUser->getName() ){
+                       $fields['Confirm']['type'] = 'check';
+                       unset( $fields['Confirm']['default'] );
+                       $this->preErrors[] = 'ipb-blockingself';
                }
-               return false;
        }
 
        /**
@@ -265,17 +317,25 @@ class SpecialBlock extends SpecialPage {
                                $form->addPreText( $s );
                        }
                }
+       }
 
-               # Username/IP is blocked already locally
-               if( $this->alreadyBlocked ) {
-                       $form->addPreText( Html::rawElement(
-                               'div',
-                               array( 'class' => 'mw-ipb-needreblock', ),
-                               wfMsgExt(
-                                       'ipb-needreblock',
-                                       array( 'parseinline' ),
-                                       $this->target
-                       ) ) );
+       /**
+        * Add header text inside the form, just underneath where the errors would go
+        * @param $form HTMLForm
+        * @return void
+        */
+       protected function doHeaderText( HTMLForm &$form ){
+               global $wgRequest;
+               # Don't need to do anything if the form has been posted
+               if( !$wgRequest->wasPosted() && $this->preErrors ){
+                       $s = HTMLForm::formatErrors( $this->preErrors );
+                       if( $s ){
+                               $form->addHeaderText( Html::rawElement(
+                                       'div',
+                                       array( 'class' => 'error' ),
+                                       $s
+                               ) );
+                       }
                }
        }
 
@@ -481,6 +541,10 @@ class SpecialBlock extends SpecialPage {
                // Handled by field validator callback
                // self::validateTargetField( $data['Target'] );
 
+               # This might have been a hidden field or a checkbox, so interesting data
+               # can come from it
+               $data['Confirm'] = !in_array( $data['Confirm'], array( '', '0', null, false ), true );
+
                list( $target, $type ) = self::getTargetAndType( $data['Target'] );
                if( $type == Block::TYPE_USER ){
                        $user = $target;
@@ -490,8 +554,7 @@ class SpecialBlock extends SpecialPage {
                        # 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() )  )
+                       if( $target === $wgUser->getName() && ( $data['PreviousTarget'] != $data['Target'] || !$data['Confirm'] ) )
                        {
                                return array( 'ipb-blockingself' );
                        }
@@ -544,6 +607,9 @@ class SpecialBlock extends SpecialPage {
                                # Typically, the user should have a handful of edits.
                                # Disallow hiding users with many edits for performance.
                                return array( 'ipb_hide_invalid' );
+
+                       } elseif( !$data['Confirm'] ){
+                               return array( 'ipb-confirmhideuser' );
                        }
                }
 
@@ -568,7 +634,7 @@ class SpecialBlock extends SpecialPage {
                $status = $block->insert();
                if( !$status ) {
                        # Show form unless the user is already aware of this...
-                       if( $data['AlreadyBlocked'] != htmlspecialchars( $block->getTarget() ) ) {
+                       if( ( $data['PreviousTarget'] != htmlspecialchars( $block->getTarget() ) ) || !$data['Confirm'] ) {
                                return array( array( 'ipb_already_blocked', $block->getTarget() ) );
                        # Otherwise, try to update the block...
                        } else {
index a1cf9bc..7ccbb0f 100644 (file)
@@ -3056,11 +3056,13 @@ Fill in a specific reason below (for example, citing particular pages that were
 'ipbwatchuser'                    => "Watch this user's user and talk pages",
 'ipb-disableusertalk'             => 'Prevent this user from editing their own talk page while blocked',
 'ipb-change-block'                => 'Re-block the user with these settings',
+'ipb-confirm'                     => 'Confirm block',
 'badipaddress'                    => 'Invalid IP address',
 'blockipsuccesssub'               => 'Block succeeded',
 'blockipsuccesstext'              => '[[Special:Contributions/$1|$1]] has been blocked.<br />
 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-confirmhideuser'             => 'You are about to block a user with "hide user" enabled.  This will suppress the user\'s name in all lists and log entries.  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',
@@ -3126,13 +3128,10 @@ See the [[Special:IPBlockList|IP block list]] for the list of currently operatio
 'ipb_expiry_temp'                 => 'Hidden username blocks must be permanent.',
 'ipb_hide_invalid'                => 'Unable to suppress this account; it may have too many edits.',
 'ipb_already_blocked'             => '"$1" is already blocked',
-'ipb-needreblock'                 => '== Already blocked ==
-$1 is already blocked.
-Do you want to change the settings?',
+'ipb-needreblock'                 => '$1 is already blocked. Do you want to change the settings?',
 'ipb-otherblocks-header'          => 'Other {{PLURAL:$1|block|blocks}}',
 'unblock-hideuser'                => 'You cannot unblock this user, as their username has been hidden.',
-'ipb_cant_unblock'                => 'Error: Block ID $1 not found.
-It may have been unblocked already.',
+'ipb_cant_unblock'                => 'Error: Block ID $1 not found. It may have been unblocked already.',
 'ipb_blocked_as_range'            => 'Error: The IP address $1 is not blocked directly and cannot be unblocked.
 It is, however, blocked as part of the range $2, which can be unblocked.',
 'ip_range_invalid'                => 'Invalid IP range.',
index e942c45..a84ea85 100644 (file)
@@ -2070,10 +2070,12 @@ $wgMessageStructure = array(
                'ipbwatchuser',
                'ipb-disableusertalk',
                'ipb-change-block',
+               'ipb-confirm',
                'badipaddress',
                'blockipsuccesssub',
                'blockipsuccesstext',
                'ipb-blockingself',
+               'ipb-confirmhideuser',
                'ipb-edit-dropdown',
                'ipb-unblock-addr',
                'ipb-unblock',