2009-01-28 00:36:49 +00:00
|
|
|
<?php
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
2009-01-28 00:36:49 +00:00
|
|
|
die();
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-28 00:36:49 +00:00
|
|
|
|
|
|
|
class AbuseFilterViewRevert extends AbuseFilterView {
|
2009-10-07 13:57:06 +00:00
|
|
|
function show() {
|
2009-01-28 00:36:49 +00:00
|
|
|
$filter = $this->mPage->mFilter;
|
|
|
|
|
2010-07-24 21:12:27 +00:00
|
|
|
global $wgUser, $wgOut;
|
2009-01-28 00:36:49 +00:00
|
|
|
$sk = $wgUser->getSkin();
|
|
|
|
|
|
|
|
if ( !$wgUser->isAllowed( 'abusefilter-revert' ) ) {
|
|
|
|
$wgOut->permissionRequired( 'abusefilter-revert' );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$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
|
|
|
|
|
|
|
$wgOut->addWikiMsg( 'abusefilter-revert-intro', $filter );
|
2010-02-13 14:10:36 +00:00
|
|
|
$wgOut->setPageTitle( wfMsg( 'abusefilter-revert-title', $filter ) );
|
2009-01-28 00:36:49 +00:00
|
|
|
|
|
|
|
// First, the search form.
|
|
|
|
$searchFields = array();
|
2010-02-13 14:10:36 +00:00
|
|
|
$searchFields['abusefilter-revert-filter'] =
|
2009-02-07 09:34:11 +00:00
|
|
|
Xml::element( 'strong', null, $filter );
|
2010-02-13 14:10:36 +00:00
|
|
|
$searchFields['abusefilter-revert-periodstart'] =
|
2009-02-07 09:34:11 +00:00
|
|
|
Xml::input( 'wpPeriodStart', 45, $this->origPeriodStart );
|
2010-02-13 14:10:36 +00:00
|
|
|
$searchFields['abusefilter-revert-periodend'] =
|
2009-02-07 09:34:11 +00:00
|
|
|
Xml::input( 'wpPeriodEnd', 45, $this->origPeriodEnd );
|
2009-01-28 00:36:49 +00:00
|
|
|
$searchForm = Xml::buildForm( $searchFields, 'abusefilter-revert-search' );
|
2010-10-29 15:14:44 +00:00
|
|
|
$searchForm .= "\n" . Html::hidden( 'submit', 1 );
|
2009-10-07 13:57:06 +00:00
|
|
|
$searchForm =
|
|
|
|
Xml::tags(
|
|
|
|
'form',
|
|
|
|
array(
|
|
|
|
'action' => $this->getTitle( "revert/$filter" )->getLocalURL(),
|
2010-08-19 21:12:09 +00:00
|
|
|
'method' => 'post'
|
2009-10-07 13:57:06 +00:00
|
|
|
),
|
|
|
|
$searchForm
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-10-07 13:57:06 +00:00
|
|
|
$searchForm =
|
2009-02-07 09:34:11 +00:00
|
|
|
Xml::fieldset( wfMsg( 'abusefilter-revert-search-legend' ), $searchForm );
|
2009-01-28 00:36:49 +00:00
|
|
|
|
|
|
|
$wgOut->addHTML( $searchForm );
|
|
|
|
|
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.
|
|
|
|
$wgOut->addWikiMsg( 'abusefilter-revert-preview-intro' );
|
|
|
|
|
|
|
|
// Look up all of them.
|
|
|
|
$results = $this->doLookup();
|
|
|
|
$list = array();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $results as $result ) {
|
2009-01-28 00:36:49 +00:00
|
|
|
global $wgLang;
|
2010-02-13 14:10:36 +00:00
|
|
|
$displayActions = array_map(
|
|
|
|
array( 'AbuseFilter', 'getActionDisplay' ),
|
2009-02-07 09:34:11 +00:00
|
|
|
$result['actions'] );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
|
|
|
$msg = wfMsgExt(
|
|
|
|
'abusefilter-revert-preview-item',
|
2009-02-07 09:34:11 +00:00
|
|
|
array( 'parseinline', 'replaceafter' ),
|
2009-10-07 13:57:06 +00:00
|
|
|
array(
|
|
|
|
$wgLang->timeanddate( $result['timestamp'], true ),
|
|
|
|
$sk->userLink( $result['userid'], $result['user'] ),
|
|
|
|
$result['action'],
|
|
|
|
$sk->link( $result['title'] ),
|
2010-03-13 17:23:08 +00:00
|
|
|
$wgLang->commaList( $displayActions ),
|
2009-10-07 13:57:06 +00:00
|
|
|
$sk->link(
|
|
|
|
SpecialPage::getTitleFor( 'AbuseLog' ),
|
|
|
|
wfMsgNoTrans( 'abusefilter-log-detailslink' ),
|
|
|
|
array(),
|
2010-02-13 14:10:36 +00:00
|
|
|
array( 'details' => $result['id'] )
|
2009-10-07 13:57:06 +00:00
|
|
|
)
|
2009-02-07 09:34:11 +00:00
|
|
|
)
|
|
|
|
);
|
2009-01-28 00:36:49 +00:00
|
|
|
$list[] = Xml::tags( 'li', null, $msg );
|
|
|
|
}
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$wgOut->addHTML( Xml::tags( 'ul', null, implode( "\n", $list ) ) );
|
2009-01-28 00:36:49 +00:00
|
|
|
|
|
|
|
// Add a button down the bottom.
|
2010-02-13 14:10:36 +00:00
|
|
|
$confirmForm =
|
2010-10-29 15:14:44 +00:00
|
|
|
Html::hidden( 'editToken', $wgUser->editToken( "abusefilter-revert-$filter" ) ) .
|
|
|
|
Html::hidden( 'title', $this->getTitle( "revert/$filter" )->getPrefixedText() ) .
|
|
|
|
Html::hidden( 'wpPeriodStart', $this->origPeriodStart ) .
|
|
|
|
Html::hidden( 'wpPeriodEnd', $this->origPeriodEnd ) .
|
|
|
|
Html::inputLabel(
|
2009-10-07 13:57:06 +00:00
|
|
|
wfMsg( 'abusefilter-revert-reasonfield' ),
|
|
|
|
'wpReason', 'wpReason', 45
|
|
|
|
) .
|
2009-02-07 09:34:11 +00:00
|
|
|
"\n" .
|
|
|
|
Xml::submitButton( wfMsg( 'abusefilter-revert-confirm' ) );
|
2009-10-07 13:57:06 +00:00
|
|
|
$confirmForm = Xml::tags(
|
|
|
|
'form',
|
|
|
|
array(
|
|
|
|
'action' => $this->getTitle( "revert/$filter" )->getLocalURL(),
|
|
|
|
'method' => 'post'
|
2010-02-13 14:10:36 +00:00
|
|
|
),
|
2009-10-07 13:57:06 +00:00
|
|
|
$confirmForm
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-28 00:36:49 +00:00
|
|
|
$wgOut->addHTML( $confirmForm );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function doLookup() {
|
|
|
|
$periodStart = $this->mPeriodStart;
|
|
|
|
$periodEnd = $this->mPeriodEnd;
|
|
|
|
$filter = $this->mPage->mFilter;
|
|
|
|
|
|
|
|
$conds = array( 'afl_filter' => $filter );
|
|
|
|
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
|
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__ );
|
|
|
|
|
|
|
|
$results = array();
|
2010-08-19 21:12:09 +00:00
|
|
|
foreach( $res as $row ) {
|
|
|
|
if ( !$row->afl_actions ) {
|
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 );
|
2009-01-28 00:36:49 +00:00
|
|
|
$reversibleActions = array( 'block', 'blockautopromote', 'degroup' );
|
|
|
|
$currentReversibleActions = array_intersect( $actions, $reversibleActions );
|
|
|
|
if ( count( $currentReversibleActions ) ) {
|
2009-10-07 13:57:06 +00:00
|
|
|
$results[] = array(
|
|
|
|
'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
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-28 00:36:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadParameters() {
|
|
|
|
global $wgRequest;
|
2009-02-07 09:34:11 +00:00
|
|
|
|
|
|
|
$this->origPeriodStart = $wgRequest->getText( 'wpPeriodStart' );
|
|
|
|
$this->mPeriodStart = strtotime( $this->origPeriodStart );
|
|
|
|
$this->origPeriodEnd = $wgRequest->getText( 'wpPeriodEnd' );
|
|
|
|
$this->mPeriodEnd = strtotime( $this->origPeriodEnd );
|
2009-01-28 00:36:49 +00:00
|
|
|
$this->mSubmit = $wgRequest->getVal( 'submit' );
|
|
|
|
$this->mReason = $wgRequest->getVal( 'wpReason' );
|
|
|
|
}
|
|
|
|
|
|
|
|
function attemptRevert() {
|
|
|
|
global $wgUser, $wgRequest, $wgOut;
|
|
|
|
|
|
|
|
$filter = $this->mPage->mFilter;
|
|
|
|
$token = $wgRequest->getVal( 'editToken' );
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( !$wgUser->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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$wgOut->addWikiMsg( 'abusefilter-revert-success', $filter );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-01-28 00:36:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function revertAction( $action, $result ) {
|
|
|
|
switch( $action ) {
|
|
|
|
case 'block':
|
2011-03-19 23:47:08 +00:00
|
|
|
$block = Block::newFromTarget( User::whoIs( $result['userid'] ) );
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( !$block || $block->getBy() != AbuseFilter::getFilterUser()->getId() ) {
|
2009-01-28 00:36:49 +00:00
|
|
|
return false; // Not blocked by abuse filter.
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-28 00:36:49 +00:00
|
|
|
|
|
|
|
$block->delete();
|
|
|
|
$log = new LogPage( 'block' );
|
2009-10-07 13:57:06 +00:00
|
|
|
$log->addEntry(
|
|
|
|
'unblock',
|
|
|
|
Title::makeTitle( NS_USER, $result['user'] ),
|
|
|
|
wfMsgForContent(
|
|
|
|
'abusefilter-revert-reason', $this->mPage->mFilter, $this->mReason
|
|
|
|
)
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-28 00:36:49 +00:00
|
|
|
break;
|
|
|
|
case 'blockautopromote':
|
|
|
|
global $wgMemc;
|
2010-02-13 14:10:36 +00:00
|
|
|
$wgMemc->delete( AbuseFilter::autopromoteBlockKey(
|
2009-02-07 09:34:11 +00:00
|
|
|
User::newFromId( $result['userid'] ) ) );
|
2009-01-28 00:36:49 +00:00
|
|
|
break;
|
|
|
|
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
|
|
|
|
|
|
|
$rows = array();
|
2010-02-13 14:10:36 +00:00
|
|
|
foreach ( $oldGroups as $group ) {
|
2010-08-19 21:12:09 +00:00
|
|
|
$rows[] = array(
|
|
|
|
'ug_user' => $result['userid'],
|
|
|
|
'ug_group' => $group
|
|
|
|
);
|
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 ) ) ) {
|
2009-01-28 00:36:49 +00:00
|
|
|
return;
|
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 );
|
2009-10-07 13:57:06 +00:00
|
|
|
$dbw->insert( 'user_groups', $rows, __METHOD__, array( '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(),
|
|
|
|
wfMsgForContent(
|
|
|
|
'abusefilter-revert-reason',
|
|
|
|
$this->mPage->mFilter,
|
|
|
|
$this->mReason
|
2009-02-07 09:34:11 +00:00
|
|
|
),
|
2010-02-13 14:10:36 +00:00
|
|
|
array( implode( ',', $currentGroups ), implode( ',', $newGroups ) )
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-28 00:36:49 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-07 09:34:11 +00:00
|
|
|
}
|