/// @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' );
$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 ) {
$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() );
$form->setSubmitText( $t );
$this->doPreText( $form );
+ $this->doHeadertext( $form );
$this->doPostText( $form );
if( $form->show() ){
'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;
}
* 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
$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';
$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;
}
/**
$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
+ ) );
+ }
}
}
// 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;
# 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' );
}
# 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' );
}
}
$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 {
'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',
'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.',