2009-01-28 00:36:49 +00:00
|
|
|
<?php
|
|
|
|
|
2020-11-29 10:53:29 +00:00
|
|
|
namespace MediaWiki\Extension\AbuseFilter\View;
|
|
|
|
|
2021-04-27 14:42:55 +00:00
|
|
|
use Html;
|
2020-11-29 10:53:29 +00:00
|
|
|
use HTMLForm;
|
|
|
|
use IContextSource;
|
|
|
|
use Linker;
|
2020-10-23 14:19:02 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager;
|
2020-11-29 15:18:32 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\Consequences\Consequence\ReversibleConsequence;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\Consequences\ConsequencesFactory;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\Consequences\Parameters;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\FilterLookup;
|
2020-10-02 15:08:48 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\SpecsFormatter;
|
2021-01-02 13:41:31 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\Variables\VariablesBlobStore;
|
2020-10-23 14:19:02 +00:00
|
|
|
use MediaWiki\Linker\LinkRenderer;
|
2020-11-29 15:18:32 +00:00
|
|
|
use MediaWiki\User\UserFactory;
|
2020-11-29 10:53:29 +00:00
|
|
|
use Message;
|
|
|
|
use MWException;
|
|
|
|
use PermissionsError;
|
|
|
|
use SpecialPage;
|
2020-11-29 15:18:32 +00:00
|
|
|
use TitleValue;
|
2020-11-29 10:53:29 +00:00
|
|
|
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
|
|
|
|
*/
|
2021-04-02 17:22:18 +00:00
|
|
|
private $origPeriodStart;
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
|
|
|
* @var string The end time of the lookup period
|
|
|
|
*/
|
2021-04-02 17:22:18 +00:00
|
|
|
private $origPeriodEnd;
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
2019-12-07 17:20:10 +00:00
|
|
|
* @var string|null The same as $origPeriodStart
|
2018-11-08 14:34:32 +00:00
|
|
|
*/
|
2021-04-02 17:22:18 +00:00
|
|
|
private $periodStart;
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
2019-12-07 17:20:10 +00:00
|
|
|
* @var string|null The same as $origPeriodEnd
|
2018-11-08 14:34:32 +00:00
|
|
|
*/
|
2021-04-02 17:22:18 +00:00
|
|
|
private $periodEnd;
|
2018-11-08 14:34:32 +00:00
|
|
|
/**
|
|
|
|
* @var string|null The reason provided for the revert
|
|
|
|
*/
|
2021-04-02 17:22:18 +00:00
|
|
|
private $reason;
|
2020-10-23 14:19:02 +00:00
|
|
|
/**
|
2020-11-29 15:18:32 +00:00
|
|
|
* @var UserFactory
|
2020-10-23 14:19:02 +00:00
|
|
|
*/
|
2020-11-29 15:18:32 +00:00
|
|
|
private $userFactory;
|
2020-10-23 14:19:02 +00:00
|
|
|
/**
|
2020-11-29 15:18:32 +00:00
|
|
|
* @var FilterLookup
|
2020-10-23 14:19:02 +00:00
|
|
|
*/
|
2020-11-29 15:18:32 +00:00
|
|
|
private $filterLookup;
|
2020-10-23 14:19:02 +00:00
|
|
|
/**
|
2020-11-29 15:18:32 +00:00
|
|
|
* @var ConsequencesFactory
|
2020-10-23 14:19:02 +00:00
|
|
|
*/
|
2020-11-29 15:18:32 +00:00
|
|
|
private $consequencesFactory;
|
2020-09-29 14:52:05 +00:00
|
|
|
/**
|
|
|
|
* @var VariablesBlobStore
|
|
|
|
*/
|
|
|
|
private $varBlobStore;
|
2020-10-02 15:08:48 +00:00
|
|
|
/**
|
|
|
|
* @var SpecsFormatter
|
|
|
|
*/
|
|
|
|
private $specsFormatter;
|
|
|
|
|
2020-10-23 14:19:02 +00:00
|
|
|
/**
|
2020-11-29 15:18:32 +00:00
|
|
|
* @param UserFactory $userFactory
|
2020-10-23 14:19:02 +00:00
|
|
|
* @param AbuseFilterPermissionManager $afPermManager
|
2020-11-29 15:18:32 +00:00
|
|
|
* @param FilterLookup $filterLookup
|
|
|
|
* @param ConsequencesFactory $consequencesFactory
|
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(
|
2020-11-29 15:18:32 +00:00
|
|
|
UserFactory $userFactory,
|
2020-10-23 14:19:02 +00:00
|
|
|
AbuseFilterPermissionManager $afPermManager,
|
2020-11-29 15:18:32 +00:00
|
|
|
FilterLookup $filterLookup,
|
|
|
|
ConsequencesFactory $consequencesFactory,
|
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 );
|
2020-11-29 15:18:32 +00:00
|
|
|
$this->userFactory = $userFactory;
|
|
|
|
$this->filterLookup = $filterLookup;
|
|
|
|
$this->consequencesFactory = $consequencesFactory;
|
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
|
|
|
|
*/
|
2021-07-21 18:51:12 +00:00
|
|
|
public function showRevertableActions( array $formData, HTMLForm $dateForm ): bool {
|
2020-10-04 12:38:18 +00:00
|
|
|
$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(
|
2021-03-08 23:54:03 +00:00
|
|
|
$lang->userTimeAndDate( $result['timestamp'], $user )
|
2020-10-04 12:38:18 +00:00
|
|
|
)->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' );
|
2021-04-02 17:22:18 +00:00
|
|
|
$periodStart = $this->periodStart;
|
|
|
|
$periodEnd = $this->periodEnd;
|
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
|
|
|
|
2021-04-02 17:22:18 +00:00
|
|
|
// Don't revert if there was no action, or the action was global
|
|
|
|
$conds[] = 'afl_actions != ' . $dbr->addQuotes( '' );
|
|
|
|
$conds[] = 'afl_wiki IS NULL';
|
|
|
|
|
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',
|
|
|
|
];
|
2021-04-02 17:22:18 +00:00
|
|
|
$res = $dbr->select(
|
|
|
|
'abuse_filter_log',
|
|
|
|
$selectFields,
|
|
|
|
$conds,
|
|
|
|
__METHOD__,
|
|
|
|
[ 'ORDER BY' => 'afl_timestamp DESC' ]
|
|
|
|
);
|
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 ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
$actions = explode( ',', $row->afl_actions );
|
2020-11-29 15:18:32 +00:00
|
|
|
// TODO: get the following from ConsequencesRegistry or sth else
|
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 ),
|
2020-11-29 15:18:32 +00:00
|
|
|
'title' => new TitleValue( (int)$row->afl_namespace, $row->afl_title ),
|
2013-06-26 22:58:36 +00:00
|
|
|
'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' );
|
2021-04-02 17:22:18 +00:00
|
|
|
$this->periodStart = strtotime( $this->origPeriodStart ) ?: null;
|
2011-11-16 05:34:24 +00:00
|
|
|
$this->origPeriodEnd = $request->getText( 'wpPeriodEnd' );
|
2021-04-02 17:22:18 +00:00
|
|
|
$this->periodEnd = strtotime( $this->origPeriodEnd ) ?: null;
|
|
|
|
$this->reason = $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 );
|
|
|
|
}
|
|
|
|
}
|
2021-04-27 14:42:55 +00:00
|
|
|
$this->getOutput()->addHTML( Html::successBox(
|
|
|
|
$this->msg(
|
2018-03-25 14:17:31 +00:00
|
|
|
'abusefilter-revert-success',
|
|
|
|
$filter,
|
|
|
|
$this->getLanguage()->formatNum( $filter )
|
2021-04-27 14:42:55 +00:00
|
|
|
)->parse()
|
|
|
|
) );
|
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
|
|
|
/**
|
2020-11-29 15:18:32 +00:00
|
|
|
* Helper method for typing
|
2017-10-06 18:52:31 +00:00
|
|
|
* @param string $action
|
|
|
|
* @param array $result
|
2020-11-29 15:18:32 +00:00
|
|
|
* @return ReversibleConsequence
|
2012-09-02 11:07:02 +00:00
|
|
|
* @throws MWException
|
|
|
|
*/
|
2021-07-21 18:51:12 +00:00
|
|
|
private function getConsequence( string $action, array $result ): ReversibleConsequence {
|
2020-11-29 15:18:32 +00:00
|
|
|
$params = new Parameters(
|
|
|
|
$this->filterLookup->getFilter( $this->filter, false ),
|
|
|
|
false,
|
|
|
|
$this->userFactory->newFromAnyId(
|
|
|
|
$result['userid'],
|
|
|
|
$result['user'],
|
|
|
|
null
|
|
|
|
),
|
|
|
|
$result['title'],
|
|
|
|
$result['action']
|
|
|
|
);
|
|
|
|
|
2015-09-28 18:03:35 +00:00
|
|
|
switch ( $action ) {
|
2009-01-28 00:36:49 +00:00
|
|
|
case 'block':
|
2020-11-29 15:18:32 +00:00
|
|
|
return $this->consequencesFactory->newBlock( $params, '', false );
|
2009-01-28 00:36:49 +00:00
|
|
|
case 'blockautopromote':
|
2020-11-29 15:18:32 +00:00
|
|
|
$duration = $this->getConfig()->get( 'AbuseFilterBlockAutopromoteDuration' ) * 86400;
|
|
|
|
return $this->consequencesFactory->newBlockAutopromote( $params, $duration );
|
2009-01-28 00:36:49 +00:00
|
|
|
case 'degroup':
|
2020-11-29 15:18:32 +00:00
|
|
|
return $this->consequencesFactory->newDegroup( $params, $result['vars'] );
|
|
|
|
default:
|
|
|
|
throw new MWException( "Invalid action $action" );
|
2009-01-28 00:36:49 +00:00
|
|
|
}
|
2020-11-29 15:18:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $action
|
|
|
|
* @param array $result
|
|
|
|
* @return bool
|
|
|
|
* @throws MWException
|
|
|
|
*/
|
2021-07-21 18:51:12 +00:00
|
|
|
public function revertAction( string $action, array $result ): bool {
|
2020-11-29 15:18:32 +00:00
|
|
|
$message = $this->msg(
|
2021-04-02 17:22:18 +00:00
|
|
|
'abusefilter-revert-reason', $this->filter, $this->reason
|
2020-11-29 15:18:32 +00:00
|
|
|
)->inContentLanguage()->text();
|
2012-09-02 11:07:02 +00:00
|
|
|
|
2020-11-29 15:18:32 +00:00
|
|
|
$consequence = $this->getConsequence( $action, $result );
|
|
|
|
return $consequence->revert( $result, $this->getUser(), $message );
|
2009-01-28 00:36:49 +00:00
|
|
|
}
|
2009-02-07 09:34:11 +00:00
|
|
|
}
|