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
|
|
|
|
|
*/
|
|
|
|
|
|
2019-05-13 14:18:07 +00:00
|
|
|
use MediaWiki\Block\DatabaseBlock;
|
2018-12-14 21:08:40 +00:00
|
|
|
use MediaWiki\Block\Restriction\NamespaceRestriction;
|
2020-01-10 00:00:51 +00:00
|
|
|
use MediaWiki\Block\Restriction\PageRestriction;
|
2019-04-11 19:54:10 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2020-05-08 22:31:17 +00:00
|
|
|
use MediaWiki\Permissions\PermissionManager;
|
2019-08-21 02:01:06 +00:00
|
|
|
use MediaWiki\User\UserIdentity;
|
2019-06-25 18:53:15 +00:00
|
|
|
use Wikimedia\IPUtils;
|
2018-08-27 22:19:37 +00:00
|
|
|
|
2011-03-12 21:54:35 +00:00
|
|
|
/**
|
|
|
|
|
* A special page that allows users with 'block' right to block users from
|
|
|
|
|
* editing pages and other actions
|
|
|
|
|
*
|
|
|
|
|
* @ingroup SpecialPage
|
|
|
|
|
*/
|
2011-11-15 02:25:36 +00:00
|
|
|
class SpecialBlock extends FormSpecialPage {
|
2020-05-08 22:31:17 +00:00
|
|
|
/**
|
|
|
|
|
* @var PermissionManager
|
|
|
|
|
*/
|
|
|
|
|
private $permissionManager;
|
|
|
|
|
|
2016-04-29 17:38:35 +00:00
|
|
|
/** @var User|string|null User to be blocked, as passed either by parameter (url?wpTarget=Foo)
|
2019-08-05 17:00:00 +00:00
|
|
|
* or as subpage (Special:Block/Foo)
|
|
|
|
|
*/
|
2011-03-12 22:53:15 +00:00
|
|
|
protected $target;
|
|
|
|
|
|
2019-05-13 14:18:07 +00:00
|
|
|
/** @var int DatabaseBlock::TYPE_ constant */
|
2011-03-12 22:53:15 +00:00
|
|
|
protected $type;
|
|
|
|
|
|
2014-04-19 08:16:52 +00:00
|
|
|
/** @var User|string The previous block target */
|
2011-04-01 23:13:15 +00:00
|
|
|
protected $previousTarget;
|
|
|
|
|
|
2014-04-19 08:16:52 +00:00
|
|
|
/** @var bool Whether the previous submission of the form asked for HideUser */
|
2011-04-01 23:13:15 +00:00
|
|
|
protected $requestedHideUser;
|
|
|
|
|
|
2014-04-19 08:16:52 +00:00
|
|
|
/** @var bool */
|
2011-03-12 22:53:15 +00:00
|
|
|
protected $alreadyBlocked;
|
2011-06-02 19:32:45 +00:00
|
|
|
|
2014-04-19 08:16:52 +00:00
|
|
|
/** @var array */
|
2016-02-17 09:09:32 +00:00
|
|
|
protected $preErrors = [];
|
2011-03-12 22:53:15 +00:00
|
|
|
|
2020-05-08 22:31:17 +00:00
|
|
|
public function __construct( PermissionManager $permissionManager ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
parent::__construct( 'Block', 'block' );
|
2020-05-08 22:31:17 +00:00
|
|
|
|
|
|
|
|
$this->permissionManager = $permissionManager;
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-14 22:35:31 +00:00
|
|
|
public function doesWrites() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 02:25:36 +00:00
|
|
|
/**
|
|
|
|
|
* Checks that the user can unblock themselves if they are trying to do so
|
|
|
|
|
*
|
|
|
|
|
* @param User $user
|
|
|
|
|
* @throws ErrorPageError
|
|
|
|
|
*/
|
|
|
|
|
protected function checkExecutePermissions( User $user ) {
|
2013-02-03 19:28:43 +00:00
|
|
|
parent::checkExecutePermissions( $user );
|
2017-02-20 22:31:04 +00:00
|
|
|
# T17810: blocked admins should have limited access here
|
2011-11-15 02:25:36 +00:00
|
|
|
$status = self::checkUnblockSelf( $this->target, $user );
|
|
|
|
|
if ( $status !== true ) {
|
|
|
|
|
throw new ErrorPageError( 'badaccess', $status );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-27 18:38:14 +00:00
|
|
|
/**
|
|
|
|
|
* We allow certain special cases where user is blocked
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function requiresUnblock() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 02:25:36 +00:00
|
|
|
/**
|
|
|
|
|
* Handle some magic here
|
|
|
|
|
*
|
2014-04-19 08:16:52 +00:00
|
|
|
* @param string $par
|
2011-11-15 02:25:36 +00:00
|
|
|
*/
|
|
|
|
|
protected function setParameter( $par ) {
|
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
|
|
|
|
2014-05-09 19:33:58 +00:00
|
|
|
list( $this->previousTarget, /*...*/ ) =
|
2019-05-13 14:18:07 +00:00
|
|
|
DatabaseBlock::parseTarget( $request->getVal( 'wpPreviousTarget' ) );
|
2011-09-12 08:49:14 +00:00
|
|
|
$this->requestedHideUser = $request->getBool( 'wpHideUser' );
|
2011-11-15 02:25:36 +00:00
|
|
|
}
|
2011-04-01 23:13:15 +00:00
|
|
|
|
2011-11-15 02:25:36 +00:00
|
|
|
/**
|
|
|
|
|
* Customizes the HTMLForm a bit
|
|
|
|
|
*
|
2014-04-19 08:16:52 +00:00
|
|
|
* @param HTMLForm $form
|
2011-11-15 02:25:36 +00:00
|
|
|
*/
|
|
|
|
|
protected function alterForm( HTMLForm $form ) {
|
|
|
|
|
$form->setHeaderText( '' );
|
2014-10-07 23:07:58 +00:00
|
|
|
$form->setSubmitDestructive();
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2011-11-15 02:25:36 +00:00
|
|
|
$msg = $this->alreadyBlocked ? 'ipb-change-block' : 'ipbsubmit';
|
|
|
|
|
$form->setSubmitTextMsg( $msg );
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2015-05-02 11:37:19 +00:00
|
|
|
$this->addHelpLink( 'Help:Blocking users' );
|
2014-08-31 10:25:18 +00:00
|
|
|
|
2011-11-15 02:25:36 +00:00
|
|
|
# Don't need to do anything if the form has been posted
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( !$this->getRequest()->wasPosted() && $this->preErrors ) {
|
2014-12-13 11:08:45 +00:00
|
|
|
$s = $form->formatErrors( $this->preErrors );
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( $s ) {
|
2011-11-15 02:25:36 +00:00
|
|
|
$form->addHeaderText( Html::rawElement(
|
2013-03-25 22:52:41 +00:00
|
|
|
'div',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'class' => 'error' ],
|
2013-03-25 22:52:41 +00:00
|
|
|
$s
|
|
|
|
|
) );
|
2011-11-15 02:25:36 +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
|
|
|
|
2015-07-26 23:44:25 +00:00
|
|
|
protected function getDisplayFormat() {
|
|
|
|
|
return 'ooui';
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
/**
|
|
|
|
|
* Get the HTMLForm descriptor array for the block form
|
2014-04-19 08:16:52 +00:00
|
|
|
* @return array
|
2011-03-12 22:53:15 +00:00
|
|
|
*/
|
2012-08-29 02:34:00 +00:00
|
|
|
protected function getFormFields() {
|
2019-04-02 10:43:37 +00:00
|
|
|
$conf = $this->getConfig();
|
|
|
|
|
$blockAllowsUTEdit = $conf->get( 'BlockAllowsUTEdit' );
|
2017-01-21 18:54:21 +00:00
|
|
|
|
2019-02-27 22:11:40 +00:00
|
|
|
$this->getOutput()->enableOOUI();
|
|
|
|
|
|
2011-09-12 08:49:14 +00:00
|
|
|
$user = $this->getUser();
|
2011-03-12 22:53:15 +00:00
|
|
|
|
2013-04-29 13:48:57 +00:00
|
|
|
$suggestedDurations = self::getSuggestedDurations();
|
|
|
|
|
|
2018-08-27 22:19:37 +00:00
|
|
|
$a = [];
|
|
|
|
|
|
|
|
|
|
$a['Target'] = [
|
|
|
|
|
'type' => 'user',
|
|
|
|
|
'ipallowed' => true,
|
|
|
|
|
'iprange' => true,
|
|
|
|
|
'id' => 'mw-bi-target',
|
|
|
|
|
'size' => '45',
|
|
|
|
|
'autofocus' => true,
|
|
|
|
|
'required' => true,
|
|
|
|
|
'validation-callback' => [ __CLASS__, 'validateTargetField' ],
|
2019-01-07 14:04:54 +00:00
|
|
|
'section' => 'target',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$a['Editing'] = [
|
|
|
|
|
'type' => 'check',
|
|
|
|
|
'label-message' => 'block-prevent-edit',
|
|
|
|
|
'default' => true,
|
|
|
|
|
'section' => 'actions',
|
2018-08-27 22:19:37 +00:00
|
|
|
];
|
2018-02-26 18:07:11 +00:00
|
|
|
|
2020-03-02 16:18:23 +00:00
|
|
|
$a['EditingRestriction'] = [
|
|
|
|
|
'type' => 'radio',
|
|
|
|
|
'cssclass' => 'mw-block-editing-restriction',
|
2020-04-17 13:57:26 +00:00
|
|
|
'default' => 'sitewide',
|
2020-03-02 16:18:23 +00:00
|
|
|
'options' => [
|
|
|
|
|
$this->msg( 'ipb-sitewide' )->escaped() .
|
|
|
|
|
new \OOUI\LabelWidget( [
|
|
|
|
|
'classes' => [ 'oo-ui-inline-help' ],
|
|
|
|
|
'label' => $this->msg( 'ipb-sitewide-help' )->text(),
|
|
|
|
|
] ) => 'sitewide',
|
|
|
|
|
$this->msg( 'ipb-partial' )->escaped() .
|
|
|
|
|
new \OOUI\LabelWidget( [
|
|
|
|
|
'classes' => [ 'oo-ui-inline-help' ],
|
|
|
|
|
'label' => $this->msg( 'ipb-partial-help' )->text(),
|
|
|
|
|
] ) => 'partial',
|
|
|
|
|
],
|
|
|
|
|
'section' => 'actions',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$a['PageRestrictions'] = [
|
|
|
|
|
'type' => 'titlesmultiselect',
|
|
|
|
|
'label' => $this->msg( 'ipb-pages-label' )->text(),
|
|
|
|
|
'exists' => true,
|
|
|
|
|
'max' => 10,
|
|
|
|
|
'cssclass' => 'mw-block-restriction',
|
|
|
|
|
'showMissing' => false,
|
|
|
|
|
'excludeDynamicNamespaces' => true,
|
|
|
|
|
'input' => [
|
|
|
|
|
'autocomplete' => false
|
|
|
|
|
],
|
|
|
|
|
'section' => 'actions',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$a['NamespaceRestrictions'] = [
|
|
|
|
|
'type' => 'namespacesmultiselect',
|
|
|
|
|
'label' => $this->msg( 'ipb-namespaces-label' )->text(),
|
|
|
|
|
'exists' => true,
|
|
|
|
|
'cssclass' => 'mw-block-restriction',
|
|
|
|
|
'input' => [
|
|
|
|
|
'autocomplete' => false
|
|
|
|
|
],
|
|
|
|
|
'section' => 'actions',
|
|
|
|
|
];
|
2018-08-27 22:19:37 +00:00
|
|
|
|
|
|
|
|
$a['CreateAccount'] = [
|
|
|
|
|
'type' => 'check',
|
|
|
|
|
'label-message' => 'ipbcreateaccount',
|
|
|
|
|
'default' => true,
|
2019-01-07 14:04:54 +00:00
|
|
|
'section' => 'actions',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2011-03-12 22:53:15 +00:00
|
|
|
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( self::canBlockEmail( $user ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$a['DisableEmail'] = [
|
2011-03-12 22:53:15 +00:00
|
|
|
'type' => 'check',
|
|
|
|
|
'label-message' => 'ipbemailban',
|
2019-01-07 14:04:54 +00:00
|
|
|
'section' => 'actions',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-02 10:43:37 +00:00
|
|
|
if ( $blockAllowsUTEdit ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$a['DisableUTEdit'] = [
|
2011-03-12 22:53:15 +00:00
|
|
|
'type' => 'check',
|
|
|
|
|
'label-message' => 'ipb-disableusertalk',
|
|
|
|
|
'default' => false,
|
2019-01-07 14:04:54 +00:00
|
|
|
'section' => 'actions',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 04:34:46 +00:00
|
|
|
$defaultExpiry = $this->msg( 'ipb-default-expiry' )->inContentLanguage();
|
|
|
|
|
if ( $this->type === DatabaseBlock::TYPE_RANGE || $this->type === DatabaseBlock::TYPE_IP ) {
|
|
|
|
|
$defaultExpiryIP = $this->msg( 'ipb-default-expiry-ip' )->inContentLanguage();
|
|
|
|
|
if ( !$defaultExpiryIP->isDisabled() ) {
|
|
|
|
|
$defaultExpiry = $defaultExpiryIP;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-07 14:04:54 +00:00
|
|
|
$a['Expiry'] = [
|
|
|
|
|
'type' => 'expiry',
|
|
|
|
|
'required' => true,
|
|
|
|
|
'options' => $suggestedDurations,
|
2019-08-05 04:34:46 +00:00
|
|
|
'default' => $defaultExpiry->text(),
|
2019-01-07 14:04:54 +00:00
|
|
|
'section' => 'expiry',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$a['Reason'] = [
|
|
|
|
|
'type' => 'selectandother',
|
|
|
|
|
// HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
|
|
|
|
|
// (e.g. emojis) count for two each. This limit is overridden in JS to instead count
|
2019-01-04 18:55:11 +00:00
|
|
|
// Unicode codepoints.
|
|
|
|
|
'maxlength' => CommentStore::COMMENT_CHARACTER_LIMIT,
|
2019-01-07 14:04:54 +00:00
|
|
|
'maxlength-unit' => 'codepoints',
|
|
|
|
|
'options-message' => 'ipbreason-dropdown',
|
|
|
|
|
'section' => 'reason',
|
|
|
|
|
];
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$a['AutoBlock'] = [
|
2011-03-12 22:53:15 +00:00
|
|
|
'type' => 'check',
|
|
|
|
|
'label-message' => 'ipbenableautoblock',
|
|
|
|
|
'default' => true,
|
2019-01-07 14:04:54 +00:00
|
|
|
'section' => 'options',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
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
|
2020-05-08 22:31:17 +00:00
|
|
|
if ( $this->permissionManager->userHasRight( $user, 'hideuser' ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$a['HideUser'] = [
|
2011-03-12 22:53:15 +00:00
|
|
|
'type' => 'check',
|
|
|
|
|
'label-message' => 'ipbhidename',
|
|
|
|
|
'cssclass' => 'mw-block-hideuser',
|
2019-01-07 14:04:54 +00:00
|
|
|
'section' => 'options',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Watchlist their user page? (Only if user is logged in)
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( $user->isLoggedIn() ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$a['Watch'] = [
|
2011-03-12 22:53:15 +00:00
|
|
|
'type' => 'check',
|
|
|
|
|
'label-message' => 'ipbwatchuser',
|
2019-01-07 14:04:54 +00:00
|
|
|
'section' => 'options',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$a['HardBlock'] = [
|
2011-03-12 22:53:15 +00:00
|
|
|
'type' => 'check',
|
|
|
|
|
'label-message' => 'ipb-hardblock',
|
|
|
|
|
'default' => false,
|
2019-01-07 14:04:54 +00:00
|
|
|
'section' => 'options',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
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
|
2016-02-17 09:09:32 +00:00
|
|
|
$a['PreviousTarget'] = [
|
2011-03-12 22:53:15 +00:00
|
|
|
'type' => 'hidden',
|
|
|
|
|
'default' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2011-03-12 22:53:15 +00:00
|
|
|
|
2011-04-01 23:13:15 +00:00
|
|
|
# We'll turn this into a checkbox if we need to
|
2016-02-17 09:09:32 +00:00
|
|
|
$a['Confirm'] = [
|
2011-04-01 23:13:15 +00:00
|
|
|
'type' => 'hidden',
|
|
|
|
|
'default' => '',
|
|
|
|
|
'label-message' => 'ipb-confirm',
|
2017-10-03 13:44:30 +00:00
|
|
|
'cssclass' => 'mw-block-confirm',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2011-04-01 23:13:15 +00:00
|
|
|
|
2011-11-15 02:25:36 +00:00
|
|
|
$this->maybeAlterFormDefaults( $a );
|
|
|
|
|
|
2013-12-12 20:18:05 +00:00
|
|
|
// Allow extensions to add more fields
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$this->getHookRunner()->onSpecialBlockModifyFormFields( $this, $a );
|
2013-12-12 20:18:05 +00:00
|
|
|
|
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.
|
2017-08-11 00:23:16 +00:00
|
|
|
* @param array &$fields HTMLForm descriptor array
|
2011-03-12 22:53:15 +00:00
|
|
|
*/
|
2012-08-29 02:34:00 +00:00
|
|
|
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
|
|
|
|
2014-05-30 09:14:54 +00:00
|
|
|
if ( $this->target ) {
|
|
|
|
|
$status = self::validateTarget( $this->target, $this->getUser() );
|
|
|
|
|
if ( !$status->isOK() ) {
|
|
|
|
|
$errors = $status->getErrorsArray();
|
|
|
|
|
$this->preErrors = array_merge( $this->preErrors, $errors );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-01 23:13:15 +00:00
|
|
|
# This won't be
|
|
|
|
|
$fields['PreviousTarget']['default'] = (string)$this->target;
|
|
|
|
|
|
2019-05-13 14:18:07 +00:00
|
|
|
$block = DatabaseBlock::newFromTarget( $this->target );
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2019-03-22 15:16:40 +00:00
|
|
|
// Populate fields if there is a block that is not an autoblock; if it is a range
|
|
|
|
|
// block, only populate the fields if the range is the same as $this->target
|
2019-05-13 14:18:07 +00:00
|
|
|
if ( $block instanceof DatabaseBlock && $block->getType() !== DatabaseBlock::TYPE_AUTO
|
|
|
|
|
&& ( $this->type != DatabaseBlock::TYPE_RANGE
|
2019-03-22 15:16:40 +00:00
|
|
|
|| $block->getTarget() == $this->target )
|
2013-03-25 22:52:41 +00:00
|
|
|
) {
|
2011-03-19 23:47:08 +00:00
|
|
|
$fields['HardBlock']['default'] = $block->isHardblock();
|
Separate out different functionalities of Block::prevents
Block::prevents plays several different roles:
* acts as get/setter for Boolean properties that correspond to
ipb_create_account, ipb_block_email and ipb_allow_usertalk
* calculates whether a block blocks a given right, based on Block
properties, global configs, white/blacklists and anonymous user
rights
* decides whether a block prevents editing of the target's own
user talk page (listed separately because 'editownusertalk' is
not a right)
This patch:
* renames mDisableUsertalk to allowEditUsertalk (and reverses the
value), to match the field ipb_allow_usertalk and make this logic
easier to follow
* renames mCreateAccount to blockCreateAccount, to make it clear
that the flag blocks account creation when true, and make this
logic easier to follow
* decouples the block that is stored in the database (which now
reflects the form that the admin submitted) and the behaviour of
the block on enforcement (since the properties set by the admin
can be overridden by global configs) - so if the global configs
change, the block behaviour could too
* creates get/setters for blockCreateAccount, mBlockEmail and
allowEditUsertalk properties
* creates appliesToRight, exclusively for checking whether the
block blocks a given right, taking into account the block
properties, global configs and anonymous user rights
* creates appliesToUsertalk, for checking whether the block
blocks a user from editing their own talk page. The block is
unaware of the user trying to make the edit, and this user is not
always the same as the block target, e.g. if the block target is
an IP range. Therefore the user's talk page is passed in to this
method. appliesToUsertalk can be called from anywhere where the
user is known
* uses the get/setters wherever Block::prevents was being used as
such
* uses appliesToRight whenever Block::prevents was being used to
determine if the block blocks a given right
* uses appliesToUsertalk in User::isBlockedFrom
Bug: T211578
Bug: T214508
Change-Id: I0e131696419211319082cb454f4f05297e55d22e
2019-02-09 12:17:54 +00:00
|
|
|
$fields['CreateAccount']['default'] = $block->isCreateAccountBlocked();
|
2011-03-21 19:12:41 +00:00
|
|
|
$fields['AutoBlock']['default'] = $block->isAutoblocking();
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( isset( $fields['DisableEmail'] ) ) {
|
Separate out different functionalities of Block::prevents
Block::prevents plays several different roles:
* acts as get/setter for Boolean properties that correspond to
ipb_create_account, ipb_block_email and ipb_allow_usertalk
* calculates whether a block blocks a given right, based on Block
properties, global configs, white/blacklists and anonymous user
rights
* decides whether a block prevents editing of the target's own
user talk page (listed separately because 'editownusertalk' is
not a right)
This patch:
* renames mDisableUsertalk to allowEditUsertalk (and reverses the
value), to match the field ipb_allow_usertalk and make this logic
easier to follow
* renames mCreateAccount to blockCreateAccount, to make it clear
that the flag blocks account creation when true, and make this
logic easier to follow
* decouples the block that is stored in the database (which now
reflects the form that the admin submitted) and the behaviour of
the block on enforcement (since the properties set by the admin
can be overridden by global configs) - so if the global configs
change, the block behaviour could too
* creates get/setters for blockCreateAccount, mBlockEmail and
allowEditUsertalk properties
* creates appliesToRight, exclusively for checking whether the
block blocks a given right, taking into account the block
properties, global configs and anonymous user rights
* creates appliesToUsertalk, for checking whether the block
blocks a user from editing their own talk page. The block is
unaware of the user trying to make the edit, and this user is not
always the same as the block target, e.g. if the block target is
an IP range. Therefore the user's talk page is passed in to this
method. appliesToUsertalk can be called from anywhere where the
user is known
* uses the get/setters wherever Block::prevents was being used as
such
* uses appliesToRight whenever Block::prevents was being used to
determine if the block blocks a given right
* uses appliesToUsertalk in User::isBlockedFrom
Bug: T211578
Bug: T214508
Change-Id: I0e131696419211319082cb454f4f05297e55d22e
2019-02-09 12:17:54 +00:00
|
|
|
$fields['DisableEmail']['default'] = $block->isEmailBlocked();
|
2011-03-15 11:20:15 +00:00
|
|
|
}
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( isset( $fields['HideUser'] ) ) {
|
2019-03-22 15:16:40 +00:00
|
|
|
$fields['HideUser']['default'] = $block->getHideName();
|
2011-03-15 11:20:15 +00:00
|
|
|
}
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( isset( $fields['DisableUTEdit'] ) ) {
|
Separate out different functionalities of Block::prevents
Block::prevents plays several different roles:
* acts as get/setter for Boolean properties that correspond to
ipb_create_account, ipb_block_email and ipb_allow_usertalk
* calculates whether a block blocks a given right, based on Block
properties, global configs, white/blacklists and anonymous user
rights
* decides whether a block prevents editing of the target's own
user talk page (listed separately because 'editownusertalk' is
not a right)
This patch:
* renames mDisableUsertalk to allowEditUsertalk (and reverses the
value), to match the field ipb_allow_usertalk and make this logic
easier to follow
* renames mCreateAccount to blockCreateAccount, to make it clear
that the flag blocks account creation when true, and make this
logic easier to follow
* decouples the block that is stored in the database (which now
reflects the form that the admin submitted) and the behaviour of
the block on enforcement (since the properties set by the admin
can be overridden by global configs) - so if the global configs
change, the block behaviour could too
* creates get/setters for blockCreateAccount, mBlockEmail and
allowEditUsertalk properties
* creates appliesToRight, exclusively for checking whether the
block blocks a given right, taking into account the block
properties, global configs and anonymous user rights
* creates appliesToUsertalk, for checking whether the block
blocks a user from editing their own talk page. The block is
unaware of the user trying to make the edit, and this user is not
always the same as the block target, e.g. if the block target is
an IP range. Therefore the user's talk page is passed in to this
method. appliesToUsertalk can be called from anywhere where the
user is known
* uses the get/setters wherever Block::prevents was being used as
such
* uses appliesToRight whenever Block::prevents was being used to
determine if the block blocks a given right
* uses appliesToUsertalk in User::isBlockedFrom
Bug: T211578
Bug: T214508
Change-Id: I0e131696419211319082cb454f4f05297e55d22e
2019-02-09 12:17:54 +00:00
|
|
|
$fields['DisableUTEdit']['default'] = !$block->isUsertalkEditAllowed();
|
2011-03-15 11:20:15 +00:00
|
|
|
}
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2012-08-08 17:04:10 +00:00
|
|
|
// If the username was hidden (ipb_deleted == 1), don't show the reason
|
2017-02-20 22:31:04 +00:00
|
|
|
// unless this user also has rights to hideuser: T37839
|
2020-05-08 22:31:17 +00:00
|
|
|
if ( !$block->getHideName() || $this->permissionManager
|
2019-08-21 02:01:06 +00:00
|
|
|
->userHasRight( $this->getUser(), 'hideuser' )
|
|
|
|
|
) {
|
2019-10-20 00:04:00 +00:00
|
|
|
$fields['Reason']['default'] = $block->getReasonComment()->text;
|
2012-08-08 17:04:10 +00:00
|
|
|
} else {
|
|
|
|
|
$fields['Reason']['default'] = '';
|
|
|
|
|
}
|
2011-04-01 23:13:15 +00:00
|
|
|
|
2012-08-29 02:34:00 +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
|
|
|
|
2019-03-22 15:16:40 +00:00
|
|
|
if ( $block->getExpiry() == 'infinity' ) {
|
2012-06-06 19:50:19 +00:00
|
|
|
$fields['Expiry']['default'] = 'infinite';
|
2011-03-12 22:53:15 +00:00
|
|
|
} else {
|
2019-03-22 15:16:40 +00:00
|
|
|
$fields['Expiry']['default'] = wfTimestamp( TS_RFC2822, $block->getExpiry() );
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
2020-04-17 13:57:26 +00:00
|
|
|
if ( !$block->isSitewide() ) {
|
|
|
|
|
$fields['EditingRestriction']['default'] = 'partial';
|
|
|
|
|
|
|
|
|
|
$pageRestrictions = [];
|
|
|
|
|
$namespaceRestrictions = [];
|
|
|
|
|
foreach ( $block->getRestrictions() as $restriction ) {
|
|
|
|
|
if ( $restriction instanceof PageRestriction && $restriction->getTitle() ) {
|
|
|
|
|
$pageRestrictions[] = $restriction->getTitle()->getPrefixedText();
|
|
|
|
|
} elseif ( $restriction instanceof NamespaceRestriction ) {
|
|
|
|
|
$namespaceRestrictions[] = $restriction->getValue();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sort the restrictions so they are in alphabetical order.
|
|
|
|
|
sort( $pageRestrictions );
|
|
|
|
|
$fields['PageRestrictions']['default'] = implode( "\n", $pageRestrictions );
|
|
|
|
|
sort( $namespaceRestrictions );
|
|
|
|
|
$fields['NamespaceRestrictions']['default'] = implode( "\n", $namespaceRestrictions );
|
|
|
|
|
|
|
|
|
|
if (
|
2020-06-15 10:46:22 +00:00
|
|
|
// @phan-suppress-next-line PhanImpossibleCondition
|
2020-04-17 13:57:26 +00:00
|
|
|
empty( $pageRestrictions ) &&
|
2020-06-15 10:46:22 +00:00
|
|
|
// @phan-suppress-next-line PhanImpossibleCondition
|
2020-04-17 13:57:26 +00:00
|
|
|
empty( $namespaceRestrictions )
|
|
|
|
|
) {
|
|
|
|
|
$fields['Editing']['default'] = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-01 23:13:15 +00:00
|
|
|
$this->alreadyBlocked = true;
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->preErrors[] = [ 'ipb-needreblock', wfEscapeWikiText( (string)$block->getTarget() ) ];
|
2011-04-01 23:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-02 16:33:11 +00:00
|
|
|
if ( $this->alreadyBlocked || $this->getRequest()->wasPosted()
|
|
|
|
|
|| $this->getRequest()->getCheck( 'wpCreateAccount' )
|
|
|
|
|
) {
|
|
|
|
|
$this->getOutput()->addJsConfigVars( 'wgCreateAccountDirty', true );
|
2019-03-12 16:42:03 +00:00
|
|
|
}
|
|
|
|
|
|
2011-04-01 23:13:15 +00:00
|
|
|
# We always need confirmation to do HideUser
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( $this->requestedHideUser ) {
|
2011-04-01 23:13:15 +00:00
|
|
|
$fields['Confirm']['type'] = 'check';
|
|
|
|
|
unset( $fields['Confirm']['default'] );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->preErrors[] = [ 'ipb-confirmhideuser', 'ipb-confirmaction' ];
|
2011-04-01 23:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Or if the user is trying to block themselves
|
2012-08-29 02:34:00 +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'] );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->preErrors[] = [ 'ipb-blockingself', 'ipb-confirmaction' ];
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-03-12 22:53:15 +00:00
|
|
|
* Add header elements like block log entries, etc.
|
2014-04-19 08:16:52 +00:00
|
|
|
* @return string
|
2011-03-12 21:54:35 +00:00
|
|
|
*/
|
2012-08-29 02:34:00 +00:00
|
|
|
protected function preText() {
|
2019-01-03 19:04:48 +00:00
|
|
|
$this->getOutput()->addModuleStyles( [
|
|
|
|
|
'mediawiki.widgets.TagMultiselectWidget.styles',
|
|
|
|
|
'mediawiki.special',
|
|
|
|
|
] );
|
2015-07-26 23:44:25 +00:00
|
|
|
$this->getOutput()->addModules( [ 'mediawiki.special.block' ] );
|
2012-07-24 20:59:42 +00:00
|
|
|
|
2015-12-31 20:24:39 +00:00
|
|
|
$blockCIDRLimit = $this->getConfig()->get( 'BlockCIDRLimit' );
|
|
|
|
|
$text = $this->msg( 'blockiptext', $blockCIDRLimit['IPv4'], $blockCIDRLimit['IPv6'] )->parse();
|
2011-03-12 22:53:15 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$otherBlockMessages = [];
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( $this->target !== null ) {
|
2016-04-29 17:38:35 +00:00
|
|
|
$targetName = $this->target;
|
|
|
|
|
if ( $this->target instanceof User ) {
|
|
|
|
|
$targetName = $this->target->getName();
|
|
|
|
|
}
|
2011-03-12 22:53:15 +00:00
|
|
|
# Get other blocks, i.e. from GlobalBlocking or TorBlock extension
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$this->getHookRunner()->onOtherBlockLogLink(
|
|
|
|
|
$otherBlockMessages, $targetName );
|
2011-03-12 22:53:15 +00:00
|
|
|
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( count( $otherBlockMessages ) ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
$s = Html::rawElement(
|
|
|
|
|
'h2',
|
2016-02-17 09:09:32 +00:00
|
|
|
[],
|
2011-12-28 19:15:10 +00:00
|
|
|
$this->msg( 'ipb-otherblocks-header', count( $otherBlockMessages ) )->parse()
|
2011-03-12 22:53:15 +00:00
|
|
|
) . "\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
|
|
|
|
2012-08-29 02:34:00 +00:00
|
|
|
foreach ( $otherBlockMessages as $link ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$list .= Html::rawElement( 'li', [], $link ) . "\n";
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
$s .= Html::rawElement(
|
|
|
|
|
'ul',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'class' => 'mw-blockip-alreadyblocked' ],
|
2011-03-12 22:53:15 +00:00
|
|
|
$list
|
|
|
|
|
) . "\n";
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-11-15 02:25:36 +00:00
|
|
|
$text .= $s;
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-15 02:25:36 +00:00
|
|
|
return $text;
|
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
|
2012-01-03 15:36:46 +00:00
|
|
|
* @return string
|
2011-03-12 21:54:35 +00:00
|
|
|
*/
|
2012-08-29 02:34:00 +00:00
|
|
|
protected function postText() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$links = [];
|
2012-06-26 09:09:53 +00:00
|
|
|
|
2015-10-10 06:41:43 +00:00
|
|
|
$this->getOutput()->addModuleStyles( 'mediawiki.special' );
|
|
|
|
|
|
2016-11-30 00:05:22 +00:00
|
|
|
$linkRenderer = $this->getLinkRenderer();
|
2011-03-12 22:53:15 +00:00
|
|
|
# Link to the user's contributions, if applicable
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( $this->target instanceof User ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
$contribsPage = SpecialPage::getTitleFor( 'Contributions', $this->target->getName() );
|
2016-11-30 00:05:22 +00:00
|
|
|
$links[] = $linkRenderer->makeLink(
|
2011-03-12 22:53:15 +00:00
|
|
|
$contribsPage,
|
2016-11-30 00:05:22 +00:00
|
|
|
$this->msg( 'ipb-blocklist-contribs', $this->target->getName() )->text()
|
2011-03-12 22:53:15 +00:00
|
|
|
);
|
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
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( $this->target instanceof User ) {
|
2014-05-09 19:33:58 +00:00
|
|
|
$message = $this->msg(
|
|
|
|
|
'ipb-unblock-addr',
|
|
|
|
|
wfEscapeWikiText( $this->target->getName() )
|
|
|
|
|
)->parse();
|
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-12-28 19:15:10 +00:00
|
|
|
$message = $this->msg( 'ipb-unblock' )->parse();
|
2011-03-13 21:33:52 +00:00
|
|
|
$list = SpecialPage::getTitleFor( 'Unblock' );
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
2016-11-30 00:05:22 +00:00
|
|
|
$links[] = $linkRenderer->makeKnownLink(
|
|
|
|
|
$list,
|
|
|
|
|
new HtmlArmor( $message )
|
|
|
|
|
);
|
2011-03-12 22:53:15 +00:00
|
|
|
|
|
|
|
|
# Link to the block list
|
2016-11-30 00:05:22 +00:00
|
|
|
$links[] = $linkRenderer->makeKnownLink(
|
2011-03-14 16:09:44 +00:00
|
|
|
SpecialPage::getTitleFor( 'BlockList' ),
|
2016-11-30 00:05:22 +00:00
|
|
|
$this->msg( 'ipb-blocklist' )->text()
|
2011-03-12 22:53:15 +00:00
|
|
|
);
|
|
|
|
|
|
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
|
2020-05-08 22:31:17 +00:00
|
|
|
if ( $this->permissionManager->userHasRight( $user, 'editinterface' ) ) {
|
2016-11-30 00:05:22 +00:00
|
|
|
$links[] = $linkRenderer->makeKnownLink(
|
2014-12-13 19:55:13 +00:00
|
|
|
$this->msg( 'ipbreason-dropdown' )->inContentLanguage()->getTitle(),
|
2016-11-30 00:05:22 +00:00
|
|
|
$this->msg( 'ipb-edit-dropdown' )->text(),
|
2016-02-17 09:09:32 +00:00
|
|
|
[],
|
|
|
|
|
[ 'action' => 'edit' ]
|
2011-03-12 22:53:15 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-28 21:11:10 +00:00
|
|
|
$text = Html::rawElement(
|
2011-03-12 22:53:15 +00:00
|
|
|
'p',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'class' => 'mw-ipb-conveniencelinks' ],
|
2011-11-21 16:13:21 +00:00
|
|
|
$this->getLanguage()->pipeList( $links )
|
2011-11-15 02:25:36 +00:00
|
|
|
);
|
2011-03-12 22:53:15 +00:00
|
|
|
|
2012-03-14 01:42:14 +00:00
|
|
|
$userTitle = self::getTargetUserTitle( $this->target );
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( $userTitle ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
# Get relevant extracts from the block and suppression logs, if possible
|
|
|
|
|
$out = '';
|
|
|
|
|
|
|
|
|
|
LogEventsList::showLogExtract(
|
|
|
|
|
$out,
|
|
|
|
|
'block',
|
2012-03-14 01:42:14 +00:00
|
|
|
$userTitle,
|
2011-03-12 22:53:15 +00:00
|
|
|
'',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2011-03-12 22:53:15 +00:00
|
|
|
'lim' => 10,
|
2016-02-17 09:09:32 +00:00
|
|
|
'msgKey' => [ 'blocklog-showlog', $userTitle->getText() ],
|
2011-03-12 22:53:15 +00:00
|
|
|
'showIfEmpty' => false
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
2011-03-12 22:53:15 +00:00
|
|
|
);
|
2011-11-15 02:25:36 +00:00
|
|
|
$text .= $out;
|
2011-03-12 22:53:15 +00:00
|
|
|
|
|
|
|
|
# Add suppression block entries if allowed
|
2020-05-08 22:31:17 +00:00
|
|
|
if ( $this->permissionManager->userHasRight( $user, 'suppressionlog' ) ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
LogEventsList::showLogExtract(
|
|
|
|
|
$out,
|
|
|
|
|
'suppress',
|
2012-03-14 01:42:14 +00:00
|
|
|
$userTitle,
|
2011-03-12 22:53:15 +00:00
|
|
|
'',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2011-03-12 22:53:15 +00:00
|
|
|
'lim' => 10,
|
2016-02-17 09:09:32 +00:00
|
|
|
'conds' => [ 'log_action' => [ 'block', 'reblock', 'unblock' ] ],
|
|
|
|
|
'msgKey' => [ 'blocklog-showsuppresslog', $userTitle->getText() ],
|
2011-03-12 22:53:15 +00:00
|
|
|
'showIfEmpty' => false
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
2011-03-12 22:53:15 +00:00
|
|
|
);
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2011-11-15 02:25:36 +00:00
|
|
|
$text .= $out;
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
2011-11-15 02:25:36 +00:00
|
|
|
|
|
|
|
|
return $text;
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-14 01:42:14 +00:00
|
|
|
/**
|
|
|
|
|
* Get a user page target for things like logs.
|
|
|
|
|
* This handles account and IP range targets.
|
2014-04-19 08:16:52 +00:00
|
|
|
* @param User|string $target
|
2012-03-14 01:42:14 +00:00
|
|
|
* @return Title|null
|
|
|
|
|
*/
|
|
|
|
|
protected static function getTargetUserTitle( $target ) {
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( $target instanceof User ) {
|
2012-03-14 01:42:14 +00:00
|
|
|
return $target->getUserPage();
|
2019-06-25 18:53:15 +00:00
|
|
|
} elseif ( IPUtils::isIPAddress( $target ) ) {
|
2012-03-14 01:42:14 +00:00
|
|
|
return Title::makeTitleSafe( NS_USER, $target );
|
|
|
|
|
}
|
2013-04-14 17:27:14 +00:00
|
|
|
|
2012-03-14 01:42:14 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
2019-05-13 14:18:07 +00:00
|
|
|
* @todo Should be in DatabaseBlock.php?
|
2014-07-24 17:43:44 +00:00
|
|
|
* @param string $par Subpage parameter passed to setup, or data value from
|
2011-03-12 22:53:15 +00:00
|
|
|
* the HTMLForm
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param WebRequest|null $request Optionally try and get data from a request too
|
2019-05-13 14:18:07 +00:00
|
|
|
* @return array [ User|string|null, DatabaseBlock::TYPE_ constant|null ]
|
2019-03-22 01:12:50 +00:00
|
|
|
* @phan-return array{0:User|string|null,1:int|null}
|
2011-03-12 21:54:35 +00:00
|
|
|
*/
|
2012-08-29 02:34:00 +00:00
|
|
|
public static function getTargetAndType( $par, WebRequest $request = null ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
$i = 0;
|
|
|
|
|
$target = null;
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2013-03-25 22:52:41 +00:00
|
|
|
while ( true ) {
|
|
|
|
|
switch ( $i++ ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
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!
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( $request instanceof WebRequest ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
$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:
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( $request instanceof WebRequest ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
$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
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( $request instanceof WebRequest ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
$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
|
|
|
|
2019-05-13 14:18:07 +00:00
|
|
|
list( $target, $type ) = DatabaseBlock::parseTarget( $target );
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( $type !== null ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ $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
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ null, null ];
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
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
|
2014-04-19 08:16:52 +00:00
|
|
|
* @param string $value
|
|
|
|
|
* @param array $alldata
|
|
|
|
|
* @param HTMLForm $form
|
2020-05-24 18:56:45 +00:00
|
|
|
* @return Message|true
|
2011-03-13 10:02:56 +00:00
|
|
|
*/
|
2011-11-13 07:25:56 +00:00
|
|
|
public static function validateTargetField( $value, $alldata, $form ) {
|
2012-11-03 04:56:24 +00:00
|
|
|
$status = self::validateTarget( $value, $form->getUser() );
|
|
|
|
|
if ( !$status->isOK() ) {
|
|
|
|
|
$errors = $status->getErrorsArray();
|
2013-04-14 17:27:14 +00:00
|
|
|
|
2018-06-08 02:58:35 +00:00
|
|
|
return $form->msg( ...$errors[0] );
|
2012-11-03 04:56:24 +00:00
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Validate a block target.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.21
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $value Block target to check
|
2012-11-03 04:56:24 +00:00
|
|
|
* @param User $user Performer of the block
|
|
|
|
|
* @return Status
|
|
|
|
|
*/
|
|
|
|
|
public static function validateTarget( $value, User $user ) {
|
2011-03-13 09:57:02 +00:00
|
|
|
global $wgBlockCIDRLimit;
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2013-04-14 19:18:38 +00:00
|
|
|
/** @var User $target */
|
2011-03-13 14:41:57 +00:00
|
|
|
list( $target, $type ) = self::getTargetAndType( $value );
|
2012-11-03 04:56:24 +00:00
|
|
|
$status = Status::newGood( $target );
|
2011-03-12 22:53:15 +00:00
|
|
|
|
2019-05-13 14:18:07 +00:00
|
|
|
if ( $type == DatabaseBlock::TYPE_USER ) {
|
2012-11-03 04:56:24 +00:00
|
|
|
if ( $target->isAnon() ) {
|
|
|
|
|
$status->fatal(
|
|
|
|
|
'nosuchusershort',
|
|
|
|
|
wfEscapeWikiText( $target->getName() )
|
|
|
|
|
);
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
2012-11-03 04:56:24 +00:00
|
|
|
$unblockStatus = self::checkUnblockSelf( $target, $user );
|
|
|
|
|
if ( $unblockStatus !== true ) {
|
|
|
|
|
$status->fatal( 'badaccess', $unblockStatus );
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
2019-05-13 14:18:07 +00:00
|
|
|
} elseif ( $type == DatabaseBlock::TYPE_RANGE ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
list( $ip, $range ) = explode( '/', $target, 2 );
|
|
|
|
|
|
2012-11-03 04:56:24 +00:00
|
|
|
if (
|
2019-06-25 18:53:15 +00:00
|
|
|
( IPUtils::isIPv4( $ip ) && $wgBlockCIDRLimit['IPv4'] == 32 ) ||
|
|
|
|
|
( IPUtils::isIPv6( $ip ) && $wgBlockCIDRLimit['IPv6'] == 128 )
|
2012-11-03 04:56:24 +00:00
|
|
|
) {
|
|
|
|
|
// Range block effectively disabled
|
|
|
|
|
$status->fatal( 'range_block_disabled' );
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
2012-11-03 04:56:24 +00:00
|
|
|
if (
|
2019-06-25 18:53:15 +00:00
|
|
|
( IPUtils::isIPv4( $ip ) && $range > 32 ) ||
|
|
|
|
|
( IPUtils::isIPv6( $ip ) && $range > 128 )
|
2012-11-03 04:56:24 +00:00
|
|
|
) {
|
|
|
|
|
// Dodgy range
|
|
|
|
|
$status->fatal( 'ip_range_invalid' );
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
2019-06-25 18:53:15 +00:00
|
|
|
if ( IPUtils::isIPv4( $ip ) && $range < $wgBlockCIDRLimit['IPv4'] ) {
|
2012-11-03 04:56:24 +00:00
|
|
|
$status->fatal( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv4'] );
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
2019-06-25 18:53:15 +00:00
|
|
|
if ( IPUtils::isIPv6( $ip ) && $range < $wgBlockCIDRLimit['IPv6'] ) {
|
2012-11-03 04:56:24 +00:00
|
|
|
$status->fatal( 'ip_range_toolarge', $wgBlockCIDRLimit['IPv6'] );
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
2019-05-13 14:18:07 +00:00
|
|
|
} elseif ( $type == DatabaseBlock::TYPE_IP ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
# All is well
|
|
|
|
|
} else {
|
2012-11-03 04:56:24 +00:00
|
|
|
$status->fatal( 'badipaddress' );
|
2011-03-12 22:51:48 +00:00
|
|
|
}
|
2011-03-13 14:41:57 +00:00
|
|
|
|
2012-11-03 04:56:24 +00:00
|
|
|
return $status;
|
2011-03-13 09:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-13 07:25:56 +00:00
|
|
|
/**
|
2015-07-27 14:23:24 +00:00
|
|
|
* Given the form data, actually implement a block. This is also called from ApiBlock.
|
|
|
|
|
*
|
2014-04-19 08:16:52 +00:00
|
|
|
* @param array $data
|
|
|
|
|
* @param IContextSource $context
|
2019-06-03 19:11:10 +00:00
|
|
|
* @return bool|array
|
2011-03-13 09:57:02 +00:00
|
|
|
*/
|
2012-08-29 02:34:00 +00:00
|
|
|
public static function processForm( array $data, IContextSource $context ) {
|
2011-11-13 07:25:56 +00:00
|
|
|
$performer = $context->getUser();
|
2020-03-02 16:18:23 +00:00
|
|
|
$isPartialBlock = isset( $data['EditingRestriction'] ) &&
|
2019-01-14 14:21:50 +00:00
|
|
|
$data['EditingRestriction'] === 'partial';
|
2011-03-13 09:57:02 +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
|
2016-02-17 09:09:32 +00:00
|
|
|
$data['Confirm'] = !in_array( $data['Confirm'], [ '', '0', null, false ], true );
|
2011-04-01 23:13:15 +00:00
|
|
|
|
2013-04-14 19:18:38 +00:00
|
|
|
/** @var User $target */
|
2011-03-13 14:41:57 +00:00
|
|
|
list( $target, $type ) = self::getTargetAndType( $data['Target'] );
|
2019-05-13 14:18:07 +00:00
|
|
|
if ( $type == DatabaseBlock::TYPE_USER ) {
|
2011-03-13 14:41:57 +00:00
|
|
|
$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'
|
2011-12-20 10:15:18 +00:00
|
|
|
# permission anyway, although the code does allow for it.
|
|
|
|
|
# Note: Important to use $target instead of $data['Target']
|
|
|
|
|
# since both $data['PreviousTarget'] and $target are normalized
|
2014-12-12 08:41:27 +00:00
|
|
|
# but $data['target'] gets overridden by (non-normalized) request variable
|
2011-12-20 10:15:18 +00:00
|
|
|
# from previous request.
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( $target === $performer->getName() &&
|
2013-03-25 22:52:41 +00:00
|
|
|
( $data['PreviousTarget'] !== $target || !$data['Confirm'] )
|
|
|
|
|
) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ 'ipb-blockingself', 'ipb-confirmaction' ];
|
2011-03-30 18:00:11 +00:00
|
|
|
}
|
2019-05-13 14:18:07 +00:00
|
|
|
} elseif ( $type == DatabaseBlock::TYPE_RANGE ) {
|
2016-06-09 21:53:47 +00:00
|
|
|
$user = null;
|
2011-03-13 14:41:57 +00:00
|
|
|
$userId = 0;
|
2019-05-13 14:18:07 +00:00
|
|
|
} elseif ( $type == DatabaseBlock::TYPE_IP ) {
|
2016-06-09 21:53:47 +00:00
|
|
|
$user = null;
|
2011-03-13 14:41:57 +00:00
|
|
|
$target = $target->getName();
|
|
|
|
|
$userId = 0;
|
|
|
|
|
} else {
|
|
|
|
|
# This should have been caught in the form field validation
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ 'badipaddress' ];
|
2011-03-13 14:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-03 19:10:46 +00:00
|
|
|
// Reason, to be passed to the block object. For default values of reason, see
|
|
|
|
|
// HTMLSelectAndOtherField::getDefault
|
|
|
|
|
// @phan-suppress-next-line PhanPluginDuplicateConditionalNullCoalescing
|
|
|
|
|
$blockReason = isset( $data['Reason'][0] ) ? $data['Reason'][0] : '';
|
|
|
|
|
|
2016-01-07 16:21:57 +00:00
|
|
|
$expiryTime = self::parseExpiryInput( $data['Expiry'] );
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
// an expiry time is needed
|
|
|
|
|
( strlen( $data['Expiry'] ) == 0 ) ||
|
|
|
|
|
// can't be a larger string as 50 (it should be a time format in any way)
|
|
|
|
|
( strlen( $data['Expiry'] ) > 50 ) ||
|
|
|
|
|
// check, if the time could be parsed
|
|
|
|
|
!$expiryTime
|
2013-03-25 22:52:41 +00:00
|
|
|
) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ 'ipb_expiry_invalid' ];
|
2011-03-12 22:51:48 +00:00
|
|
|
}
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2016-01-07 16:21:57 +00:00
|
|
|
// an expiry time should be in the future, not in the
|
|
|
|
|
// past (wouldn't make any sense) - bug T123069
|
|
|
|
|
if ( $expiryTime < wfTimestampNow() ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ 'ipb_expiry_old' ];
|
2016-01-07 16:21:57 +00:00
|
|
|
}
|
|
|
|
|
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( !isset( $data['DisableEmail'] ) ) {
|
2011-03-22 11:14:11 +00:00
|
|
|
$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
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( !isset( $data['HideUser'] ) ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
$data['HideUser'] = false;
|
|
|
|
|
}
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( $data['HideUser'] ) {
|
2019-08-21 02:01:06 +00:00
|
|
|
if ( !MediaWikiServices::getInstance()
|
|
|
|
|
->getPermissionManager()
|
|
|
|
|
->userHasRight( $performer, 'hideuser' )
|
|
|
|
|
) {
|
2011-03-12 22:53:15 +00:00
|
|
|
# this codepath is unreachable except by a malicious user spoofing forms,
|
2015-09-15 22:38:15 +00:00
|
|
|
# or by race conditions (user has hideuser and block rights, loads block form,
|
|
|
|
|
# and loses hideuser rights before submission); so need to fail completely
|
2011-03-12 22:53:15 +00:00
|
|
|
# rather than just silently disable hiding
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ 'badaccess-group0' ];
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 14:21:50 +00:00
|
|
|
if ( $isPartialBlock ) {
|
|
|
|
|
return [ 'ipb_hide_partial' ];
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
# Recheck params here...
|
2019-07-30 02:15:56 +00:00
|
|
|
$hideUserContribLimit = $context->getConfig()->get( 'HideUserContribLimit' );
|
2019-05-13 14:18:07 +00:00
|
|
|
if ( $type != DatabaseBlock::TYPE_USER ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
$data['HideUser'] = false; # IP users should not be hidden
|
2014-06-18 02:45:32 +00:00
|
|
|
} elseif ( !wfIsInfinity( $data['Expiry'] ) ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
# Bad expiry.
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ 'ipb_expiry_temp' ];
|
2019-07-30 02:15:56 +00:00
|
|
|
} elseif ( $hideUserContribLimit !== false
|
|
|
|
|
&& $user->getEditCount() > $hideUserContribLimit
|
2013-12-17 18:56:33 +00:00
|
|
|
) {
|
2011-03-12 22:53:15 +00:00
|
|
|
# Typically, the user should have a handful of edits.
|
|
|
|
|
# Disallow hiding users with many edits for performance.
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ [ 'ipb_hide_invalid',
|
2019-07-30 02:15:56 +00:00
|
|
|
Message::numParam( $hideUserContribLimit ) ] ];
|
2012-08-29 02:34:00 +00:00
|
|
|
} elseif ( !$data['Confirm'] ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ 'ipb-confirmhideuser', 'ipb-confirmaction' ];
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-15 13:10:56 +00:00
|
|
|
// Check whether the user can edit their own user talk page.
|
2019-07-30 02:15:56 +00:00
|
|
|
$blockAllowsUTEdit = $context->getConfig()->get( 'BlockAllowsUTEdit' );
|
2020-05-15 13:10:56 +00:00
|
|
|
$isUserTalkNamespaceBlock = !$isPartialBlock ||
|
|
|
|
|
in_array( NS_USER_TALK, explode( "\n", $data['NamespaceRestrictions'] ) );
|
|
|
|
|
if ( $isUserTalkNamespaceBlock ) {
|
|
|
|
|
// If the block blocks the user talk namespace, disallow own user talk edit if
|
|
|
|
|
// the global config disallows it; otherwise use the form field value.
|
|
|
|
|
$userTalkEditAllowed = $blockAllowsUTEdit ? !$data['DisableUTEdit'] : false;
|
|
|
|
|
} else {
|
|
|
|
|
// If the block doesn't block the user talk namespace, then it can't block own
|
|
|
|
|
// user talk edit, regardless of the config or field (T210475). Return error
|
|
|
|
|
// message if the field tries to disallow own user talk edit.
|
|
|
|
|
if ( isset( $data['DisableUTEdit'] ) && $data['DisableUTEdit'] ) {
|
|
|
|
|
return [ 'ipb-prevent-user-talk-edit' ];
|
|
|
|
|
}
|
|
|
|
|
$userTalkEditAllowed = true;
|
2019-07-30 02:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
2020-05-02 00:30:47 +00:00
|
|
|
// A block is empty if it is a partial block, the page restrictions are empty, the
|
|
|
|
|
// namespace restrictions are empty, and none of the actions are enabled
|
|
|
|
|
if ( $isPartialBlock &&
|
|
|
|
|
!( isset( $data['PageRestrictions'] ) && $data['PageRestrictions'] !== '' ) &&
|
|
|
|
|
!( isset( $data['NamespaceRestrictions'] ) && $data['NamespaceRestrictions'] !== '' ) &&
|
|
|
|
|
$data['DisableEmail'] === false &&
|
2020-05-15 13:10:56 +00:00
|
|
|
( $userTalkEditAllowed || !$blockAllowsUTEdit ) &&
|
2020-05-02 00:30:47 +00:00
|
|
|
!$data['CreateAccount']
|
|
|
|
|
) {
|
|
|
|
|
return [ 'ipb-empty-block' ];
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-21 19:12:41 +00:00
|
|
|
# Create block object.
|
2019-05-13 14:18:07 +00:00
|
|
|
$block = new DatabaseBlock();
|
2011-03-21 19:12:41 +00:00
|
|
|
$block->setTarget( $target );
|
2011-11-13 07:25:56 +00:00
|
|
|
$block->setBlocker( $performer );
|
2020-03-03 19:10:46 +00:00
|
|
|
$block->setReason( $blockReason );
|
2019-03-22 15:16:40 +00:00
|
|
|
$block->setExpiry( $expiryTime );
|
Separate out different functionalities of Block::prevents
Block::prevents plays several different roles:
* acts as get/setter for Boolean properties that correspond to
ipb_create_account, ipb_block_email and ipb_allow_usertalk
* calculates whether a block blocks a given right, based on Block
properties, global configs, white/blacklists and anonymous user
rights
* decides whether a block prevents editing of the target's own
user talk page (listed separately because 'editownusertalk' is
not a right)
This patch:
* renames mDisableUsertalk to allowEditUsertalk (and reverses the
value), to match the field ipb_allow_usertalk and make this logic
easier to follow
* renames mCreateAccount to blockCreateAccount, to make it clear
that the flag blocks account creation when true, and make this
logic easier to follow
* decouples the block that is stored in the database (which now
reflects the form that the admin submitted) and the behaviour of
the block on enforcement (since the properties set by the admin
can be overridden by global configs) - so if the global configs
change, the block behaviour could too
* creates get/setters for blockCreateAccount, mBlockEmail and
allowEditUsertalk properties
* creates appliesToRight, exclusively for checking whether the
block blocks a given right, taking into account the block
properties, global configs and anonymous user rights
* creates appliesToUsertalk, for checking whether the block
blocks a user from editing their own talk page. The block is
unaware of the user trying to make the edit, and this user is not
always the same as the block target, e.g. if the block target is
an IP range. Therefore the user's talk page is passed in to this
method. appliesToUsertalk can be called from anywhere where the
user is known
* uses the get/setters wherever Block::prevents was being used as
such
* uses appliesToRight whenever Block::prevents was being used to
determine if the block blocks a given right
* uses appliesToUsertalk in User::isBlockedFrom
Bug: T211578
Bug: T214508
Change-Id: I0e131696419211319082cb454f4f05297e55d22e
2019-02-09 12:17:54 +00:00
|
|
|
$block->isCreateAccountBlocked( $data['CreateAccount'] );
|
2019-07-30 02:15:56 +00:00
|
|
|
$block->isUsertalkEditAllowed( $userTalkEditAllowed );
|
Separate out different functionalities of Block::prevents
Block::prevents plays several different roles:
* acts as get/setter for Boolean properties that correspond to
ipb_create_account, ipb_block_email and ipb_allow_usertalk
* calculates whether a block blocks a given right, based on Block
properties, global configs, white/blacklists and anonymous user
rights
* decides whether a block prevents editing of the target's own
user talk page (listed separately because 'editownusertalk' is
not a right)
This patch:
* renames mDisableUsertalk to allowEditUsertalk (and reverses the
value), to match the field ipb_allow_usertalk and make this logic
easier to follow
* renames mCreateAccount to blockCreateAccount, to make it clear
that the flag blocks account creation when true, and make this
logic easier to follow
* decouples the block that is stored in the database (which now
reflects the form that the admin submitted) and the behaviour of
the block on enforcement (since the properties set by the admin
can be overridden by global configs) - so if the global configs
change, the block behaviour could too
* creates get/setters for blockCreateAccount, mBlockEmail and
allowEditUsertalk properties
* creates appliesToRight, exclusively for checking whether the
block blocks a given right, taking into account the block
properties, global configs and anonymous user rights
* creates appliesToUsertalk, for checking whether the block
blocks a user from editing their own talk page. The block is
unaware of the user trying to make the edit, and this user is not
always the same as the block target, e.g. if the block target is
an IP range. Therefore the user's talk page is passed in to this
method. appliesToUsertalk can be called from anywhere where the
user is known
* uses the get/setters wherever Block::prevents was being used as
such
* uses appliesToRight whenever Block::prevents was being used to
determine if the block blocks a given right
* uses appliesToUsertalk in User::isBlockedFrom
Bug: T211578
Bug: T214508
Change-Id: I0e131696419211319082cb454f4f05297e55d22e
2019-02-09 12:17:54 +00:00
|
|
|
$block->isEmailBlocked( $data['DisableEmail'] );
|
2011-03-21 19:12:41 +00:00
|
|
|
$block->isHardblock( $data['HardBlock'] );
|
|
|
|
|
$block->isAutoblocking( $data['AutoBlock'] );
|
2019-03-22 15:16:40 +00:00
|
|
|
$block->setHideName( $data['HideUser'] );
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2019-01-14 14:21:50 +00:00
|
|
|
if ( $isPartialBlock ) {
|
|
|
|
|
$block->isSitewide( false );
|
2018-08-27 22:19:37 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$reason = [ 'hookaborted' ];
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
if ( !Hooks::runner()->onBlockIp( $block, $performer, $reason ) ) {
|
2014-01-18 21:31:47 +00:00
|
|
|
return $reason;
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
2018-12-14 21:08:40 +00:00
|
|
|
$pageRestrictions = [];
|
|
|
|
|
$namespaceRestrictions = [];
|
2020-03-02 16:18:23 +00:00
|
|
|
if ( isset( $data['PageRestrictions'] ) && $data['PageRestrictions'] !== '' ) {
|
|
|
|
|
$pageRestrictions = array_map( function ( $text ) {
|
|
|
|
|
$title = Title::newFromText( $text );
|
|
|
|
|
// Use the link cache since the title has already been loaded when
|
|
|
|
|
// the field was validated.
|
|
|
|
|
$restriction = new PageRestriction( 0, $title->getArticleID() );
|
|
|
|
|
$restriction->setTitle( $title );
|
|
|
|
|
return $restriction;
|
|
|
|
|
}, explode( "\n", $data['PageRestrictions'] ) );
|
2018-08-27 22:19:37 +00:00
|
|
|
}
|
2020-03-02 16:18:23 +00:00
|
|
|
if ( isset( $data['NamespaceRestrictions'] ) && $data['NamespaceRestrictions'] !== '' ) {
|
|
|
|
|
$namespaceRestrictions = array_map( function ( $id ) {
|
|
|
|
|
return new NamespaceRestriction( 0, $id );
|
|
|
|
|
}, explode( "\n", $data['NamespaceRestrictions'] ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$restrictions = ( array_merge( $pageRestrictions, $namespaceRestrictions ) );
|
|
|
|
|
$block->setRestrictions( $restrictions );
|
2018-08-27 22:19:37 +00:00
|
|
|
|
2016-06-09 21:53:47 +00:00
|
|
|
$priorBlock = null;
|
2011-03-12 22:53:15 +00:00
|
|
|
# Try to insert block. Is there a conflicting block?
|
2011-03-22 11:22:15 +00:00
|
|
|
$status = $block->insert();
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( !$status ) {
|
2012-04-14 21:43:49 +00:00
|
|
|
# Indicates whether the user is confirming the block and is aware of
|
|
|
|
|
# the conflict (did not change the block target in the meantime)
|
|
|
|
|
$blockNotConfirmed = !$data['Confirm'] || ( array_key_exists( 'PreviousTarget', $data )
|
|
|
|
|
&& $data['PreviousTarget'] !== $target );
|
|
|
|
|
|
2017-02-20 22:31:04 +00:00
|
|
|
# Special case for API - T34434
|
2012-04-14 21:43:49 +00:00
|
|
|
$reblockNotAllowed = ( array_key_exists( 'Reblock', $data ) && !$data['Reblock'] );
|
|
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
# Show form unless the user is already aware of this...
|
2013-03-25 22:52:41 +00:00
|
|
|
if ( $blockNotConfirmed || $reblockNotAllowed ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ [ 'ipb_already_blocked', $block->getTarget() ] ];
|
2013-03-25 22:52:41 +00:00
|
|
|
# Otherwise, try to update the block...
|
2011-03-12 22:53:15 +00:00
|
|
|
} 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
|
2019-05-13 14:18:07 +00:00
|
|
|
$currentBlock = DatabaseBlock::newFromTarget( $target );
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( $block->equals( $currentBlock ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ [ '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...
|
2019-08-21 02:01:06 +00:00
|
|
|
if ( $currentBlock->getHideName() && !MediaWikiServices::getInstance()
|
|
|
|
|
->getPermissionManager()
|
|
|
|
|
->userHasRight( $performer, 'hideuser' )
|
|
|
|
|
) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ 'cant-see-hidden-user' ];
|
2011-03-12 22:53:15 +00:00
|
|
|
}
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2016-06-09 21:53:47 +00:00
|
|
|
$priorBlock = clone $currentBlock;
|
2019-10-27 11:19:36 +00:00
|
|
|
$currentBlock->setBlocker( $performer );
|
2013-06-02 17:36:30 +00:00
|
|
|
$currentBlock->isHardblock( $block->isHardblock() );
|
Separate out different functionalities of Block::prevents
Block::prevents plays several different roles:
* acts as get/setter for Boolean properties that correspond to
ipb_create_account, ipb_block_email and ipb_allow_usertalk
* calculates whether a block blocks a given right, based on Block
properties, global configs, white/blacklists and anonymous user
rights
* decides whether a block prevents editing of the target's own
user talk page (listed separately because 'editownusertalk' is
not a right)
This patch:
* renames mDisableUsertalk to allowEditUsertalk (and reverses the
value), to match the field ipb_allow_usertalk and make this logic
easier to follow
* renames mCreateAccount to blockCreateAccount, to make it clear
that the flag blocks account creation when true, and make this
logic easier to follow
* decouples the block that is stored in the database (which now
reflects the form that the admin submitted) and the behaviour of
the block on enforcement (since the properties set by the admin
can be overridden by global configs) - so if the global configs
change, the block behaviour could too
* creates get/setters for blockCreateAccount, mBlockEmail and
allowEditUsertalk properties
* creates appliesToRight, exclusively for checking whether the
block blocks a given right, taking into account the block
properties, global configs and anonymous user rights
* creates appliesToUsertalk, for checking whether the block
blocks a user from editing their own talk page. The block is
unaware of the user trying to make the edit, and this user is not
always the same as the block target, e.g. if the block target is
an IP range. Therefore the user's talk page is passed in to this
method. appliesToUsertalk can be called from anywhere where the
user is known
* uses the get/setters wherever Block::prevents was being used as
such
* uses appliesToRight whenever Block::prevents was being used to
determine if the block blocks a given right
* uses appliesToUsertalk in User::isBlockedFrom
Bug: T211578
Bug: T214508
Change-Id: I0e131696419211319082cb454f4f05297e55d22e
2019-02-09 12:17:54 +00:00
|
|
|
$currentBlock->isCreateAccountBlocked( $block->isCreateAccountBlocked() );
|
2019-03-22 15:16:40 +00:00
|
|
|
$currentBlock->setExpiry( $block->getExpiry() );
|
2013-06-02 17:36:30 +00:00
|
|
|
$currentBlock->isAutoblocking( $block->isAutoblocking() );
|
2019-03-22 15:16:40 +00:00
|
|
|
$currentBlock->setHideName( $block->getHideName() );
|
Separate out different functionalities of Block::prevents
Block::prevents plays several different roles:
* acts as get/setter for Boolean properties that correspond to
ipb_create_account, ipb_block_email and ipb_allow_usertalk
* calculates whether a block blocks a given right, based on Block
properties, global configs, white/blacklists and anonymous user
rights
* decides whether a block prevents editing of the target's own
user talk page (listed separately because 'editownusertalk' is
not a right)
This patch:
* renames mDisableUsertalk to allowEditUsertalk (and reverses the
value), to match the field ipb_allow_usertalk and make this logic
easier to follow
* renames mCreateAccount to blockCreateAccount, to make it clear
that the flag blocks account creation when true, and make this
logic easier to follow
* decouples the block that is stored in the database (which now
reflects the form that the admin submitted) and the behaviour of
the block on enforcement (since the properties set by the admin
can be overridden by global configs) - so if the global configs
change, the block behaviour could too
* creates get/setters for blockCreateAccount, mBlockEmail and
allowEditUsertalk properties
* creates appliesToRight, exclusively for checking whether the
block blocks a given right, taking into account the block
properties, global configs and anonymous user rights
* creates appliesToUsertalk, for checking whether the block
blocks a user from editing their own talk page. The block is
unaware of the user trying to make the edit, and this user is not
always the same as the block target, e.g. if the block target is
an IP range. Therefore the user's talk page is passed in to this
method. appliesToUsertalk can be called from anywhere where the
user is known
* uses the get/setters wherever Block::prevents was being used as
such
* uses appliesToRight whenever Block::prevents was being used to
determine if the block blocks a given right
* uses appliesToUsertalk in User::isBlockedFrom
Bug: T211578
Bug: T214508
Change-Id: I0e131696419211319082cb454f4f05297e55d22e
2019-02-09 12:17:54 +00:00
|
|
|
$currentBlock->isEmailBlocked( $block->isEmailBlocked() );
|
|
|
|
|
$currentBlock->isUsertalkEditAllowed( $block->isUsertalkEditAllowed() );
|
2019-10-20 00:04:00 +00:00
|
|
|
$currentBlock->setReason( $block->getReasonComment() );
|
2018-08-27 22:19:37 +00:00
|
|
|
|
2020-03-02 16:18:23 +00:00
|
|
|
// Maintain the sitewide status. If partial blocks is not enabled,
|
|
|
|
|
// saving the block will result in a sitewide block.
|
|
|
|
|
$currentBlock->isSitewide( $block->isSitewide() );
|
2018-08-27 22:19:37 +00:00
|
|
|
|
2020-03-02 16:18:23 +00:00
|
|
|
// Set the block id of the restrictions.
|
|
|
|
|
$blockRestrictionStore = MediaWikiServices::getInstance()->getBlockRestrictionStore();
|
|
|
|
|
$currentBlock->setRestrictions(
|
|
|
|
|
$blockRestrictionStore->setBlockId( $currentBlock->getId(), $restrictions )
|
|
|
|
|
);
|
2013-06-02 17:36:30 +00:00
|
|
|
|
|
|
|
|
$status = $currentBlock->update();
|
2018-12-18 07:50:05 +00:00
|
|
|
// TODO handle failure
|
2013-06-02 17:36:30 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
$logaction = 'reblock';
|
|
|
|
|
|
|
|
|
|
# Unset _deleted fields if requested
|
2019-03-22 15:16:40 +00:00
|
|
|
if ( $currentBlock->getHideName() && !$data['HideUser'] ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
RevisionDeleteUser::unsuppressUserName( $target, $userId );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# If hiding/unhiding a name, this should go in the private logs
|
2019-03-22 15:16:40 +00:00
|
|
|
if ( (bool)$currentBlock->getHideName() ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
$data['HideUser'] = true;
|
|
|
|
|
}
|
2018-12-18 07:50:05 +00:00
|
|
|
|
|
|
|
|
$block = $currentBlock;
|
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
|
|
|
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
Hooks::runner()->onBlockIpComplete( $block, $performer, $priorBlock );
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
# Set *_deleted fields if requested
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( $data['HideUser'] ) {
|
2011-03-12 22:53:15 +00:00
|
|
|
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
|
2019-05-13 14:18:07 +00:00
|
|
|
if ( $type != DatabaseBlock::TYPE_RANGE && $data['Watch'] ) {
|
2014-05-09 19:33:58 +00:00
|
|
|
WatchAction::doWatch(
|
|
|
|
|
Title::makeTitle( NS_USER, $target ),
|
|
|
|
|
$performer,
|
2016-02-01 11:53:01 +00:00
|
|
|
User::IGNORE_USER_RIGHTS
|
2014-05-09 19:33:58 +00:00
|
|
|
);
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
2019-05-13 14:18:07 +00:00
|
|
|
# DatabaseBlock constructor sanitizes certain block options on insert
|
Separate out different functionalities of Block::prevents
Block::prevents plays several different roles:
* acts as get/setter for Boolean properties that correspond to
ipb_create_account, ipb_block_email and ipb_allow_usertalk
* calculates whether a block blocks a given right, based on Block
properties, global configs, white/blacklists and anonymous user
rights
* decides whether a block prevents editing of the target's own
user talk page (listed separately because 'editownusertalk' is
not a right)
This patch:
* renames mDisableUsertalk to allowEditUsertalk (and reverses the
value), to match the field ipb_allow_usertalk and make this logic
easier to follow
* renames mCreateAccount to blockCreateAccount, to make it clear
that the flag blocks account creation when true, and make this
logic easier to follow
* decouples the block that is stored in the database (which now
reflects the form that the admin submitted) and the behaviour of
the block on enforcement (since the properties set by the admin
can be overridden by global configs) - so if the global configs
change, the block behaviour could too
* creates get/setters for blockCreateAccount, mBlockEmail and
allowEditUsertalk properties
* creates appliesToRight, exclusively for checking whether the
block blocks a given right, taking into account the block
properties, global configs and anonymous user rights
* creates appliesToUsertalk, for checking whether the block
blocks a user from editing their own talk page. The block is
unaware of the user trying to make the edit, and this user is not
always the same as the block target, e.g. if the block target is
an IP range. Therefore the user's talk page is passed in to this
method. appliesToUsertalk can be called from anywhere where the
user is known
* uses the get/setters wherever Block::prevents was being used as
such
* uses appliesToRight whenever Block::prevents was being used to
determine if the block blocks a given right
* uses appliesToUsertalk in User::isBlockedFrom
Bug: T211578
Bug: T214508
Change-Id: I0e131696419211319082cb454f4f05297e55d22e
2019-02-09 12:17:54 +00:00
|
|
|
$data['BlockEmail'] = $block->isEmailBlocked();
|
2011-03-21 19:12:41 +00:00
|
|
|
$data['AutoBlock'] = $block->isAutoblocking();
|
2011-03-12 22:53:15 +00:00
|
|
|
|
|
|
|
|
# Prepare log parameters
|
2016-02-17 09:09:32 +00:00
|
|
|
$logParams = [];
|
2020-01-02 08:36:22 +00:00
|
|
|
|
|
|
|
|
$rawExpiry = $data['Expiry'];
|
|
|
|
|
$logExpiry = wfIsInfinity( $rawExpiry ) ? 'infinity' : $rawExpiry;
|
|
|
|
|
|
|
|
|
|
$logParams['5::duration'] = $logExpiry;
|
2014-08-04 21:12:53 +00:00
|
|
|
$logParams['6::flags'] = self::blockLogFlags( $data, $type );
|
2018-09-19 05:51:49 +00:00
|
|
|
$logParams['sitewide'] = $block->isSitewide();
|
|
|
|
|
|
2020-03-02 16:18:23 +00:00
|
|
|
if ( !$block->isSitewide() ) {
|
2019-01-25 04:45:11 +00:00
|
|
|
if ( $data['PageRestrictions'] !== '' ) {
|
|
|
|
|
$logParams['7::restrictions']['pages'] = explode( "\n", $data['PageRestrictions'] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $data['NamespaceRestrictions'] !== '' ) {
|
|
|
|
|
$logParams['7::restrictions']['namespaces'] = explode( "\n", $data['NamespaceRestrictions'] );
|
|
|
|
|
}
|
2018-09-19 05:51:49 +00:00
|
|
|
}
|
2011-03-12 22:53:15 +00:00
|
|
|
|
2015-09-15 22:38:15 +00:00
|
|
|
# Make log entry, if the name is hidden, put it in the suppression log
|
2011-03-12 22:53:15 +00:00
|
|
|
$log_type = $data['HideUser'] ? 'suppress' : 'block';
|
2014-08-04 21:12:53 +00:00
|
|
|
$logEntry = new ManualLogEntry( $log_type, $logaction );
|
|
|
|
|
$logEntry->setTarget( Title::makeTitle( NS_USER, $target ) );
|
2020-03-03 19:10:46 +00:00
|
|
|
$logEntry->setComment( $blockReason );
|
2014-08-04 21:12:53 +00:00
|
|
|
$logEntry->setPerformer( $performer );
|
|
|
|
|
$logEntry->setParameters( $logParams );
|
2018-12-18 07:50:05 +00:00
|
|
|
# Relate log ID to block ID (T27763)
|
|
|
|
|
$logEntry->setRelations( [ 'ipb_id' => $block->getId() ] );
|
2014-08-04 21:12:53 +00:00
|
|
|
$logId = $logEntry->insert();
|
2017-01-12 07:14:55 +00:00
|
|
|
|
2017-01-27 15:31:47 +00:00
|
|
|
if ( !empty( $data['Tags'] ) ) {
|
2019-07-07 22:07:56 +00:00
|
|
|
$logEntry->addTags( $data['Tags'] );
|
2017-01-12 07:14:55 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-04 21:12:53 +00:00
|
|
|
$logEntry->publish( $logId );
|
2011-03-12 21:54:35 +00:00
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
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?
|
2014-04-19 08:16:52 +00:00
|
|
|
* @param Language|null $lang The language to get the durations in, or null to use
|
2011-07-26 19:04:48 +00:00
|
|
|
* the wiki's content language
|
2018-04-30 01:38:42 +00:00
|
|
|
* @param bool $includeOther Whether to include the 'other' option in the list of
|
|
|
|
|
* suggestions
|
2020-03-24 08:59:02 +00:00
|
|
|
* @return string[]
|
2011-03-12 21:54:35 +00:00
|
|
|
*/
|
2017-10-04 19:02:29 +00:00
|
|
|
public static function getSuggestedDurations( Language $lang = null, $includeOther = true ) {
|
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
|
|
|
|
2012-08-29 02:34:00 +00:00
|
|
|
if ( $msg == '-' ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [];
|
2011-03-18 16:35:22 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-13 03:37:14 +00:00
|
|
|
$a = XmlSelect::parseOptionsMessage( $msg );
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2018-04-30 01:38:42 +00:00
|
|
|
if ( $a && $includeOther ) {
|
2018-03-22 05:15:16 +00:00
|
|
|
// if options exist, add other to the end instead of the begining (which
|
|
|
|
|
// is what happens by default).
|
|
|
|
|
$a[ wfMessage( 'ipbother' )->text() ] = 'other';
|
|
|
|
|
}
|
|
|
|
|
|
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.
|
2018-03-22 05:15:16 +00:00
|
|
|
*
|
|
|
|
|
* @todo strtotime() only accepts English strings. This means the expiry input
|
|
|
|
|
* can only be specified in English.
|
2019-04-12 04:41:14 +00:00
|
|
|
* @see https://www.php.net/manual/en/function.strtotime.php
|
2018-03-22 05:15:16 +00:00
|
|
|
*
|
2014-04-19 08:16:52 +00:00
|
|
|
* @param string $expiry Whatever was typed into the form
|
2018-03-22 05:15:16 +00:00
|
|
|
* @return string|bool Timestamp or 'infinity' or false on error.
|
2011-03-18 16:35:22 +00:00
|
|
|
*/
|
|
|
|
|
public static function parseExpiryInput( $expiry ) {
|
2014-06-18 02:45:32 +00:00
|
|
|
if ( wfIsInfinity( $expiry ) ) {
|
2018-03-22 05:15:16 +00:00
|
|
|
return 'infinity';
|
|
|
|
|
}
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2018-03-22 05:15:16 +00:00
|
|
|
$expiry = strtotime( $expiry );
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2018-03-22 05:15:16 +00:00
|
|
|
if ( $expiry < 0 || $expiry === false ) {
|
|
|
|
|
return false;
|
2011-03-18 16:35:22 +00:00
|
|
|
}
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2018-03-22 05:15:16 +00:00
|
|
|
return wfTimestamp( TS_MW, $expiry );
|
2011-03-18 16:35:22 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
/**
|
|
|
|
|
* Can we do an email block?
|
2019-08-21 02:01:06 +00:00
|
|
|
* @param UserIdentity $user The sysop wanting to make a block
|
2014-04-19 08:16:52 +00:00
|
|
|
* @return bool
|
2011-03-12 22:53:15 +00:00
|
|
|
*/
|
2019-08-21 02:01:06 +00:00
|
|
|
public static function canBlockEmail( UserIdentity $user ) {
|
2019-09-05 22:57:06 +00:00
|
|
|
global $wgEnableUserEmail;
|
2011-09-01 13:59:38 +00:00
|
|
|
|
2019-09-05 22:57:06 +00:00
|
|
|
return ( $wgEnableUserEmail && MediaWikiServices::getInstance()
|
2019-08-21 02:01:06 +00:00
|
|
|
->getPermissionManager()
|
|
|
|
|
->userHasRight( $user, 'blockemail' ) );
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-12 22:53:15 +00:00
|
|
|
/**
|
2020-03-31 10:55:57 +00:00
|
|
|
* T17810: Sitewide blocked admins should not be able to block/unblock
|
|
|
|
|
* others with one exception; they can block the user who blocked them,
|
|
|
|
|
* to reduce advantage of a malicious account blocking all admins (T150826).
|
2018-11-27 18:38:14 +00:00
|
|
|
*
|
2020-03-31 10:55:57 +00:00
|
|
|
* T208965: Partially blocked admins can block and unblock others as normal.
|
2018-11-27 18:38:14 +00:00
|
|
|
*
|
2020-05-07 18:50:24 +00:00
|
|
|
* @param User|string|null $target Target to block or unblock; could be a User object,
|
|
|
|
|
* or username/IP address, or null when the target is not known yet (e.g. when
|
2018-12-10 03:28:09 +00:00
|
|
|
* displaying Special:Block)
|
2014-04-19 08:16:52 +00:00
|
|
|
* @param User $performer User doing the request
|
|
|
|
|
* @return bool|string True or error message key
|
2011-03-12 22:53:15 +00:00
|
|
|
*/
|
2018-12-10 03:28:09 +00:00
|
|
|
public static function checkUnblockSelf( $target, User $performer ) {
|
2020-05-07 18:50:24 +00:00
|
|
|
return MediaWikiServices::getInstance()
|
|
|
|
|
->getBlockPermissionCheckerFactory()
|
|
|
|
|
->newBlockPermissionChecker( $target, $performer )
|
|
|
|
|
->checkBlockPermissions();
|
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
|
2014-04-19 08:16:52 +00:00
|
|
|
* @param array $data From HTMLForm data
|
2019-05-13 14:18:07 +00:00
|
|
|
* @param int $type DatabaseBlock::TYPE_ constant (USER, RANGE, or IP)
|
2012-08-29 02:34:00 +00:00
|
|
|
* @return string
|
2011-03-12 21:54:35 +00:00
|
|
|
*/
|
2011-03-12 22:53:15 +00:00
|
|
|
protected static function blockLogFlags( array $data, $type ) {
|
2018-09-19 05:51:49 +00:00
|
|
|
$config = RequestContext::getMain()->getConfig();
|
|
|
|
|
|
|
|
|
|
$blockAllowsUTEdit = $config->get( 'BlockAllowsUTEdit' );
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$flags = [];
|
2011-03-12 22:51:48 +00:00
|
|
|
|
2012-08-29 02:34:00 +00:00
|
|
|
# when blocking a user the option 'anononly' is not available/has no effect
|
|
|
|
|
# -> do not write this into log
|
2019-05-13 14:18:07 +00:00
|
|
|
if ( !$data['HardBlock'] && $type != DatabaseBlock::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
|
|
|
}
|
|
|
|
|
|
2012-08-29 02:34:00 +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
|
2019-05-13 14:18:07 +00:00
|
|
|
if ( !$data['AutoBlock'] && $type == DatabaseBlock::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
|
|
|
|
2012-08-29 02:34:00 +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
|
|
|
}
|
|
|
|
|
|
2018-09-19 05:51:49 +00:00
|
|
|
if ( $blockAllowsUTEdit && $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
|
|
|
|
2012-08-29 02:34:00 +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-11-15 02:25:36 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Process the form on POST submission.
|
2014-04-19 08:16:52 +00:00
|
|
|
* @param array $data
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param HTMLForm|null $form
|
2014-04-19 08:16:52 +00:00
|
|
|
* @return bool|array True for success, false for didn't-try, array of errors on failure
|
2011-11-15 02:25:36 +00:00
|
|
|
*/
|
2015-07-27 14:23:24 +00:00
|
|
|
public function onSubmit( array $data, HTMLForm $form = null ) {
|
2019-01-14 14:58:42 +00:00
|
|
|
// If "Editing" checkbox is unchecked, the block must be a partial block affecting
|
|
|
|
|
// actions other than editing, and there must be no restrictions.
|
|
|
|
|
if ( isset( $data['Editing'] ) && $data['Editing'] === false ) {
|
|
|
|
|
$data['EditingRestriction'] = 'partial';
|
2019-01-18 16:22:09 +00:00
|
|
|
$data['PageRestrictions'] = '';
|
2018-12-14 21:08:40 +00:00
|
|
|
$data['NamespaceRestrictions'] = '';
|
2019-01-14 14:58:42 +00:00
|
|
|
}
|
2015-07-27 14:23:24 +00:00
|
|
|
return self::processForm( $data, $form->getContext() );
|
2011-11-15 02:25:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Do something exciting on successful processing of the form, most likely to show a
|
|
|
|
|
* confirmation message
|
|
|
|
|
*/
|
|
|
|
|
public function onSuccess() {
|
|
|
|
|
$out = $this->getOutput();
|
|
|
|
|
$out->setPageTitle( $this->msg( 'blockipsuccesssub' ) );
|
2012-04-21 13:12:08 +00:00
|
|
|
$out->addWikiMsg( 'blockipsuccesstext', wfEscapeWikiText( $this->target ) );
|
2011-11-15 02:25:36 +00:00
|
|
|
}
|
2013-03-07 20:15:54 +00:00
|
|
|
|
2015-12-03 20:08:31 +00:00
|
|
|
/**
|
|
|
|
|
* Return an array of subpages beginning with $search that this special page will accept.
|
|
|
|
|
*
|
|
|
|
|
* @param string $search Prefix to search for
|
|
|
|
|
* @param int $limit Maximum number of results to return (usually 10)
|
|
|
|
|
* @param int $offset Number of results to skip (usually 0)
|
|
|
|
|
* @return string[] Matching subpages
|
|
|
|
|
*/
|
|
|
|
|
public function prefixSearchSubpages( $search, $limit, $offset ) {
|
|
|
|
|
$user = User::newFromName( $search );
|
|
|
|
|
if ( !$user ) {
|
|
|
|
|
// No prefix suggestion for invalid user
|
2016-02-17 09:09:32 +00:00
|
|
|
return [];
|
2015-12-03 20:08:31 +00:00
|
|
|
}
|
|
|
|
|
// Autocomplete subpage as user list - public to allow caching
|
|
|
|
|
return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-07 20:15:54 +00:00
|
|
|
protected function getGroupName() {
|
|
|
|
|
return 'users';
|
|
|
|
|
}
|
2011-03-12 22:51:48 +00:00
|
|
|
}
|