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;
|
2022-05-28 12:03:28 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\ActionSpecifier;
|
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;
|
2022-05-28 12:03:28 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\Variables\UnsetVariableException;
|
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 PermissionsError;
|
|
|
|
use SpecialPage;
|
2020-11-29 15:18:32 +00:00
|
|
|
use TitleValue;
|
2023-06-07 15:41:20 +00:00
|
|
|
use UnexpectedValueException;
|
2020-11-29 10:53:29 +00:00
|
|
|
use UserBlockedError;
|
2023-02-26 12:51:08 +00:00
|
|
|
use Wikimedia\Rdbms\LBFactory;
|
2020-11-29 10:53:29 +00:00
|
|
|
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
|
|
|
/**
|
2022-03-20 15:07:59 +00:00
|
|
|
* @var string|null The start time of the lookup period
|
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
|
|
|
/**
|
2022-03-20 15:07:59 +00:00
|
|
|
* @var string|null The end time of the lookup period
|
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;
|
2023-02-26 12:51:08 +00:00
|
|
|
/**
|
|
|
|
* @var LBFactory
|
|
|
|
*/
|
|
|
|
private $lbFactory;
|
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
|
|
|
/**
|
2023-02-26 12:51:08 +00:00
|
|
|
* @param LBFactory $lbFactory
|
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(
|
2023-02-26 12:51:08 +00:00
|
|
|
LBFactory $lbFactory,
|
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 );
|
2023-02-26 12:51:08 +00:00
|
|
|
$this->lbFactory = $lbFactory;
|
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
|
|
|
|
2022-07-02 13:35:00 +00:00
|
|
|
$performer = $this->getAuthority();
|
2011-11-16 05:34:24 +00:00
|
|
|
$out = $this->getOutput();
|
2009-01-28 00:36:49 +00:00
|
|
|
|
2022-07-02 13:35:00 +00:00
|
|
|
if ( !$this->afPermManager->canRevertFilterActions( $performer ) ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
throw new PermissionsError( 'abusefilter-revert' );
|
2009-01-28 00:36:49 +00:00
|
|
|
}
|
|
|
|
|
2022-07-02 13:35:00 +00:00
|
|
|
$block = $performer->getBlock();
|
2019-09-14 13:04:37 +00:00
|
|
|
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'
|
|
|
|
];
|
2022-03-20 15:07:59 +00:00
|
|
|
$searchFields['PeriodStart'] = [
|
2018-03-25 14:17:31 +00:00
|
|
|
'type' => 'datetime',
|
|
|
|
'label-message' => 'abusefilter-revert-periodstart',
|
|
|
|
'min' => $min,
|
|
|
|
'max' => $max
|
|
|
|
];
|
2022-03-20 15:07:59 +00:00
|
|
|
$searchFields['PeriodEnd'] = [
|
2018-03-25 14:17:31 +00:00
|
|
|
'type' => 'datetime',
|
|
|
|
'label-message' => 'abusefilter-revert-periodend',
|
|
|
|
'min' => $min,
|
|
|
|
'max' => $max
|
|
|
|
];
|
|
|
|
|
|
|
|
HTMLForm::factory( 'ooui', $searchFields, $this->getContext() )
|
2022-03-20 15:07:59 +00:00
|
|
|
->setTitle( $this->getTitle( "revert/$filter" ) )
|
2018-03-25 14:17:31 +00:00
|
|
|
->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 === [] ) {
|
2022-05-24 07:31:17 +00:00
|
|
|
$dateForm->addPostHtml( $this->msg( 'abusefilter-revert-preview-no-results' )->escaped() );
|
2020-11-10 09:45:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a summary of everything that will be reversed.
|
2022-05-24 07:31:17 +00:00
|
|
|
$dateForm->addPostHtml( $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
|
|
|
|
2022-05-28 12:03:28 +00:00
|
|
|
/** @var ActionSpecifier $spec */
|
|
|
|
$spec = $result['spec'];
|
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(
|
2022-05-28 12:03:28 +00:00
|
|
|
Linker::userLink( $spec->getUser()->getId(), $spec->getUser()->getName() )
|
2020-10-04 12:38:18 +00:00
|
|
|
)->params(
|
2022-05-28 12:03:28 +00:00
|
|
|
$spec->getAction()
|
2020-10-04 12:38:18 +00:00
|
|
|
)->rawParams(
|
2022-05-28 12:03:28 +00:00
|
|
|
$this->linkRenderer->makeLink( $spec->getTitle() )
|
2020-10-04 12:38:18 +00:00
|
|
|
)->params(
|
|
|
|
$lang->commaList( $displayActions )
|
|
|
|
)->rawParams(
|
|
|
|
$this->linkRenderer->makeLink(
|
|
|
|
SpecialPage::getTitleFor( 'AbuseLog' ),
|
|
|
|
$this->msg( 'abusefilter-log-detailslink' )->text(),
|
|
|
|
[],
|
|
|
|
[ 'details' => $result['id'] ]
|
|
|
|
)
|
2022-05-28 12:03:28 +00:00
|
|
|
)->params(
|
|
|
|
$spec->getUser()->getName()
|
|
|
|
)->parse();
|
2020-10-04 12:38:18 +00:00
|
|
|
$list[] = Xml::tags( 'li', null, $msg );
|
2009-01-28 00:36:49 +00:00
|
|
|
}
|
2020-10-04 12:38:18 +00:00
|
|
|
|
2022-05-24 07:31:17 +00:00
|
|
|
$dateForm->addPostHtml( Xml::tags( 'ul', null, implode( "\n", $list ) ) );
|
2020-10-04 12:38:18 +00:00
|
|
|
|
|
|
|
// Add a button down the bottom.
|
|
|
|
$confirmForm = [];
|
2022-03-20 15:07:59 +00:00
|
|
|
$confirmForm['PeriodStart'] = [
|
2020-10-04 12:38:18 +00:00
|
|
|
'type' => 'hidden',
|
|
|
|
];
|
2022-03-20 15:07:59 +00:00
|
|
|
$confirmForm['PeriodEnd'] = [
|
2020-10-04 12:38:18 +00:00
|
|
|
'type' => 'hidden',
|
|
|
|
];
|
2022-03-20 15:07:59 +00:00
|
|
|
$confirmForm['Reason'] = [
|
2020-10-04 12:38:18 +00:00
|
|
|
'type' => 'text',
|
|
|
|
'label-message' => 'abusefilter-revert-reasonfield',
|
|
|
|
'id' => 'wpReason',
|
|
|
|
];
|
|
|
|
|
|
|
|
$revertForm = HTMLForm::factory( 'ooui', $confirmForm, $this->getContext() )
|
2022-03-20 15:07:59 +00:00
|
|
|
->setTitle( $this->getTitle( "revert/$filter" ) )
|
|
|
|
->setTokenSalt( "abusefilter-revert-$filter" )
|
2020-10-04 12:38:18 +00:00
|
|
|
->setWrapperLegendMsg( 'abusefilter-revert-confirm-legend' )
|
|
|
|
->setSubmitTextMsg( 'abusefilter-revert-confirm' )
|
|
|
|
->prepareForm()
|
|
|
|
->getHTML( true );
|
2022-05-24 07:31:17 +00:00
|
|
|
$dateForm->addPostHtml( $revertForm );
|
2020-10-04 12:38:18 +00:00
|
|
|
|
|
|
|
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() {
|
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;
|
2023-02-26 12:51:08 +00:00
|
|
|
$dbr = $this->lbFactory->getReplicaDatabase();
|
2009-01-28 00:36:49 +00:00
|
|
|
|
2019-02-06 16:07:01 +00:00
|
|
|
// Only hits from local filters can be reverted
|
|
|
|
$conds = [ 'afl_filter_id' => $filter, 'afl_global' => 0 ];
|
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',
|
2022-07-10 08:19:41 +00:00
|
|
|
'afl_ip',
|
2018-08-31 14:19:44 +00:00
|
|
|
'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
|
|
|
|
2022-05-28 12:03:28 +00:00
|
|
|
// TODO: get the following from ConsequencesRegistry or sth else
|
|
|
|
static $reversibleActions = [ 'block', 'blockautopromote', 'degroup' ];
|
|
|
|
|
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 );
|
2009-01-28 00:36:49 +00:00
|
|
|
$currentReversibleActions = array_intersect( $actions, $reversibleActions );
|
|
|
|
if ( count( $currentReversibleActions ) ) {
|
2022-05-28 12:03:28 +00:00
|
|
|
$vars = $this->varBlobStore->loadVarDump( $row->afl_var_dump );
|
|
|
|
try {
|
|
|
|
// The variable is not lazy-loaded
|
|
|
|
$accountName = $vars->getComputedVariable( 'accountname' )->toNative();
|
|
|
|
} catch ( UnsetVariableException $_ ) {
|
|
|
|
$accountName = null;
|
|
|
|
}
|
2017-06-15 14:23:16 +00:00
|
|
|
$results[] = [
|
2013-06-26 22:58:36 +00:00
|
|
|
'id' => $row->afl_id,
|
|
|
|
'actions' => $currentReversibleActions,
|
2022-05-28 12:03:28 +00:00
|
|
|
'vars' => $vars,
|
|
|
|
'spec' => new ActionSpecifier(
|
|
|
|
$row->afl_action,
|
|
|
|
new TitleValue( (int)$row->afl_namespace, $row->afl_title ),
|
|
|
|
$this->userFactory->newFromAnyId( (int)$row->afl_user, $row->afl_user_text ),
|
2022-07-10 08:19:41 +00:00
|
|
|
$row->afl_ip,
|
2022-05-28 12:03:28 +00:00
|
|
|
$accountName
|
|
|
|
),
|
2013-06-26 22:58:36 +00:00
|
|
|
'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];
|
2022-03-20 15:07:59 +00:00
|
|
|
$this->periodStart = strtotime( $request->getText( 'wpPeriodStart' ) ) ?: null;
|
|
|
|
$this->periodEnd = strtotime( $request->getText( 'wpPeriodEnd' ) ) ?: null;
|
2021-04-02 17:22:18 +00:00
|
|
|
$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;
|
2022-03-20 15:07:59 +00:00
|
|
|
$token = $this->getRequest()->getVal( 'wpEditToken' );
|
2011-11-16 05:34:24 +00:00
|
|
|
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
|
|
|
*/
|
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,
|
2022-05-28 12:03:28 +00:00
|
|
|
$result['spec']
|
2020-11-29 15:18:32 +00:00
|
|
|
);
|
|
|
|
|
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:
|
2023-06-07 15:41:20 +00:00
|
|
|
throw new UnexpectedValueException( "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
|
|
|
|
*/
|
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 );
|
2022-06-08 09:59:18 +00:00
|
|
|
return $consequence->revert( $this->getUser(), $message );
|
2009-01-28 00:36:49 +00:00
|
|
|
}
|
2009-02-07 09:34:11 +00:00
|
|
|
}
|