2009-01-28 00:36:49 +00:00
|
|
|
<?php
|
|
|
|
|
2020-11-29 10:53:29 +00:00
|
|
|
namespace MediaWiki\Extension\AbuseFilter\View;
|
|
|
|
|
|
|
|
use HTMLForm;
|
|
|
|
use IContextSource;
|
|
|
|
use Linker;
|
|
|
|
use ManualLogEntry;
|
2019-05-31 15:08:19 +00:00
|
|
|
use MediaWiki\Block\DatabaseBlock;
|
2020-10-23 14:19:02 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\BlockAutopromoteStore;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\FilterUser;
|
2020-10-02 15:08:48 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\SpecsFormatter;
|
2020-09-29 14:52:05 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\VariablesBlobStore;
|
2020-10-23 14:19:02 +00:00
|
|
|
use MediaWiki\Linker\LinkRenderer;
|
|
|
|
use MediaWiki\User\UserGroupManager;
|
2020-11-29 10:53:29 +00:00
|
|
|
use Message;
|
|
|
|
use MWException;
|
|
|
|
use PermissionsError;
|
|
|
|
use SpecialPage;
|
|
|
|
use Title;
|
|
|
|
use User;
|
|
|
|
use UserBlockedError;
|
|
|
|
use Xml;
|
2018-10-18 17:30:15 +00:00
|
|
|
|
2009-01-28 00:36:49 +00:00
|
|
|
class AbuseFilterViewRevert extends AbuseFilterView {
|
2020-10-03 17:13:32 +00:00
|
|
|
/** @var int */
|
|
|
|
private $filter;
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
|
|
|
* @var string The start time of the lookup period
|
|
|
|
*/
|
|
|
|
public $origPeriodStart;
|
|
|
|
/**
|
|
|
|
* @var string The end time of the lookup period
|
|
|
|
*/
|
|
|
|
public $origPeriodEnd;
|
|
|
|
/**
|
2019-12-07 17:20:10 +00:00
|
|
|
* @var string|null The same as $origPeriodStart
|
2018-11-08 14:34:32 +00:00
|
|
|
*/
|
|
|
|
public $mPeriodStart;
|
|
|
|
/**
|
2019-12-07 17:20:10 +00:00
|
|
|
* @var string|null The same as $origPeriodEnd
|
2018-11-08 14:34:32 +00:00
|
|
|
*/
|
|
|
|
public $mPeriodEnd;
|
|
|
|
/**
|
|
|
|
* @var string|null The reason provided for the revert
|
|
|
|
*/
|
2018-03-30 00:57:57 +00:00
|
|
|
public $mReason;
|
2020-10-23 14:19:02 +00:00
|
|
|
/**
|
|
|
|
* @var UserGroupManager
|
|
|
|
*/
|
|
|
|
private $userGroupsManager;
|
|
|
|
/**
|
|
|
|
* @var BlockAutopromoteStore
|
|
|
|
*/
|
|
|
|
private $blockAutopromoteStore;
|
|
|
|
/**
|
|
|
|
* @var FilterUser
|
|
|
|
*/
|
|
|
|
private $filterUser;
|
2020-09-29 14:52:05 +00:00
|
|
|
/**
|
|
|
|
* @var VariablesBlobStore
|
|
|
|
*/
|
|
|
|
private $varBlobStore;
|
2020-10-23 14:19:02 +00:00
|
|
|
|
2020-10-02 15:08:48 +00:00
|
|
|
/**
|
|
|
|
* @var SpecsFormatter
|
|
|
|
*/
|
|
|
|
private $specsFormatter;
|
|
|
|
|
2020-10-23 14:19:02 +00:00
|
|
|
/**
|
|
|
|
* @param UserGroupManager $userGroupManager
|
|
|
|
* @param AbuseFilterPermissionManager $afPermManager
|
|
|
|
* @param BlockAutopromoteStore $blockAutopromoteStore
|
|
|
|
* @param FilterUser $filterUser
|
2020-09-29 14:52:05 +00:00
|
|
|
* @param VariablesBlobStore $varBlobStore
|
2020-10-02 15:08:48 +00:00
|
|
|
* @param SpecsFormatter $specsFormatter
|
2020-10-23 14:19:02 +00:00
|
|
|
* @param IContextSource $context
|
|
|
|
* @param LinkRenderer $linkRenderer
|
|
|
|
* @param string $basePageName
|
|
|
|
* @param array $params
|
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
UserGroupManager $userGroupManager,
|
|
|
|
AbuseFilterPermissionManager $afPermManager,
|
|
|
|
BlockAutopromoteStore $blockAutopromoteStore,
|
|
|
|
FilterUser $filterUser,
|
2020-09-29 14:52:05 +00:00
|
|
|
VariablesBlobStore $varBlobStore,
|
2020-10-02 15:08:48 +00:00
|
|
|
SpecsFormatter $specsFormatter,
|
2020-10-23 14:19:02 +00:00
|
|
|
IContextSource $context,
|
|
|
|
LinkRenderer $linkRenderer,
|
|
|
|
string $basePageName,
|
|
|
|
array $params
|
|
|
|
) {
|
|
|
|
parent::__construct( $afPermManager, $context, $linkRenderer, $basePageName, $params );
|
|
|
|
$this->userGroupsManager = $userGroupManager;
|
|
|
|
$this->blockAutopromoteStore = $blockAutopromoteStore;
|
|
|
|
$this->filterUser = $filterUser;
|
2020-09-29 14:52:05 +00:00
|
|
|
$this->varBlobStore = $varBlobStore;
|
2020-10-02 15:08:48 +00:00
|
|
|
$this->specsFormatter = $specsFormatter;
|
|
|
|
$this->specsFormatter->setMessageLocalizer( $this->getContext() );
|
2020-10-23 14:19:02 +00:00
|
|
|
}
|
2013-10-15 13:22:05 +00:00
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* Shows the page
|
|
|
|
*/
|
|
|
|
public function show() {
|
2018-03-25 14:17:31 +00:00
|
|
|
$lang = $this->getLanguage();
|
2009-01-28 00:36:49 +00:00
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$user = $this->getUser();
|
|
|
|
$out = $this->getOutput();
|
2009-01-28 00:36:49 +00:00
|
|
|
|
2020-10-23 14:19:02 +00:00
|
|
|
if ( !$this->afPermManager->canRevertFilterActions( $user ) ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
throw new PermissionsError( 'abusefilter-revert' );
|
2009-01-28 00:36:49 +00:00
|
|
|
}
|
|
|
|
|
2019-09-14 13:04:37 +00:00
|
|
|
$block = $user->getBlock();
|
|
|
|
if ( $block && $block->isSitewide() ) {
|
|
|
|
throw new UserBlockedError( $block );
|
|
|
|
}
|
|
|
|
|
2009-01-28 00:36:49 +00:00
|
|
|
$this->loadParameters();
|
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $this->attemptRevert() ) {
|
2009-01-28 00:36:49 +00:00
|
|
|
return;
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-28 00:36:49 +00:00
|
|
|
|
2020-10-03 17:13:32 +00:00
|
|
|
$filter = $this->filter;
|
2020-10-03 13:05:20 +00:00
|
|
|
|
2017-11-11 11:38:12 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-revert-intro', Message::numParam( $filter ) );
|
|
|
|
$out->setPageTitle( $this->msg( 'abusefilter-revert-title' )->numParams( $filter ) );
|
2009-01-28 00:36:49 +00:00
|
|
|
|
2018-03-25 14:17:31 +00:00
|
|
|
// First, the search form. Limit dates to avoid huge queries
|
|
|
|
$RCMaxAge = $this->getConfig()->get( 'RCMaxAge' );
|
|
|
|
$min = wfTimestamp( TS_ISO_8601, time() - $RCMaxAge );
|
|
|
|
$max = wfTimestampNow();
|
|
|
|
$filterLink =
|
|
|
|
$this->linkRenderer->makeLink(
|
2020-10-03 17:13:32 +00:00
|
|
|
$this->getTitle( $filter ),
|
|
|
|
$lang->formatNum( $filter )
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2018-03-25 14:17:31 +00:00
|
|
|
$searchFields = [];
|
|
|
|
$searchFields['filterid'] = [
|
|
|
|
'type' => 'info',
|
|
|
|
'default' => $filterLink,
|
|
|
|
'raw' => true,
|
|
|
|
'label-message' => 'abusefilter-revert-filter'
|
|
|
|
];
|
|
|
|
$searchFields['periodstart'] = [
|
|
|
|
'type' => 'datetime',
|
|
|
|
'name' => 'wpPeriodStart',
|
|
|
|
'default' => $this->origPeriodStart,
|
|
|
|
'label-message' => 'abusefilter-revert-periodstart',
|
|
|
|
'min' => $min,
|
|
|
|
'max' => $max
|
|
|
|
];
|
|
|
|
$searchFields['periodend'] = [
|
|
|
|
'type' => 'datetime',
|
|
|
|
'name' => 'wpPeriodEnd',
|
|
|
|
'default' => $this->origPeriodEnd,
|
|
|
|
'label-message' => 'abusefilter-revert-periodend',
|
|
|
|
'min' => $min,
|
|
|
|
'max' => $max
|
|
|
|
];
|
|
|
|
|
|
|
|
HTMLForm::factory( 'ooui', $searchFields, $this->getContext() )
|
|
|
|
->setAction( $this->getTitle( "revert/$filter" )->getLocalURL() )
|
|
|
|
->setWrapperLegendMsg( 'abusefilter-revert-search-legend' )
|
|
|
|
->setSubmitTextMsg( 'abusefilter-revert-search' )
|
2020-10-04 12:38:18 +00:00
|
|
|
->setMethod( 'get' )
|
|
|
|
->setFormIdentifier( 'revert-select-date' )
|
|
|
|
->setSubmitCallback( [ $this, 'showRevertableActions' ] )
|
|
|
|
->showAlways();
|
|
|
|
}
|
2009-01-28 00:36:49 +00:00
|
|
|
|
2020-10-04 12:38:18 +00:00
|
|
|
/**
|
|
|
|
* Show revertable actions, called as submit callback by HTMLForm
|
|
|
|
* @param array $formData
|
|
|
|
* @param HTMLForm $dateForm
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function showRevertableActions( array $formData, HTMLForm $dateForm ) : bool {
|
|
|
|
$lang = $this->getLanguage();
|
|
|
|
$user = $this->getUser();
|
|
|
|
$filter = $this->filter;
|
|
|
|
|
|
|
|
// Look up all of them.
|
|
|
|
$results = $this->doLookup();
|
2020-11-10 09:45:24 +00:00
|
|
|
if ( $results === [] ) {
|
|
|
|
$dateForm->addPostText( $this->msg( 'abusefilter-revert-preview-no-results' )->escaped() );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a summary of everything that will be reversed.
|
|
|
|
$dateForm->addPostText( $this->msg( 'abusefilter-revert-preview-intro' )->parseAsBlock() );
|
2020-10-04 12:38:18 +00:00
|
|
|
$list = [];
|
|
|
|
|
|
|
|
foreach ( $results as $result ) {
|
|
|
|
$displayActions = [];
|
|
|
|
foreach ( $result['actions'] as $action ) {
|
2020-10-02 15:08:48 +00:00
|
|
|
$displayActions[] = $this->specsFormatter->getActionDisplay( $action );
|
2020-10-04 12:38:18 +00:00
|
|
|
}
|
2018-03-25 14:17:31 +00:00
|
|
|
|
2020-10-04 12:38:18 +00:00
|
|
|
$msg = $this->msg( 'abusefilter-revert-preview-item' )
|
|
|
|
->params(
|
|
|
|
$lang->timeanddate( $result['timestamp'], true )
|
|
|
|
)->rawParams(
|
|
|
|
Linker::userLink( $result['userid'], $result['user'] )
|
|
|
|
)->params(
|
|
|
|
$result['action']
|
|
|
|
)->rawParams(
|
|
|
|
$this->linkRenderer->makeLink( $result['title'] )
|
|
|
|
)->params(
|
|
|
|
$lang->commaList( $displayActions )
|
|
|
|
)->rawParams(
|
|
|
|
$this->linkRenderer->makeLink(
|
|
|
|
SpecialPage::getTitleFor( 'AbuseLog' ),
|
|
|
|
$this->msg( 'abusefilter-log-detailslink' )->text(),
|
|
|
|
[],
|
|
|
|
[ 'details' => $result['id'] ]
|
|
|
|
)
|
|
|
|
)->params( $result['user'] )->parse();
|
|
|
|
$list[] = Xml::tags( 'li', null, $msg );
|
2009-01-28 00:36:49 +00:00
|
|
|
}
|
2020-10-04 12:38:18 +00:00
|
|
|
|
|
|
|
$dateForm->addPostText( Xml::tags( 'ul', null, implode( "\n", $list ) ) );
|
|
|
|
|
|
|
|
// Add a button down the bottom.
|
|
|
|
$confirmForm = [];
|
|
|
|
$confirmForm['edittoken'] = [
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'editToken',
|
|
|
|
'default' => $user->getEditToken( "abusefilter-revert-$filter" )
|
|
|
|
];
|
|
|
|
$confirmForm['title'] = [
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'title',
|
|
|
|
'default' => $this->getTitle( "revert/$filter" )->getPrefixedDBkey()
|
|
|
|
];
|
|
|
|
$confirmForm['wpPeriodStart'] = [
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'wpPeriodStart',
|
|
|
|
'default' => $this->origPeriodStart
|
|
|
|
];
|
|
|
|
$confirmForm['wpPeriodEnd'] = [
|
|
|
|
'type' => 'hidden',
|
|
|
|
'name' => 'wpPeriodEnd',
|
|
|
|
'default' => $this->origPeriodEnd
|
|
|
|
];
|
|
|
|
$confirmForm['reason'] = [
|
|
|
|
'type' => 'text',
|
|
|
|
'label-message' => 'abusefilter-revert-reasonfield',
|
|
|
|
'name' => 'wpReason',
|
|
|
|
'id' => 'wpReason',
|
|
|
|
];
|
|
|
|
|
|
|
|
$revertForm = HTMLForm::factory( 'ooui', $confirmForm, $this->getContext() )
|
|
|
|
->setAction( $this->getTitle( "revert/$filter" )->getLocalURL() )
|
|
|
|
->setWrapperLegendMsg( 'abusefilter-revert-confirm-legend' )
|
|
|
|
->setSubmitTextMsg( 'abusefilter-revert-confirm' )
|
|
|
|
->prepareForm()
|
|
|
|
->getHTML( true );
|
|
|
|
$dateForm->addPostText( $revertForm );
|
|
|
|
|
|
|
|
return true;
|
2009-01-28 00:36:49 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
2019-10-09 10:37:38 +00:00
|
|
|
* @return array[]
|
2018-04-04 21:14:25 +00:00
|
|
|
*/
|
|
|
|
public function doLookup() {
|
2018-09-11 16:57:49 +00:00
|
|
|
$aflFilterMigrationStage = $this->getConfig()->get( 'AbuseFilterAflFilterMigrationStage' );
|
2009-01-28 00:36:49 +00:00
|
|
|
$periodStart = $this->mPeriodStart;
|
|
|
|
$periodEnd = $this->mPeriodEnd;
|
2020-10-03 17:13:32 +00:00
|
|
|
$filter = $this->filter;
|
2018-09-11 16:57:49 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2009-01-28 00:36:49 +00:00
|
|
|
|
2018-09-11 16:57:49 +00:00
|
|
|
$conds = [];
|
2009-01-28 00:36:49 +00:00
|
|
|
|
2018-09-11 16:57:49 +00:00
|
|
|
if ( $aflFilterMigrationStage & SCHEMA_COMPAT_READ_NEW ) {
|
|
|
|
// Only hits from local filters can be reverted
|
|
|
|
$conds['afl_filter_id'] = $filter;
|
|
|
|
$conds['afl_global'] = 0;
|
|
|
|
} else {
|
|
|
|
// SCHEMA_COMPAT_READ_OLD
|
|
|
|
$conds['afl_filter'] = $filter;
|
|
|
|
}
|
2009-01-28 00:36:49 +00:00
|
|
|
|
2019-12-07 17:20:10 +00:00
|
|
|
if ( $periodStart !== null ) {
|
2018-06-28 14:45:30 +00:00
|
|
|
$conds[] = 'afl_timestamp >= ' . $dbr->addQuotes( $dbr->timestamp( $periodStart ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2019-12-07 17:20:10 +00:00
|
|
|
if ( $periodEnd !== null ) {
|
2018-06-28 14:45:30 +00:00
|
|
|
$conds[] = 'afl_timestamp <= ' . $dbr->addQuotes( $dbr->timestamp( $periodEnd ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-28 00:36:49 +00:00
|
|
|
|
2018-08-31 14:19:44 +00:00
|
|
|
$selectFields = [
|
|
|
|
'afl_id',
|
|
|
|
'afl_user',
|
|
|
|
'afl_user_text',
|
|
|
|
'afl_action',
|
|
|
|
'afl_actions',
|
|
|
|
'afl_var_dump',
|
|
|
|
'afl_timestamp',
|
|
|
|
'afl_namespace',
|
|
|
|
'afl_title',
|
|
|
|
'afl_wiki',
|
|
|
|
];
|
|
|
|
$res = $dbr->select( 'abuse_filter_log', $selectFields, $conds, __METHOD__ );
|
2009-01-28 00:36:49 +00:00
|
|
|
|
2017-06-15 14:23:16 +00:00
|
|
|
$results = [];
|
2015-09-28 18:03:35 +00:00
|
|
|
foreach ( $res as $row ) {
|
2012-09-12 15:53:47 +00:00
|
|
|
// Don't revert if there was no action, or the action was global
|
|
|
|
if ( !$row->afl_actions || $row->afl_wiki != null ) {
|
2009-01-28 00:36:49 +00:00
|
|
|
continue;
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-28 00:36:49 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$actions = explode( ',', $row->afl_actions );
|
2017-06-15 14:23:16 +00:00
|
|
|
$reversibleActions = [ 'block', 'blockautopromote', 'degroup' ];
|
2009-01-28 00:36:49 +00:00
|
|
|
$currentReversibleActions = array_intersect( $actions, $reversibleActions );
|
|
|
|
if ( count( $currentReversibleActions ) ) {
|
2017-06-15 14:23:16 +00:00
|
|
|
$results[] = [
|
2013-06-26 22:58:36 +00:00
|
|
|
'id' => $row->afl_id,
|
|
|
|
'actions' => $currentReversibleActions,
|
|
|
|
'user' => $row->afl_user_text,
|
|
|
|
'userid' => $row->afl_user,
|
2020-09-29 14:52:05 +00:00
|
|
|
'vars' => $this->varBlobStore->loadVarDump( $row->afl_var_dump ),
|
2013-06-26 22:58:36 +00:00
|
|
|
'title' => Title::makeTitle( $row->afl_namespace, $row->afl_title ),
|
|
|
|
'action' => $row->afl_action,
|
|
|
|
'timestamp' => $row->afl_timestamp
|
2017-06-15 14:23:16 +00:00
|
|
|
];
|
2009-01-28 00:36:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* Loads parameters from request
|
|
|
|
*/
|
|
|
|
public function loadParameters() {
|
2011-11-16 05:34:24 +00:00
|
|
|
$request = $this->getRequest();
|
2009-02-07 09:34:11 +00:00
|
|
|
|
2020-10-03 17:13:32 +00:00
|
|
|
$this->filter = (int)$this->mParams[1];
|
2011-11-16 05:34:24 +00:00
|
|
|
$this->origPeriodStart = $request->getText( 'wpPeriodStart' );
|
2019-12-07 17:20:10 +00:00
|
|
|
$this->mPeriodStart = strtotime( $this->origPeriodStart ) ?: null;
|
2011-11-16 05:34:24 +00:00
|
|
|
$this->origPeriodEnd = $request->getText( 'wpPeriodEnd' );
|
2019-12-07 17:20:10 +00:00
|
|
|
$this->mPeriodEnd = strtotime( $this->origPeriodEnd ) ?: null;
|
2011-11-16 05:34:24 +00:00
|
|
|
$this->mReason = $request->getVal( 'wpReason' );
|
2009-01-28 00:36:49 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function attemptRevert() {
|
2020-10-03 17:13:32 +00:00
|
|
|
$filter = $this->filter;
|
2011-11-16 05:34:24 +00:00
|
|
|
$token = $this->getRequest()->getVal( 'editToken' );
|
|
|
|
if ( !$this->getUser()->matchEditToken( $token, "abusefilter-revert-$filter" ) ) {
|
2009-01-28 00:36:49 +00:00
|
|
|
return false;
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-28 00:36:49 +00:00
|
|
|
|
|
|
|
$results = $this->doLookup();
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $results as $result ) {
|
2020-12-03 08:52:39 +00:00
|
|
|
foreach ( $result['actions'] as $action ) {
|
2009-01-28 00:36:49 +00:00
|
|
|
$this->revertAction( $action, $result );
|
|
|
|
}
|
|
|
|
}
|
2018-03-25 14:17:31 +00:00
|
|
|
$this->getOutput()->wrapWikiMsg(
|
|
|
|
'<p class="success">$1</p>',
|
|
|
|
[
|
|
|
|
'abusefilter-revert-success',
|
|
|
|
$filter,
|
|
|
|
$this->getLanguage()->formatNum( $filter )
|
|
|
|
]
|
2014-06-28 19:23:43 +00:00
|
|
|
);
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-01-28 00:36:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-02 11:07:02 +00:00
|
|
|
/**
|
2017-10-06 18:52:31 +00:00
|
|
|
* @param string $action
|
|
|
|
* @param array $result
|
2012-09-02 11:07:02 +00:00
|
|
|
* @return bool
|
|
|
|
* @throws MWException
|
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function revertAction( $action, $result ) {
|
2015-09-28 18:03:35 +00:00
|
|
|
switch ( $action ) {
|
2009-01-28 00:36:49 +00:00
|
|
|
case 'block':
|
2019-05-31 15:08:19 +00:00
|
|
|
$block = DatabaseBlock::newFromTarget( $result['user'] );
|
2020-10-23 14:19:02 +00:00
|
|
|
$filterUser = $this->filterUser->getUser();
|
2020-10-25 15:30:43 +00:00
|
|
|
if ( !( $block && $block->getBy() === $filterUser->getId() ) ) {
|
2016-03-14 17:17:23 +00:00
|
|
|
// Not blocked by abuse filter
|
|
|
|
return false;
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-28 00:36:49 +00:00
|
|
|
$block->delete();
|
2016-03-14 17:17:23 +00:00
|
|
|
$logEntry = new ManualLogEntry( 'block', 'unblock' );
|
|
|
|
$logEntry->setTarget( Title::makeTitle( NS_USER, $result['user'] ) );
|
|
|
|
$logEntry->setComment(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg(
|
2020-10-03 17:13:32 +00:00
|
|
|
'abusefilter-revert-reason', $this->filter, $this->mReason
|
2012-09-02 11:07:02 +00:00
|
|
|
)->inContentLanguage()->text()
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2016-03-14 17:17:23 +00:00
|
|
|
$logEntry->setPerformer( $this->getUser() );
|
|
|
|
$logEntry->publish( $logEntry->insert() );
|
2012-09-02 11:07:02 +00:00
|
|
|
return true;
|
2009-01-28 00:36:49 +00:00
|
|
|
case 'blockautopromote':
|
2018-07-16 12:10:36 +00:00
|
|
|
$target = User::newFromId( $result['userid'] );
|
|
|
|
$msg = $this->msg(
|
2020-10-03 17:13:32 +00:00
|
|
|
'abusefilter-revert-reason', $this->filter, $this->mReason
|
2018-07-16 12:10:36 +00:00
|
|
|
)->inContentLanguage()->text();
|
|
|
|
|
2020-10-23 14:19:02 +00:00
|
|
|
return $this->blockAutopromoteStore->unblockAutopromote( $target, $this->getUser(), $msg );
|
2009-01-28 00:36:49 +00:00
|
|
|
case 'degroup':
|
|
|
|
// Pull the user's groups from the vars.
|
2020-10-12 11:53:55 +00:00
|
|
|
$removedGroups = $result['vars']->getVar( 'user_groups' )->toNative();
|
2020-10-23 14:19:02 +00:00
|
|
|
$removedGroups = array_diff( $removedGroups,
|
|
|
|
$this->userGroupsManager->listAllImplicitGroups() );
|
2009-01-28 00:36:49 +00:00
|
|
|
$user = User::newFromId( $result['userid'] );
|
2020-10-23 14:19:02 +00:00
|
|
|
$currentGroups = $this->userGroupsManager->getUserGroups( $user );
|
2009-01-28 00:36:49 +00:00
|
|
|
|
2020-10-25 09:28:38 +00:00
|
|
|
$addedGroups = [];
|
2020-10-12 11:53:55 +00:00
|
|
|
foreach ( $removedGroups as $group ) {
|
|
|
|
// TODO An addUserToGroups method with bulk updates would be nice
|
2020-10-23 14:19:02 +00:00
|
|
|
if ( $this->userGroupsManager->addUserToGroup( $user, $group ) ) {
|
2020-10-25 09:28:38 +00:00
|
|
|
$addedGroups[] = $group;
|
|
|
|
}
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2020-10-12 11:53:55 +00:00
|
|
|
// Don't log if no groups were added.
|
2020-10-25 09:28:38 +00:00
|
|
|
if ( !$addedGroups ) {
|
2020-10-12 11:53:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-01-28 00:36:49 +00:00
|
|
|
|
2020-10-12 11:53:55 +00:00
|
|
|
// TODO Core should provide a logging method
|
2018-07-12 17:46:13 +00:00
|
|
|
$logEntry = new ManualLogEntry( 'rights', 'rights' );
|
|
|
|
$logEntry->setTarget( $user->getUserPage() );
|
|
|
|
$logEntry->setPerformer( $this->getUser() );
|
|
|
|
$logEntry->setComment(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg(
|
2009-10-07 13:57:06 +00:00
|
|
|
'abusefilter-revert-reason',
|
2020-10-03 17:13:32 +00:00
|
|
|
$this->filter,
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->mReason
|
2018-07-12 17:46:13 +00:00
|
|
|
)->inContentLanguage()->text()
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2018-07-12 17:46:13 +00:00
|
|
|
$logEntry->setParameters( [
|
|
|
|
'4::oldgroups' => $currentGroups,
|
2020-10-25 09:28:38 +00:00
|
|
|
'5::newgroups' => array_merge( $currentGroups, $addedGroups )
|
2018-07-12 17:46:13 +00:00
|
|
|
] );
|
|
|
|
$logEntry->publish( $logEntry->insert() );
|
2012-09-02 11:07:02 +00:00
|
|
|
|
|
|
|
return true;
|
2009-01-28 00:36:49 +00:00
|
|
|
}
|
2012-09-02 11:07:02 +00:00
|
|
|
|
2020-10-12 11:53:55 +00:00
|
|
|
throw new MWException( "Invalid action $action" );
|
2009-01-28 00:36:49 +00:00
|
|
|
}
|
2009-02-07 09:34:11 +00:00
|
|
|
}
|