2011-03-12 21:54:35 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2011-03-12 22:53:15 +00:00
|
|
|
* Implements Special:Block
|
2011-03-12 21:54:35 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup SpecialPage
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A special page that allows users with 'block' right to block users from
|
|
|
|
|
* editing pages and other actions
|
|
|
|
|
*
|
|
|
|
|
* @ingroup SpecialPage
|
|
|
|
|
*/
|
2011-03-12 22:53:15 +00:00
|
|
|
class SpecialBlock extends SpecialPage {
|
2011-03-13 09:57:02 +00:00
|
|
|
/** The maximum number of edits a user can have and still be hidden
|
|
|
|
|
* TODO: config setting? */
|
2011-03-12 21:54:35 +00:00
|
|
|
const HIDEUSER_CONTRIBLIMIT = 1000;
|
|
|
|
|
|
2011-03-13 09:57:02 +00:00
|
|
|
/** @var User user to be blocked, as passed either by parameter (url?wpTarget=Foo)
|
|
|
|
|
* or as subpage (Special:Block/Foo) */
|
2011-03-12 22:53:15 +00:00
|
|
|
protected $target;
|
|
|
|
|
|
2011-03-13 09:57:02 +00:00
|
|
|
/// @var Block::TYPE_ constant
|
2011-03-12 22:53:15 +00:00
|
|
|
protected $type;
|
|
|
|
|
|
2011-04-01 23:13:15 +00:00
|
|
|
/// @var User|String the previous block target
|
|
|
|
|
protected $previousTarget;
|
|
|
|
|
|
|
|
|
|
/// @var Bool whether the previous submission of the form asked for HideUser
|
|
|
|
|
protected $requestedHideUser;
|
|
|
|
|
|
2011-03-13 09:57:02 +00:00
|
|
|
/// @var Bool
|
2011-03-12 22:53:15 +00:00
|
|
|
protected $alreadyBlocked;
|
2011-06-02 19:32:45 +00:00
|
|
|
|
2011-04-01 23:13:15 +00:00
|
|
|
/// @var Array
|
|
|
|
|
protected $preErrors = array();
|
2011-03-12 22:53:15 +00:00
|
|
|
|
2011-03-12 21:54:35 +00:00
|
|
|
public function __construct() {
|
2011-03-12 22:53:15 +00:00
|
|
|
parent::__construct( 'Block', 'block' );
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute( $par ) {
|
2011-11-15 01:34:19 +00:00
|
|
|
$this->checkPermissions();
|
|
|
|
|
$this->checkReadOnly();
|
2011-07-16 19:31:18 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
# Extract variables from the request. Try not to get into a situation where we
|
|
|
|
|
# need to extract *every* variable from the form just for processing here, but
|
|
|
|
|
# there are legitimate uses for some variables
|
2011-09-12 08:49:14 +00:00
|
|
|
$request = $this->getRequest();
|
|
|
|
|
list( $this->target, $this->type ) = self::getTargetAndType( $par, $request );
|
2011-03-12 22:53:15 +00:00
|
|
|
if ( $this->target instanceof User ) {
|
|
|
|
|
# Set the 'relevant user' in the skin, so it displays links like Contributions,
|
|
|
|
|
# User logs, UserRights, etc.
|
2011-07-01 02:25:19 +00:00
|
|
|
$this->getSkin()->setRelevantUser( $this->target );
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2011-09-12 08:49:14 +00:00
|
|
|
list( $this->previousTarget, /*...*/ ) = Block::parseTarget( $request->getVal( 'wpPreviousTarget' ) );
|
|
|
|
|
$this->requestedHideUser = $request->getBool( 'wpHideUser' );
|
2011-04-01 23:13:15 +00:00
|
|
|
|
2011-03-12 21:54:35 +00:00
|
|
|
# bug 15810: blocked admins should have limited access here
|
2011-11-13 07:25:56 +00:00
|
|
|
$status = self::checkUnblockSelf( $this->target, $user );
|
2011-03-12 22:53:15 +00:00
|
|
|
if ( $status !== true ) {
|
|
|
|
|
throw new ErrorPageError( 'badaccess', $status );
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-21 08:54:14 +00:00
|
|
|
$this->setHeaders();
|
|
|
|
|
$this->outputHeader();
|
|
|
|
|
|
2011-09-12 08:49:14 +00:00
|
|
|
$out = $this->getOutput();
|
2011-10-27 20:23:16 +00:00
|
|
|
$out->setPageTitle( $this->msg( 'blockip-title' ) );
|
2011-10-01 05:55:12 +00:00
|
|
|
$out->addModules( array( 'mediawiki.special', 'mediawiki.special.block' ) );
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2011-09-12 08:49:14 +00:00
|
|
|
$fields = $this->getFormFields();
|
2011-04-01 23:13:15 +00:00
|
|
|
$this->maybeAlterFormDefaults( $fields );
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2011-04-13 16:51:22 +00:00
|
|
|
$form = new HTMLForm( $fields, $this->getContext() );
|
2011-03-12 22:53:15 +00:00
|
|
|
$form->setWrapperLegend( wfMsg( 'blockip-legend' ) );
|
2011-11-13 07:25:56 +00:00
|
|
|
$form->setSubmitCallback( array( __CLASS__, 'processUIForm' ) );
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
$t = $this->alreadyBlocked
|
|
|
|
|
? wfMsg( 'ipb-change-block' )
|
|
|
|
|
: wfMsg( 'ipbsubmit' );
|
|
|
|
|
$form->setSubmitText( $t );
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
$this->doPreText( $form );
|
2011-04-01 23:13:15 +00:00
|
|
|
$this->doHeadertext( $form );
|
2011-03-12 22:53:15 +00:00
|
|
|
$this->doPostText( $form );
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
if( $form->show() ){
|
2011-10-27 20:23:16 +00:00
|
|
|
$out->setPageTitle( $this->msg( 'blockipsuccesssub' ) );
|
2011-09-12 08:49:14 +00:00
|
|
|
$out->addWikiMsg( 'blockipsuccesstext', $this->target );
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
/**
|
|
|
|
|
* Get the HTMLForm descriptor array for the block form
|
|
|
|
|
* @return Array
|
|
|
|
|
*/
|
2011-09-12 08:49:14 +00:00
|
|
|
protected function getFormFields(){
|
|
|
|
|
global $wgBlockAllowsUTEdit;
|
|
|
|
|
|
|
|
|
|
$user = $this->getUser();
|
2011-03-12 22:53:15 +00:00
|
|
|
|
|
|
|
|
$a = array(
|
|
|
|
|
'Target' => array(
|
|
|
|
|
'type' => 'text',
|
|
|
|
|
'label-message' => 'ipadressorusername',
|
|
|
|
|
'tabindex' => '1',
|
|
|
|
|
'id' => 'mw-bi-target',
|
|
|
|
|
'size' => '45',
|
|
|
|
|
'required' => true,
|
2011-03-13 09:57:02 +00:00
|
|
|
'validation-callback' => array( __CLASS__, 'validateTargetField' ),
|
2011-03-12 22:53:15 +00:00
|
|
|
),
|
|
|
|
|
'Expiry' => array(
|
2011-03-18 22:28:39 +00:00
|
|
|
'type' => !count( self::getSuggestedDurations() ) ? 'text' : 'selectorother',
|
2011-03-12 22:53:15 +00:00
|
|
|
'label-message' => 'ipbexpiry',
|
|
|
|
|
'required' => true,
|
|
|
|
|
'tabindex' => '2',
|
|
|
|
|
'options' => self::getSuggestedDurations(),
|
|
|
|
|
'other' => wfMsg( 'ipbother' ),
|
|
|
|
|
),
|
|
|
|
|
'Reason' => array(
|
|
|
|
|
'type' => 'selectandother',
|
|
|
|
|
'label-message' => 'ipbreason',
|
|
|
|
|
'options-message' => 'ipbreason-dropdown',
|
|
|
|
|
),
|
|
|
|
|
'CreateAccount' => array(
|
|
|
|
|
'type' => 'check',
|
|
|
|
|
'label-message' => 'ipbcreateaccount',
|
|
|
|
|
'default' => true,
|
|
|
|
|
),
|
2011-03-12 22:51:48 +00:00
|
|
|
);
|
2011-03-12 22:53:15 +00:00
|
|
|
|
2011-09-12 08:49:14 +00:00
|
|
|
if( self::canBlockEmail( $user ) ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
$a['DisableEmail'] = array(
|
|
|
|
|
'type' => 'check',
|
|
|
|
|
'label-message' => 'ipbemailban',
|
2011-03-12 21:54:35 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( $wgBlockAllowsUTEdit ){
|
2011-03-12 22:53:15 +00:00
|
|
|
$a['DisableUTEdit'] = array(
|
|
|
|
|
'type' => 'check',
|
|
|
|
|
'label-message' => 'ipb-disableusertalk',
|
|
|
|
|
'default' => false,
|
2011-03-12 21:54:35 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
$a['AutoBlock'] = array(
|
|
|
|
|
'type' => 'check',
|
|
|
|
|
'label-message' => 'ipbenableautoblock',
|
|
|
|
|
'default' => true,
|
2011-03-12 21:54:35 +00:00
|
|
|
);
|
|
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
# Allow some users to hide name from block log, blocklist and listusers
|
2011-09-12 08:49:14 +00:00
|
|
|
if( $user->isAllowed( 'hideuser' ) ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
$a['HideUser'] = array(
|
|
|
|
|
'type' => 'check',
|
|
|
|
|
'label-message' => 'ipbhidename',
|
|
|
|
|
'cssclass' => 'mw-block-hideuser',
|
2011-03-12 21:54:35 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Watchlist their user page? (Only if user is logged in)
|
2011-09-12 08:49:14 +00:00
|
|
|
if( $user->isLoggedIn() ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
$a['Watch'] = array(
|
|
|
|
|
'type' => 'check',
|
|
|
|
|
'label-message' => 'ipbwatchuser',
|
2011-03-12 21:54:35 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
$a['HardBlock'] = array(
|
|
|
|
|
'type' => 'check',
|
|
|
|
|
'label-message' => 'ipb-hardblock',
|
|
|
|
|
'default' => false,
|
2011-03-12 21:54:35 +00:00
|
|
|
);
|
|
|
|
|
|
2011-04-01 23:13:15 +00:00
|
|
|
# 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(
|
2011-03-12 22:53:15 +00:00
|
|
|
'type' => 'hidden',
|
|
|
|
|
'default' => false,
|
|
|
|
|
);
|
|
|
|
|
|
2011-04-01 23:13:15 +00:00
|
|
|
# We'll turn this into a checkbox if we need to
|
|
|
|
|
$a['Confirm'] = array(
|
|
|
|
|
'type' => 'hidden',
|
|
|
|
|
'default' => '',
|
|
|
|
|
'label-message' => 'ipb-confirm',
|
|
|
|
|
);
|
|
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
return $a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If the user has already been blocked with similar settings, load that block
|
|
|
|
|
* and change the defaults for the form fields to match the existing settings.
|
|
|
|
|
* @param &$fields Array HTMLForm descriptor array
|
|
|
|
|
* @return Bool whether fields were altered (that is, whether the target is
|
|
|
|
|
* already blocked)
|
|
|
|
|
*/
|
|
|
|
|
protected function maybeAlterFormDefaults( &$fields ){
|
2011-04-01 23:13:15 +00:00
|
|
|
# This will be overwritten by request data
|
2011-03-13 14:41:57 +00:00
|
|
|
$fields['Target']['default'] = (string)$this->target;
|
2011-03-12 22:53:15 +00:00
|
|
|
|
2011-04-01 23:13:15 +00:00
|
|
|
# This won't be
|
|
|
|
|
$fields['PreviousTarget']['default'] = (string)$this->target;
|
|
|
|
|
|
2011-03-21 19:12:41 +00:00
|
|
|
$block = Block::newFromTarget( $this->target );
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
if( $block instanceof Block && !$block->mAuto # The block exists and isn't an autoblock
|
|
|
|
|
&& ( $this->type != Block::TYPE_RANGE # The block isn't a rangeblock
|
2011-03-21 19:12:41 +00:00
|
|
|
|| $block->getTarget() == $this->target ) # or if it is, the range is what we're about to block
|
2011-03-12 22:53:15 +00:00
|
|
|
)
|
|
|
|
|
{
|
2011-03-19 23:47:08 +00:00
|
|
|
$fields['HardBlock']['default'] = $block->isHardblock();
|
|
|
|
|
$fields['CreateAccount']['default'] = $block->prevents( 'createaccount' );
|
2011-03-21 19:12:41 +00:00
|
|
|
$fields['AutoBlock']['default'] = $block->isAutoblocking();
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-15 11:20:15 +00:00
|
|
|
if( isset( $fields['DisableEmail'] ) ){
|
2011-03-19 23:47:08 +00:00
|
|
|
$fields['DisableEmail']['default'] = $block->prevents( 'sendemail' );
|
2011-03-15 11:20:15 +00:00
|
|
|
}
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-15 11:20:15 +00:00
|
|
|
if( isset( $fields['HideUser'] ) ){
|
|
|
|
|
$fields['HideUser']['default'] = $block->mHideName;
|
|
|
|
|
}
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-15 11:20:15 +00:00
|
|
|
if( isset( $fields['DisableUTEdit'] ) ){
|
2011-03-20 17:43:17 +00:00
|
|
|
$fields['DisableUTEdit']['default'] = $block->prevents( 'editownusertalk' );
|
2011-03-15 11:20:15 +00:00
|
|
|
}
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
$fields['Reason']['default'] = $block->mReason;
|
2011-04-01 23:13:15 +00:00
|
|
|
|
2011-09-12 08:49:14 +00:00
|
|
|
if( $this->getRequest()->wasPosted() ){
|
2011-04-01 23:13:15 +00:00
|
|
|
# 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;
|
|
|
|
|
}
|
2011-03-12 22:53:15 +00:00
|
|
|
|
|
|
|
|
if( $block->mExpiry == 'infinity' ) {
|
|
|
|
|
$fields['Expiry']['default'] = 'indefinite';
|
|
|
|
|
} else {
|
|
|
|
|
$fields['Expiry']['default'] = wfTimestamp( TS_RFC2822, $block->mExpiry );
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-01 23:13:15 +00:00
|
|
|
$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
|
2011-09-12 08:49:14 +00:00
|
|
|
if( (string)$this->target === $this->getUser()->getName() ){
|
2011-04-01 23:13:15 +00:00
|
|
|
$fields['Confirm']['type'] = 'check';
|
|
|
|
|
unset( $fields['Confirm']['default'] );
|
|
|
|
|
$this->preErrors[] = 'ipb-blockingself';
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-03-12 22:53:15 +00:00
|
|
|
* Add header elements like block log entries, etc.
|
|
|
|
|
* @param $form HTMLForm
|
|
|
|
|
* @return void
|
2011-03-12 21:54:35 +00:00
|
|
|
*/
|
2011-03-12 22:53:15 +00:00
|
|
|
protected function doPreText( HTMLForm &$form ){
|
|
|
|
|
$form->addPreText( wfMsgExt( 'blockiptext', 'parse' ) );
|
|
|
|
|
|
|
|
|
|
$otherBlockMessages = array();
|
|
|
|
|
if( $this->target !== null ) {
|
|
|
|
|
# Get other blocks, i.e. from GlobalBlocking or TorBlock extension
|
|
|
|
|
wfRunHooks( 'OtherBlockLogLink', array( &$otherBlockMessages, $this->target ) );
|
|
|
|
|
|
|
|
|
|
if( count( $otherBlockMessages ) ) {
|
|
|
|
|
$s = Html::rawElement(
|
|
|
|
|
'h2',
|
|
|
|
|
array(),
|
|
|
|
|
wfMsgExt( 'ipb-otherblocks-header', 'parseinline', count( $otherBlockMessages ) )
|
|
|
|
|
) . "\n";
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
$list = '';
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
foreach( $otherBlockMessages as $link ) {
|
|
|
|
|
$list .= Html::rawElement( 'li', array(), $link ) . "\n";
|
|
|
|
|
}
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
$s .= Html::rawElement(
|
|
|
|
|
'ul',
|
|
|
|
|
array( 'class' => 'mw-blockip-alreadyblocked' ),
|
|
|
|
|
$list
|
|
|
|
|
) . "\n";
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
$form->addPreText( $s );
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-04-01 23:13:15 +00:00
|
|
|
}
|
2011-03-12 22:53:15 +00:00
|
|
|
|
2011-04-01 23:13:15 +00:00
|
|
|
/**
|
|
|
|
|
* Add header text inside the form, just underneath where the errors would go
|
|
|
|
|
* @param $form HTMLForm
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected function doHeaderText( HTMLForm &$form ){
|
|
|
|
|
# Don't need to do anything if the form has been posted
|
2011-09-12 08:49:14 +00:00
|
|
|
if( !$this->getRequest()->wasPosted() && $this->preErrors ){
|
2011-04-01 23:13:15 +00:00
|
|
|
$s = HTMLForm::formatErrors( $this->preErrors );
|
|
|
|
|
if( $s ){
|
|
|
|
|
$form->addHeaderText( Html::rawElement(
|
|
|
|
|
'div',
|
|
|
|
|
array( 'class' => 'error' ),
|
|
|
|
|
$s
|
|
|
|
|
) );
|
|
|
|
|
}
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
2011-03-12 22:53:15 +00:00
|
|
|
|
2011-03-12 21:54:35 +00:00
|
|
|
/**
|
2011-03-12 22:53:15 +00:00
|
|
|
* Add footer elements to the form
|
|
|
|
|
* @param $form HTMLForm
|
|
|
|
|
* @return void
|
2011-03-12 21:54:35 +00:00
|
|
|
*/
|
2011-03-12 22:53:15 +00:00
|
|
|
protected function doPostText( HTMLForm &$form ){
|
|
|
|
|
# Link to the user's contributions, if applicable
|
|
|
|
|
if( $this->target instanceof User ){
|
|
|
|
|
$contribsPage = SpecialPage::getTitleFor( 'Contributions', $this->target->getName() );
|
2011-07-26 19:04:48 +00:00
|
|
|
$links[] = Linker::link(
|
2011-03-12 22:53:15 +00:00
|
|
|
$contribsPage,
|
|
|
|
|
wfMsgExt( 'ipb-blocklist-contribs', 'escape', $this->target->getName() )
|
|
|
|
|
);
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
2011-03-12 22:53:15 +00:00
|
|
|
|
|
|
|
|
# Link to unblock the specified user, or to a blank unblock form
|
|
|
|
|
if( $this->target instanceof User ) {
|
|
|
|
|
$message = wfMsgExt( 'ipb-unblock-addr', array( 'parseinline' ), $this->target->getName() );
|
2011-03-13 21:33:52 +00:00
|
|
|
$list = SpecialPage::getTitleFor( 'Unblock', $this->target->getName() );
|
2011-03-12 21:54:35 +00:00
|
|
|
} else {
|
2011-03-12 22:53:15 +00:00
|
|
|
$message = wfMsgExt( 'ipb-unblock', array( 'parseinline' ) );
|
2011-03-13 21:33:52 +00:00
|
|
|
$list = SpecialPage::getTitleFor( 'Unblock' );
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
2011-07-26 19:04:48 +00:00
|
|
|
$links[] = Linker::linkKnown( $list, $message, array() );
|
2011-03-12 22:53:15 +00:00
|
|
|
|
|
|
|
|
# Link to the block list
|
2011-07-26 19:04:48 +00:00
|
|
|
$links[] = Linker::linkKnown(
|
2011-03-14 16:09:44 +00:00
|
|
|
SpecialPage::getTitleFor( 'BlockList' ),
|
2011-03-12 22:53:15 +00:00
|
|
|
wfMsg( 'ipb-blocklist' )
|
|
|
|
|
);
|
|
|
|
|
|
2011-09-12 08:49:14 +00:00
|
|
|
$user = $this->getUser();
|
|
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
# Link to edit the block dropdown reasons, if applicable
|
2011-09-12 08:49:14 +00:00
|
|
|
if ( $user->isAllowed( 'editinterface' ) ) {
|
2011-07-26 19:04:48 +00:00
|
|
|
$links[] = Linker::link(
|
2011-03-12 22:53:15 +00:00
|
|
|
Title::makeTitle( NS_MEDIAWIKI, 'Ipbreason-dropdown' ),
|
|
|
|
|
wfMsgHtml( 'ipb-edit-dropdown' ),
|
|
|
|
|
array(),
|
|
|
|
|
array( 'action' => 'edit' )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$form->addPostText( Html::rawElement(
|
|
|
|
|
'p',
|
|
|
|
|
array( 'class' => 'mw-ipb-conveniencelinks' ),
|
2011-09-12 08:49:14 +00:00
|
|
|
$this->getLang()->pipeList( $links )
|
2011-03-12 22:53:15 +00:00
|
|
|
) );
|
|
|
|
|
|
|
|
|
|
if( $this->target instanceof User ){
|
|
|
|
|
# Get relevant extracts from the block and suppression logs, if possible
|
|
|
|
|
$userpage = $this->target->getUserPage();
|
|
|
|
|
$out = '';
|
|
|
|
|
|
|
|
|
|
LogEventsList::showLogExtract(
|
|
|
|
|
$out,
|
|
|
|
|
'block',
|
2011-09-24 17:52:53 +00:00
|
|
|
$userpage,
|
2011-03-12 22:53:15 +00:00
|
|
|
'',
|
|
|
|
|
array(
|
|
|
|
|
'lim' => 10,
|
|
|
|
|
'msgKey' => array( 'blocklog-showlog', $userpage->getText() ),
|
|
|
|
|
'showIfEmpty' => false
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
$form->addPostText( $out );
|
|
|
|
|
|
|
|
|
|
# Add suppression block entries if allowed
|
2011-09-12 08:49:14 +00:00
|
|
|
if( $user->isAllowed( 'suppressionlog' ) ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
LogEventsList::showLogExtract(
|
|
|
|
|
$out,
|
|
|
|
|
'suppress',
|
2011-09-24 17:52:53 +00:00
|
|
|
$userpage,
|
2011-03-12 22:53:15 +00:00
|
|
|
'',
|
|
|
|
|
array(
|
|
|
|
|
'lim' => 10,
|
|
|
|
|
'conds' => array( 'log_action' => array( 'block', 'reblock', 'unblock' ) ),
|
|
|
|
|
'msgKey' => array( 'blocklog-showsuppresslog', $userpage->getText() ),
|
|
|
|
|
'showIfEmpty' => false
|
|
|
|
|
)
|
|
|
|
|
);
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
$form->addPostText( $out );
|
|
|
|
|
}
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-03-12 22:53:15 +00:00
|
|
|
* Determine the target of the block, and the type of target
|
|
|
|
|
* TODO: should be in Block.php?
|
|
|
|
|
* @param $par String subpage parameter passed to setup, or data value from
|
|
|
|
|
* the HTMLForm
|
|
|
|
|
* @param $request WebRequest optionally try and get data from a request too
|
2011-07-20 02:34:17 +00:00
|
|
|
* @return array( User|string|null, Block::TYPE_ constant|null )
|
2011-03-12 21:54:35 +00:00
|
|
|
*/
|
2011-03-12 22:53:15 +00:00
|
|
|
public static function getTargetAndType( $par, WebRequest $request = null ){
|
|
|
|
|
$i = 0;
|
|
|
|
|
$target = null;
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
while( true ){
|
|
|
|
|
switch( $i++ ){
|
|
|
|
|
case 0:
|
|
|
|
|
# The HTMLForm will check wpTarget first and only if it doesn't get
|
|
|
|
|
# a value use the default, which will be generated from the options
|
|
|
|
|
# below; so this has to have a higher precedence here than $par, or
|
|
|
|
|
# we could end up with different values in $this->target and the HTMLForm!
|
|
|
|
|
if( $request instanceof WebRequest ){
|
|
|
|
|
$target = $request->getText( 'wpTarget', null );
|
2011-03-12 22:51:48 +00:00
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
break;
|
2011-03-12 22:53:15 +00:00
|
|
|
case 1:
|
|
|
|
|
$target = $par;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
if( $request instanceof WebRequest ){
|
|
|
|
|
$target = $request->getText( 'ip', null );
|
2011-03-12 22:51:48 +00:00
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
break;
|
2011-03-12 22:53:15 +00:00
|
|
|
case 3:
|
|
|
|
|
# B/C @since 1.18
|
|
|
|
|
if( $request instanceof WebRequest ){
|
|
|
|
|
$target = $request->getText( 'wpBlockAddress', null );
|
|
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
break;
|
2011-03-12 22:53:15 +00:00
|
|
|
case 4:
|
|
|
|
|
break 2;
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-13 14:47:34 +00:00
|
|
|
list( $target, $type ) = Block::parseTarget( $target );
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-13 14:47:34 +00:00
|
|
|
if( $type !== null ){
|
|
|
|
|
return array( $target, $type );
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
return array( null, null );
|
|
|
|
|
}
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2011-03-13 10:02:56 +00:00
|
|
|
/**
|
|
|
|
|
* HTMLForm field validation-callback for Target field.
|
|
|
|
|
* @since 1.18
|
2011-07-26 19:04:48 +00:00
|
|
|
* @param $value String
|
|
|
|
|
* @param $alldata Array
|
2011-03-13 10:02:56 +00:00
|
|
|
* @return Message
|
|
|
|
|
*/
|
2011-11-13 07:25:56 +00:00
|
|
|
public static function validateTargetField( $value, $alldata, $form ) {
|
2011-03-13 09:57:02 +00:00
|
|
|
global $wgBlockCIDRLimit;
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2011-03-13 14:41:57 +00:00
|
|
|
list( $target, $type ) = self::getTargetAndType( $value );
|
2011-03-12 22:53:15 +00:00
|
|
|
|
|
|
|
|
if( $type == Block::TYPE_USER ){
|
|
|
|
|
# TODO: why do we not have a User->exists() method?
|
|
|
|
|
if( !$target->getId() ){
|
2011-11-13 07:25:56 +00:00
|
|
|
return $form->msg( 'nosuchusershort',
|
2011-06-20 19:45:35 +00:00
|
|
|
wfEscapeWikiText( $target->getName() ) );
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-13 07:25:56 +00:00
|
|
|
$status = self::checkUnblockSelf( $target, $form->getUser() );
|
2011-03-12 22:53:15 +00:00
|
|
|
if ( $status !== true ) {
|
2011-11-13 07:25:56 +00:00
|
|
|
return $form->msg( 'badaccess', $status );
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} elseif( $type == Block::TYPE_RANGE ){
|
|
|
|
|
list( $ip, $range ) = explode( '/', $target, 2 );
|
|
|
|
|
|
|
|
|
|
if( ( IP::isIPv4( $ip ) && $wgBlockCIDRLimit['IPv4'] == 32 )
|
2011-10-05 02:36:40 +00:00
|
|
|
|| ( IP::isIPv6( $ip ) && $wgBlockCIDRLimit['IPv6'] == 128 ) )
|
2011-03-12 22:53:15 +00:00
|
|
|
{
|
|
|
|
|
# Range block effectively disabled
|
2011-11-13 07:25:56 +00:00
|
|
|
return $form->msg( 'range_block_disabled' );
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( ( IP::isIPv4( $ip ) && $range > 32 )
|
|
|
|
|
|| ( IP::isIPv6( $ip ) && $range > 128 ) )
|
|
|
|
|
{
|
|
|
|
|
# Dodgy range
|
2011-11-13 07:25:56 +00:00
|
|
|
return $form->msg( 'ip_range_invalid' );
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( IP::isIPv4( $ip ) && $range < $wgBlockCIDRLimit['IPv4'] ) {
|
2011-11-13 07:25:56 +00:00
|
|
|
return $form->msg( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] );
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( IP::isIPv6( $ip ) && $range < $wgBlockCIDRLimit['IPv6'] ) {
|
2011-11-13 07:25:56 +00:00
|
|
|
return $form->msg( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] );
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
|
|
|
|
} elseif( $type == Block::TYPE_IP ){
|
|
|
|
|
# All is well
|
|
|
|
|
} else {
|
2011-11-13 07:25:56 +00:00
|
|
|
return $form->msg( 'badipaddress' );
|
2011-03-12 22:51:48 +00:00
|
|
|
}
|
2011-03-13 14:41:57 +00:00
|
|
|
|
|
|
|
|
return true;
|
2011-03-13 09:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-13 07:25:56 +00:00
|
|
|
/**
|
|
|
|
|
* Submit callback for an HTMLForm object, will simply pass
|
|
|
|
|
*/
|
|
|
|
|
public static function processUIForm( array $data, HTMLForm $form ) {
|
|
|
|
|
return self::processForm( $data, $form->getContext() );
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-13 09:57:02 +00:00
|
|
|
/**
|
|
|
|
|
* Given the form data, actually implement a block
|
|
|
|
|
* @param $data Array
|
|
|
|
|
* @return Bool|String
|
|
|
|
|
*/
|
2011-11-13 07:25:56 +00:00
|
|
|
public static function processForm( array $data, IContextSource $context ){
|
|
|
|
|
global $wgBlockAllowsUTEdit;
|
|
|
|
|
|
|
|
|
|
$performer = $context->getUser();
|
2011-03-13 09:57:02 +00:00
|
|
|
|
|
|
|
|
// Handled by field validator callback
|
|
|
|
|
// self::validateTargetField( $data['Target'] );
|
2011-03-12 22:53:15 +00:00
|
|
|
|
2011-04-01 23:13:15 +00:00
|
|
|
# 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 );
|
|
|
|
|
|
2011-03-13 14:41:57 +00:00
|
|
|
list( $target, $type ) = self::getTargetAndType( $data['Target'] );
|
|
|
|
|
if( $type == Block::TYPE_USER ){
|
|
|
|
|
$user = $target;
|
|
|
|
|
$target = $user->getName();
|
|
|
|
|
$userId = $user->getId();
|
2011-03-30 18:00:11 +00:00
|
|
|
|
|
|
|
|
# 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
|
2011-11-13 07:25:56 +00:00
|
|
|
if( $target === $performer->getName() &&
|
2011-08-11 10:33:22 +00:00
|
|
|
( $data['PreviousTarget'] !== $data['Target'] || !$data['Confirm'] ) )
|
2011-03-30 18:00:11 +00:00
|
|
|
{
|
|
|
|
|
return array( 'ipb-blockingself' );
|
|
|
|
|
}
|
2011-03-13 14:41:57 +00:00
|
|
|
} 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
|
2011-03-13 21:33:52 +00:00
|
|
|
return array( 'badipaddress' );
|
2011-03-13 14:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
if( ( strlen( $data['Expiry'] ) == 0) || ( strlen( $data['Expiry'] ) > 50 )
|
2011-03-18 16:35:22 +00:00
|
|
|
|| !self::parseExpiryInput( $data['Expiry'] ) )
|
2011-03-12 22:53:15 +00:00
|
|
|
{
|
2011-03-12 22:51:48 +00:00
|
|
|
return array( 'ipb_expiry_invalid' );
|
|
|
|
|
}
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2011-03-22 11:14:11 +00:00
|
|
|
if( !isset( $data['DisableEmail'] ) ){
|
|
|
|
|
$data['DisableEmail'] = false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
# If the user has done the form 'properly', they won't even have been given the
|
|
|
|
|
# option to suppress-block unless they have the 'hideuser' permission
|
|
|
|
|
if( !isset( $data['HideUser'] ) ){
|
|
|
|
|
$data['HideUser'] = false;
|
|
|
|
|
}
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
if( $data['HideUser'] ) {
|
2011-11-13 07:25:56 +00:00
|
|
|
if( !$performer->isAllowed('hideuser') ){
|
2011-03-12 22:53:15 +00:00
|
|
|
# this codepath is unreachable except by a malicious user spoofing forms,
|
|
|
|
|
# or by race conditions (user has oversight and sysop, loads block form,
|
|
|
|
|
# and is de-oversighted before submission); so need to fail completely
|
|
|
|
|
# rather than just silently disable hiding
|
|
|
|
|
return array( 'badaccess-group0' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Recheck params here...
|
|
|
|
|
if( $type != Block::TYPE_USER ) {
|
|
|
|
|
$data['HideUser'] = false; # IP users should not be hidden
|
2011-03-17 19:04:01 +00:00
|
|
|
} elseif( !in_array( $data['Expiry'], array( 'infinite', 'infinity', 'indefinite' ) ) ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
# Bad expiry.
|
2011-03-12 21:54:35 +00:00
|
|
|
return array( 'ipb_expiry_temp' );
|
2011-03-12 22:53:15 +00:00
|
|
|
} elseif( $user->getEditCount() > self::HIDEUSER_CONTRIBLIMIT ) {
|
|
|
|
|
# Typically, the user should have a handful of edits.
|
|
|
|
|
# Disallow hiding users with many edits for performance.
|
2011-03-12 21:54:35 +00:00
|
|
|
return array( 'ipb_hide_invalid' );
|
2011-04-01 23:13:15 +00:00
|
|
|
} elseif( !$data['Confirm'] ){
|
|
|
|
|
return array( 'ipb-confirmhideuser' );
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-21 19:12:41 +00:00
|
|
|
# Create block object.
|
|
|
|
|
$block = new Block();
|
|
|
|
|
$block->setTarget( $target );
|
2011-11-13 07:25:56 +00:00
|
|
|
$block->setBlocker( $performer );
|
2011-03-21 19:12:41 +00:00
|
|
|
$block->mReason = $data['Reason'][0];
|
|
|
|
|
$block->mExpiry = self::parseExpiryInput( $data['Expiry'] );
|
|
|
|
|
$block->prevents( 'createaccount', $data['CreateAccount'] );
|
2011-03-20 17:43:17 +00:00
|
|
|
$block->prevents( 'editownusertalk', ( !$wgBlockAllowsUTEdit || $data['DisableUTEdit'] ) );
|
2011-03-19 23:47:08 +00:00
|
|
|
$block->prevents( 'sendemail', $data['DisableEmail'] );
|
2011-03-21 19:12:41 +00:00
|
|
|
$block->isHardblock( $data['HardBlock'] );
|
|
|
|
|
$block->isAutoblocking( $data['AutoBlock'] );
|
|
|
|
|
$block->mHideName = $data['HideUser'];
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2011-11-13 07:25:56 +00:00
|
|
|
if( !wfRunHooks( 'BlockIp', array( &$block, &$performer ) ) ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
return array( 'hookaborted' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Try to insert block. Is there a conflicting block?
|
2011-03-22 11:22:15 +00:00
|
|
|
$status = $block->insert();
|
|
|
|
|
if( !$status ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
# Show form unless the user is already aware of this...
|
2011-06-24 07:49:50 +00:00
|
|
|
if( !$data['Confirm'] || ( array_key_exists( 'PreviousTarget', $data )
|
2011-09-28 01:28:29 +00:00
|
|
|
&& $data['PreviousTarget'] !== $target ) )
|
2011-06-24 07:49:50 +00:00
|
|
|
{
|
2011-03-22 17:26:32 +00:00
|
|
|
return array( array( 'ipb_already_blocked', $block->getTarget() ) );
|
2011-03-12 22:53:15 +00:00
|
|
|
# Otherwise, try to update the block...
|
|
|
|
|
} else {
|
|
|
|
|
# This returns direct blocks before autoblocks/rangeblocks, since we should
|
|
|
|
|
# be sure the user is blocked by now it should work for our purposes
|
2011-03-21 19:12:41 +00:00
|
|
|
$currentBlock = Block::newFromTarget( $target );
|
2011-03-12 22:53:15 +00:00
|
|
|
|
|
|
|
|
if( $block->equals( $currentBlock ) ) {
|
2011-03-22 17:26:32 +00:00
|
|
|
return array( array( 'ipb_already_blocked', $block->getTarget() ) );
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
# If the name was hidden and the blocking user cannot hide
|
|
|
|
|
# names, then don't allow any block changes...
|
2011-11-13 07:25:56 +00:00
|
|
|
if( $currentBlock->mHideName && !$performer->isAllowed( 'hideuser' ) ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
return array( 'cant-see-hidden-user' );
|
|
|
|
|
}
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
$currentBlock->delete();
|
2011-03-22 11:22:15 +00:00
|
|
|
$status = $block->insert();
|
2011-03-12 22:53:15 +00:00
|
|
|
$logaction = 'reblock';
|
|
|
|
|
|
|
|
|
|
# Unset _deleted fields if requested
|
|
|
|
|
if( $currentBlock->mHideName && !$data['HideUser'] ) {
|
|
|
|
|
RevisionDeleteUser::unsuppressUserName( $target, $userId );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# If hiding/unhiding a name, this should go in the private logs
|
|
|
|
|
if( (bool)$currentBlock->mHideName ){
|
|
|
|
|
$data['HideUser'] = true;
|
|
|
|
|
}
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
2011-03-12 22:53:15 +00:00
|
|
|
} else {
|
|
|
|
|
$logaction = 'block';
|
|
|
|
|
}
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2011-11-13 07:25:56 +00:00
|
|
|
wfRunHooks( 'BlockIpComplete', array( $block, $performer ) );
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
# Set *_deleted fields if requested
|
|
|
|
|
if( $data['HideUser'] ) {
|
|
|
|
|
RevisionDeleteUser::suppressUserName( $target, $userId );
|
|
|
|
|
}
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
# Can't watch a rangeblock
|
|
|
|
|
if( $type != Block::TYPE_RANGE && $data['Watch'] ) {
|
2011-11-13 07:25:56 +00:00
|
|
|
$performer->addWatch( Title::makeTitle( NS_USER, $target ) );
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
# Block constructor sanitizes certain block options on insert
|
2011-03-19 23:47:08 +00:00
|
|
|
$data['BlockEmail'] = $block->prevents( 'sendemail' );
|
2011-03-21 19:12:41 +00:00
|
|
|
$data['AutoBlock'] = $block->isAutoblocking();
|
2011-03-12 22:53:15 +00:00
|
|
|
|
|
|
|
|
# Prepare log parameters
|
|
|
|
|
$logParams = array();
|
|
|
|
|
$logParams[] = $data['Expiry'];
|
|
|
|
|
$logParams[] = self::blockLogFlags( $data, $type );
|
|
|
|
|
|
|
|
|
|
# Make log entry, if the name is hidden, put it in the oversight log
|
|
|
|
|
$log_type = $data['HideUser'] ? 'suppress' : 'block';
|
|
|
|
|
$log = new LogPage( $log_type );
|
2011-03-22 11:22:15 +00:00
|
|
|
$log_id = $log->addEntry(
|
2011-03-12 22:53:15 +00:00
|
|
|
$logaction,
|
|
|
|
|
Title::makeTitle( NS_USER, $target ),
|
|
|
|
|
$data['Reason'][0],
|
|
|
|
|
$logParams
|
|
|
|
|
);
|
2011-03-22 11:22:15 +00:00
|
|
|
# Relate log ID to block IDs (bug 25763)
|
2011-03-22 11:51:09 +00:00
|
|
|
$blockIds = array_merge( array( $status['id'] ), $status['autoIds'] );
|
2011-03-22 11:22:15 +00:00
|
|
|
$log->addRelations( 'ipb_id', $blockIds, $log_id );
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
# Report to the user
|
|
|
|
|
return true;
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-03-12 22:53:15 +00:00
|
|
|
* Get an array of suggested block durations from MediaWiki:Ipboptions
|
2011-05-17 22:03:20 +00:00
|
|
|
* @todo FIXME: This uses a rather odd syntax for the options, should it be converted
|
2011-03-12 22:53:15 +00:00
|
|
|
* to the standard "**<duration>|<displayname>" format?
|
2011-07-26 19:04:48 +00:00
|
|
|
* @param $lang Language|null the language to get the durations in, or null to use
|
|
|
|
|
* the wiki's content language
|
2011-03-12 22:53:15 +00:00
|
|
|
* @return Array
|
2011-03-12 21:54:35 +00:00
|
|
|
*/
|
2011-03-18 16:35:22 +00:00
|
|
|
public static function getSuggestedDurations( $lang = null ){
|
2011-03-12 22:53:15 +00:00
|
|
|
$a = array();
|
2011-03-18 16:35:22 +00:00
|
|
|
$msg = $lang === null
|
2011-03-21 19:12:41 +00:00
|
|
|
? wfMessage( 'ipboptions' )->inContentLanguage()->text()
|
|
|
|
|
: wfMessage( 'ipboptions' )->inLanguage( $lang )->text();
|
2011-03-18 16:35:22 +00:00
|
|
|
|
|
|
|
|
if( $msg == '-' ){
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach( explode( ',', $msg ) as $option ) {
|
|
|
|
|
if( strpos( $option, ':' ) === false ){
|
|
|
|
|
$option = "$option:$option";
|
|
|
|
|
}
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
list( $show, $value ) = explode( ':', $option );
|
|
|
|
|
$a[htmlspecialchars( $show )] = htmlspecialchars( $value );
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
return $a;
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-18 16:35:22 +00:00
|
|
|
/**
|
|
|
|
|
* Convert a submitted expiry time, which may be relative ("2 weeks", etc) or absolute
|
|
|
|
|
* ("24 May 2034", etc), into an absolute timestamp we can put into the database.
|
|
|
|
|
* @param $expiry String: whatever was typed into the form
|
|
|
|
|
* @return String: timestamp or "infinity" string for the DB implementation
|
|
|
|
|
*/
|
|
|
|
|
public static function parseExpiryInput( $expiry ) {
|
2011-03-18 22:28:39 +00:00
|
|
|
static $infinity;
|
|
|
|
|
if( $infinity == null ){
|
2011-05-18 19:29:50 +00:00
|
|
|
$infinity = wfGetDB( DB_SLAVE )->getInfinity();
|
2011-03-18 22:28:39 +00:00
|
|
|
}
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-18 16:35:22 +00:00
|
|
|
if ( $expiry == 'infinite' || $expiry == 'indefinite' ) {
|
2011-03-18 22:28:39 +00:00
|
|
|
$expiry = $infinity;
|
2011-03-18 16:35:22 +00:00
|
|
|
} else {
|
|
|
|
|
$expiry = strtotime( $expiry );
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-18 16:35:22 +00:00
|
|
|
if ( $expiry < 0 || $expiry === false ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-18 16:35:22 +00:00
|
|
|
$expiry = wfTimestamp( TS_MW, $expiry );
|
|
|
|
|
}
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-18 16:35:22 +00:00
|
|
|
return $expiry;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
/**
|
|
|
|
|
* Can we do an email block?
|
|
|
|
|
* @param $user User: the sysop wanting to make a block
|
|
|
|
|
* @return Boolean
|
|
|
|
|
*/
|
|
|
|
|
public static function canBlockEmail( $user ) {
|
|
|
|
|
global $wgEnableUserEmail, $wgSysopEmailBans;
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
return ( $wgEnableUserEmail && $wgSysopEmailBans && $user->isAllowed( 'blockemail' ) );
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
/**
|
|
|
|
|
* bug 15810: blocked admins should not be able to block/unblock
|
|
|
|
|
* others, and probably shouldn't be able to unblock themselves
|
|
|
|
|
* either.
|
|
|
|
|
* @param $user User|Int|String
|
2011-11-13 07:25:56 +00:00
|
|
|
* @param $performer User user doing the request
|
2011-07-26 19:04:48 +00:00
|
|
|
* @return Bool|String true or error message key
|
2011-03-12 22:53:15 +00:00
|
|
|
*/
|
2011-11-13 07:25:56 +00:00
|
|
|
public static function checkUnblockSelf( $user, User $performer ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
if ( is_int( $user ) ) {
|
|
|
|
|
$user = User::newFromId( $user );
|
|
|
|
|
} elseif ( is_string( $user ) ) {
|
|
|
|
|
$user = User::newFromName( $user );
|
|
|
|
|
}
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-11-13 07:25:56 +00:00
|
|
|
if( $performer->isBlocked() ){
|
|
|
|
|
if( $user instanceof User && $user->getId() == $performer->getId() ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
# User is trying to unblock themselves
|
2011-11-13 07:25:56 +00:00
|
|
|
if ( $performer->isAllowed( 'unblockself' ) ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
return true;
|
2011-07-26 19:04:48 +00:00
|
|
|
# User blocked themselves and is now trying to reverse it
|
2011-11-13 07:25:56 +00:00
|
|
|
} elseif ( $performer->blockedBy() === $performer->getName() ) {
|
2011-07-26 19:04:48 +00:00
|
|
|
return true;
|
2011-03-12 22:53:15 +00:00
|
|
|
} else {
|
|
|
|
|
return 'ipbnounblockself';
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
# User is trying to block/unblock someone else
|
|
|
|
|
return 'ipbblocked';
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return a comma-delimited list of "flags" to be passed to the log
|
|
|
|
|
* reader for this block, to provide more information in the logs
|
2011-03-12 22:53:15 +00:00
|
|
|
* @param $data Array from HTMLForm data
|
2011-10-06 22:57:32 +00:00
|
|
|
* @param $type Block::TYPE_ constant (USER, RANGE, or IP)
|
2011-03-12 21:54:35 +00:00
|
|
|
* @return array
|
|
|
|
|
*/
|
2011-03-12 22:53:15 +00:00
|
|
|
protected static function blockLogFlags( array $data, $type ) {
|
2011-03-12 21:54:35 +00:00
|
|
|
global $wgBlockAllowsUTEdit;
|
|
|
|
|
$flags = array();
|
2011-03-12 22:51:48 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
# when blocking a user the option 'anononly' is not available/has no effect -> do not write this into log
|
|
|
|
|
if( !$data['HardBlock'] && $type != Block::TYPE_USER ){
|
2011-09-01 14:40:56 +00:00
|
|
|
// For grepping: message block-log-flags-anononly
|
2011-03-12 22:53:15 +00:00
|
|
|
$flags[] = 'anononly';
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
if( $data['CreateAccount'] ){
|
2011-09-01 14:40:56 +00:00
|
|
|
// For grepping: message block-log-flags-nocreate
|
2011-03-12 22:53:15 +00:00
|
|
|
$flags[] = 'nocreate';
|
|
|
|
|
}
|
2011-03-12 22:51:48 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
# Same as anononly, this is not displayed when blocking an IP address
|
2011-10-06 22:57:32 +00:00
|
|
|
if( !$data['AutoBlock'] && $type == Block::TYPE_USER ){
|
2011-09-01 14:40:56 +00:00
|
|
|
// For grepping: message block-log-flags-noautoblock
|
2011-03-12 22:53:15 +00:00
|
|
|
$flags[] = 'noautoblock';
|
|
|
|
|
}
|
2011-03-12 22:51:48 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
if( $data['DisableEmail'] ){
|
2011-09-01 14:40:56 +00:00
|
|
|
// For grepping: message block-log-flags-noemail
|
2011-03-12 22:53:15 +00:00
|
|
|
$flags[] = 'noemail';
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-02 18:31:42 +00:00
|
|
|
if( $wgBlockAllowsUTEdit && $data['DisableUTEdit'] ){
|
2011-09-01 14:40:56 +00:00
|
|
|
// For grepping: message block-log-flags-nousertalk
|
2011-03-12 22:53:15 +00:00
|
|
|
$flags[] = 'nousertalk';
|
|
|
|
|
}
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
if( $data['HideUser'] ){
|
2011-09-01 14:40:56 +00:00
|
|
|
// For grepping: message block-log-flags-hiddenname
|
2011-03-12 22:53:15 +00:00
|
|
|
$flags[] = 'hiddenname';
|
2011-03-12 22:51:48 +00:00
|
|
|
}
|
2011-03-12 22:53:15 +00:00
|
|
|
|
|
|
|
|
return implode( ',', $flags );
|
2011-03-12 22:51:48 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-03-12 22:53:15 +00:00
|
|
|
|
|
|
|
|
# BC @since 1.18
|
|
|
|
|
class IPBlockForm extends SpecialBlock {}
|