2009-01-28 00:36:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class AbuseFilterViewRevert extends AbuseFilterView {
|
2013-10-15 13:22:05 +00:00
|
|
|
public $origPeriodStart, $origPeriodEnd, $mPeriodStart, $mPeriodEnd,
|
|
|
|
$mReason;
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
function show() {
|
2018-03-25 14:17:31 +00:00
|
|
|
$lang = $this->getLanguage();
|
2009-01-28 00:36:49 +00:00
|
|
|
$filter = $this->mPage->mFilter;
|
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$user = $this->getUser();
|
|
|
|
$out = $this->getOutput();
|
2009-01-28 00:36:49 +00:00
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
if ( !$user->isAllowed( 'abusefilter-revert' ) ) {
|
|
|
|
throw new PermissionsError( 'abusefilter-revert' );
|
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
|
|
|
|
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(
|
|
|
|
SpecialPage::getTitleFor( 'AbuseFilter', intval( $filter ) ),
|
|
|
|
$lang->formatNum( intval( $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() )
|
|
|
|
->addHiddenField( 'submit', 1 )
|
|
|
|
->setAction( $this->getTitle( "revert/$filter" )->getLocalURL() )
|
|
|
|
->setWrapperLegendMsg( 'abusefilter-revert-search-legend' )
|
|
|
|
->setSubmitTextMsg( 'abusefilter-revert-search' )
|
|
|
|
->setMethod( 'post' )
|
|
|
|
->prepareForm()
|
|
|
|
->displayForm( false );
|
2009-01-28 00:36:49 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $this->mSubmit ) {
|
2009-01-28 00:36:49 +00:00
|
|
|
// Add a summary of everything that will be reversed.
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-revert-preview-intro' );
|
2009-01-28 00:36:49 +00:00
|
|
|
|
|
|
|
// Look up all of them.
|
|
|
|
$results = $this->doLookup();
|
2017-06-15 14:23:16 +00:00
|
|
|
$list = [];
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $results as $result ) {
|
|
|
|
$displayActions = array_map(
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'AbuseFilter', 'getActionDisplay' ],
|
2009-02-07 09:34:11 +00:00
|
|
|
$result['actions'] );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-09-02 11:07:02 +00:00
|
|
|
$msg = $this->msg( 'abusefilter-revert-preview-item' )
|
|
|
|
->rawParams(
|
2011-11-16 05:34:24 +00:00
|
|
|
$lang->timeanddate( $result['timestamp'], true ),
|
2012-03-11 20:51:54 +00:00
|
|
|
Linker::userLink( $result['userid'], $result['user'] ),
|
2009-10-07 13:57:06 +00:00
|
|
|
$result['action'],
|
2016-12-04 15:13:16 +00:00
|
|
|
$this->linkRenderer->makeLink( $result['title'] ),
|
2011-11-16 05:34:24 +00:00
|
|
|
$lang->commaList( $displayActions ),
|
2016-12-04 15:13:16 +00:00
|
|
|
$this->linkRenderer->makeLink(
|
2009-10-07 13:57:06 +00:00
|
|
|
SpecialPage::getTitleFor( 'AbuseLog' ),
|
2016-12-04 15:13:16 +00:00
|
|
|
$this->msg( 'abusefilter-log-detailslink' )->text(),
|
2017-06-15 14:23:16 +00:00
|
|
|
[],
|
|
|
|
[ 'details' => $result['id'] ]
|
2009-10-07 13:57:06 +00:00
|
|
|
)
|
2016-06-04 13:07:40 +00:00
|
|
|
)->params( $result['user'] )->parse();
|
2009-01-28 00:36:49 +00:00
|
|
|
$list[] = Xml::tags( 'li', null, $msg );
|
|
|
|
}
|
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addHTML( Xml::tags( 'ul', null, implode( "\n", $list ) ) );
|
2009-01-28 00:36:49 +00:00
|
|
|
|
|
|
|
// Add a button down the bottom.
|
2018-03-25 14:17:31 +00:00
|
|
|
$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',
|
|
|
|
];
|
|
|
|
HTMLForm::factory( 'ooui', $confirmForm, $this->getContext() )
|
|
|
|
->setAction( $this->getTitle( "revert/$filter" )->getLocalURL() )
|
|
|
|
->setWrapperLegendMsg( 'abusefilter-revert-confirm-legend' )
|
|
|
|
->setSubmitTextMsg( 'abusefilter-revert-confirm' )
|
|
|
|
->setMethod( 'post' )
|
|
|
|
->prepareForm()
|
|
|
|
->displayForm( false );
|
|
|
|
|
2009-01-28 00:36:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function doLookup() {
|
|
|
|
$periodStart = $this->mPeriodStart;
|
|
|
|
$periodEnd = $this->mPeriodEnd;
|
|
|
|
$filter = $this->mPage->mFilter;
|
|
|
|
|
2017-06-15 14:23:16 +00:00
|
|
|
$conds = [ 'afl_filter' => $filter ];
|
2009-01-28 00:36:49 +00:00
|
|
|
|
2017-08-30 02:51:39 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2009-01-28 00:36:49 +00:00
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $periodStart ) {
|
2010-02-13 14:10:36 +00:00
|
|
|
$conds[] = 'afl_timestamp>' . $dbr->addQuotes( $dbr->timestamp( $periodStart ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
|
|
|
if ( $periodEnd ) {
|
2010-02-13 14:10:36 +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
|
|
|
|
|
|
|
// Database query.
|
|
|
|
$res = $dbr->select( 'abuse_filter_log', '*', $conds, __METHOD__ );
|
|
|
|
|
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,
|
|
|
|
'vars' => AbuseFilter::loadVarDump( $row->afl_var_dump ),
|
|
|
|
'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;
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadParameters() {
|
2011-11-16 05:34:24 +00:00
|
|
|
$request = $this->getRequest();
|
2009-02-07 09:34:11 +00:00
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$this->origPeriodStart = $request->getText( 'wpPeriodStart' );
|
2009-02-07 09:34:11 +00:00
|
|
|
$this->mPeriodStart = strtotime( $this->origPeriodStart );
|
2011-11-16 05:34:24 +00:00
|
|
|
$this->origPeriodEnd = $request->getText( 'wpPeriodEnd' );
|
2009-02-07 09:34:11 +00:00
|
|
|
$this->mPeriodEnd = strtotime( $this->origPeriodEnd );
|
2011-11-16 05:34:24 +00:00
|
|
|
$this->mSubmit = $request->getVal( 'submit' );
|
|
|
|
$this->mReason = $request->getVal( 'wpReason' );
|
2009-01-28 00:36:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function attemptRevert() {
|
|
|
|
$filter = $this->mPage->mFilter;
|
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 ) {
|
2009-01-28 00:36:49 +00:00
|
|
|
$actions = $result['actions'];
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $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
|
|
|
|
*/
|
2009-01-28 00:36:49 +00:00
|
|
|
function revertAction( $action, $result ) {
|
2015-09-28 18:03:35 +00:00
|
|
|
switch ( $action ) {
|
2009-01-28 00:36:49 +00:00
|
|
|
case 'block':
|
2016-03-14 17:17:23 +00:00
|
|
|
$block = Block::newFromTarget( $result['user'] );
|
|
|
|
if ( !( $block && $block->getBy() == AbuseFilter::getFilterUser()->getId() ) ) {
|
|
|
|
// 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(
|
2009-10-07 13:57:06 +00:00
|
|
|
'abusefilter-revert-reason', $this->mPage->mFilter, $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':
|
2015-05-21 21:54:30 +00:00
|
|
|
ObjectCache::getMainStashInstance()->delete(
|
2017-08-07 23:22:48 +00:00
|
|
|
AbuseFilter::autoPromoteBlockKey( User::newFromId( $result['userid'] ) )
|
2015-05-21 21:54:30 +00:00
|
|
|
);
|
2012-09-02 11:07:02 +00:00
|
|
|
return true;
|
2009-01-28 00:36:49 +00:00
|
|
|
case 'degroup':
|
|
|
|
// Pull the user's groups from the vars.
|
|
|
|
$oldGroups = $result['vars']['USER_GROUPS'];
|
2009-10-07 13:57:06 +00:00
|
|
|
$oldGroups = explode( ',', $oldGroups );
|
|
|
|
$oldGroups = array_diff(
|
|
|
|
$oldGroups,
|
|
|
|
array_intersect( $oldGroups, User::getImplicitGroups() )
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-28 00:36:49 +00:00
|
|
|
|
2017-06-15 14:23:16 +00:00
|
|
|
$rows = [];
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $oldGroups as $group ) {
|
2017-06-15 14:23:16 +00:00
|
|
|
$rows[] = [
|
2010-08-19 21:12:09 +00:00
|
|
|
'ug_user' => $result['userid'],
|
|
|
|
'ug_group' => $group
|
2017-06-15 14:23:16 +00:00
|
|
|
];
|
2009-01-28 00:36:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cheat a little bit. User::addGroup repeatedly is too slow.
|
|
|
|
$user = User::newFromId( $result['userid'] );
|
|
|
|
$currentGroups = $user->getGroups();
|
|
|
|
$newGroups = array_merge( $oldGroups, $currentGroups );
|
|
|
|
|
|
|
|
// Don't do anything if there are no groups to add.
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( !count( array_diff( $newGroups, $currentGroups ) ) ) {
|
2012-09-02 11:07:02 +00:00
|
|
|
return false;
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-01-28 00:36:49 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2017-06-15 14:23:16 +00:00
|
|
|
$dbw->insert( 'user_groups', $rows, __METHOD__, [ 'IGNORE' ] );
|
2009-01-28 00:36:49 +00:00
|
|
|
$user->invalidateCache();
|
|
|
|
|
|
|
|
$log = new LogPage( 'rights' );
|
2009-10-07 13:57:06 +00:00
|
|
|
$log->addEntry( 'rights', $user->getUserPage(),
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg(
|
2009-10-07 13:57:06 +00:00
|
|
|
'abusefilter-revert-reason',
|
|
|
|
$this->mPage->mFilter,
|
|
|
|
$this->mReason
|
2012-09-02 11:07:02 +00:00
|
|
|
)->inContentLanguage()->text(),
|
2017-06-15 14:23:16 +00:00
|
|
|
[ implode( ',', $currentGroups ), implode( ',', $newGroups ) ]
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
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
|
|
|
|
|
|
|
throw new MWException( 'Invalid action' . $action );
|
2009-01-28 00:36:49 +00:00
|
|
|
}
|
2009-02-07 09:34:11 +00:00
|
|
|
}
|