2009-01-29 22:44:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class AbuseFilterViewExamine extends AbuseFilterView {
|
2011-08-26 20:12:34 +00:00
|
|
|
public static $examineType = null;
|
|
|
|
public static $examineId = null;
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
function show() {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out = $this->getOutput();
|
|
|
|
$out->setPageTitle( $this->msg( 'abusefilter-examine' ) );
|
|
|
|
$out->addWikiMsg( 'abusefilter-examine-intro' );
|
2009-01-29 22:44:31 +00:00
|
|
|
|
|
|
|
$this->loadParameters();
|
|
|
|
|
|
|
|
// Check if we've got a subpage
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( count( $this->mParams ) > 1 && is_numeric( $this->mParams[1] ) ) {
|
2009-02-04 19:51:03 +00:00
|
|
|
$this->showExaminerForRC( $this->mParams[1] );
|
2009-10-07 13:57:06 +00:00
|
|
|
} elseif ( count( $this->mParams ) > 2
|
|
|
|
&& $this->mParams[1] == 'log'
|
|
|
|
&& is_numeric( $this->mParams[2] ) )
|
2009-02-07 09:34:11 +00:00
|
|
|
{
|
2009-02-04 19:51:03 +00:00
|
|
|
$this->showExaminerForLogEntry( $this->mParams[2] );
|
2009-01-29 22:44:31 +00:00
|
|
|
} else {
|
|
|
|
$this->showSearch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function showSearch() {
|
|
|
|
// Add selector
|
|
|
|
$selector = '';
|
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
$selectFields = array(); # Same fields as in Test
|
2009-03-21 18:47:26 +00:00
|
|
|
$selectFields['abusefilter-test-user'] = Xml::input( 'wpSearchUser', 45, $this->mSearchUser );
|
2010-02-13 14:10:36 +00:00
|
|
|
$selectFields['abusefilter-test-period-start'] =
|
2009-03-21 18:47:26 +00:00
|
|
|
Xml::input( 'wpSearchPeriodStart', 45, $this->mSearchPeriodStart );
|
2010-02-13 14:10:36 +00:00
|
|
|
$selectFields['abusefilter-test-period-end'] =
|
2009-03-21 18:47:26 +00:00
|
|
|
Xml::input( 'wpSearchPeriodEnd', 45, $this->mSearchPeriodEnd );
|
2009-01-29 22:44:31 +00:00
|
|
|
|
|
|
|
$selector .= Xml::buildForm( $selectFields, 'abusefilter-examine-submit' );
|
2010-10-29 15:14:44 +00:00
|
|
|
$selector .= Html::hidden( 'submit', 1 );
|
|
|
|
$selector .= Html::hidden( 'title', $this->getTitle( 'examine' )->getPrefixedText() );
|
2009-10-07 13:57:06 +00:00
|
|
|
$selector = Xml::tags( 'form',
|
|
|
|
array(
|
|
|
|
'action' => $this->getTitle( 'examine' )->getLocalURL(),
|
2010-08-19 21:12:09 +00:00
|
|
|
'method' => 'get'
|
2009-10-07 13:57:06 +00:00
|
|
|
),
|
|
|
|
$selector
|
|
|
|
);
|
|
|
|
$selector = Xml::fieldset(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-examine-legend' )->text(),
|
2009-10-07 13:57:06 +00:00
|
|
|
$selector
|
|
|
|
);
|
2011-11-16 05:34:24 +00:00
|
|
|
$this->getOutput()->addHTML( $selector );
|
2009-01-29 22:44:31 +00:00
|
|
|
|
2009-02-07 09:34:11 +00:00
|
|
|
if ( $this->mSubmit ) {
|
2009-01-29 22:44:31 +00:00
|
|
|
$this->showResults();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function showResults() {
|
2011-11-16 05:34:24 +00:00
|
|
|
$changesList = new AbuseFilterChangesList( $this->getSkin() );
|
2009-01-29 22:44:31 +00:00
|
|
|
$output = $changesList->beginRecentChangesList();
|
2009-03-12 11:38:21 +00:00
|
|
|
$this->mCounter = 1;
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 11:38:21 +00:00
|
|
|
$pager = new AbuseFilterExaminePager( $this, $changesList );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-22 03:12:53 +00:00
|
|
|
$output .= $pager->getNavigationBar() .
|
|
|
|
$pager->getBody() .
|
|
|
|
$pager->getNavigationBar();
|
2009-01-29 22:44:31 +00:00
|
|
|
|
|
|
|
$output .= $changesList->endRecentChangesList();
|
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$this->getOutput()->addHTML( $output );
|
2009-01-29 22:44:31 +00:00
|
|
|
}
|
|
|
|
|
2009-02-04 19:51:03 +00:00
|
|
|
function showExaminerForRC( $rcid ) {
|
2009-01-29 22:44:31 +00:00
|
|
|
// Get data
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
$row = $dbr->selectRow( 'recentchanges', '*', array( 'rc_id' => $rcid ), __METHOD__ );
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( !$row ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$this->getOutput()->addWikiMsg( 'abusefilter-examine-notfound' );
|
2009-01-29 22:44:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-26 20:12:34 +00:00
|
|
|
self::$examineType = 'rc';
|
|
|
|
self::$examineId = $rcid;
|
|
|
|
|
2009-01-29 22:44:31 +00:00
|
|
|
$vars = AbuseFilter::getVarsFromRCRow( $row );
|
|
|
|
|
2009-02-04 19:51:03 +00:00
|
|
|
$this->showExaminer( $vars );
|
|
|
|
}
|
|
|
|
|
|
|
|
function showExaminerForLogEntry( $logid ) {
|
|
|
|
// Get data
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
$row = $dbr->selectRow( 'abuse_filter_log', '*', array( 'afl_id' => $logid ), __METHOD__ );
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( !$row ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$this->getOutput()->addWikiMsg( 'abusefilter-examine-notfound' );
|
2009-02-04 19:51:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-26 20:12:34 +00:00
|
|
|
self::$examineType = 'log';
|
|
|
|
self::$examineId = $logid;
|
|
|
|
|
2012-01-03 17:29:10 +00:00
|
|
|
if ( !SpecialAbuseLog::canSeeDetails( $row->afl_filter ) ) {
|
2011-12-27 23:35:24 +00:00
|
|
|
$this->getOutput()->addWikiMsg( 'abusefilter-log-cannot-see-details' );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $row->afl_deleted && !SpecialAbuseLog::canSeeHidden() ) {
|
|
|
|
$this->getOutput()->addWikiMsg( 'abusefilter-log-details-hidden' );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-27 03:06:19 +00:00
|
|
|
$vars = AbuseFilter::loadVarDump( $row->afl_var_dump );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-04 19:51:03 +00:00
|
|
|
$this->showExaminer( $vars );
|
|
|
|
}
|
|
|
|
|
|
|
|
function showExaminer( $vars ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$output = $this->getOutput();
|
2009-02-04 19:51:03 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( !$vars ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$output->addWikiMsg( 'abusefilter-examine-incompatible' );
|
2009-01-29 22:44:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $vars instanceof AbuseFilterVariableHolder ) {
|
2009-03-25 02:53:23 +00:00
|
|
|
$vars = $vars->exportAllVars();
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-29 22:44:31 +00:00
|
|
|
|
2011-11-22 16:08:18 +00:00
|
|
|
$html = '';
|
2009-01-29 22:44:31 +00:00
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$output->addModules( 'ext.abuseFilter.examine' );
|
2009-01-29 22:44:31 +00:00
|
|
|
|
|
|
|
// Add test bit
|
2011-11-16 05:34:24 +00:00
|
|
|
if ( $this->getUser()->isAllowed( 'abusefilter-modify' ) ) {
|
2012-09-02 11:07:02 +00:00
|
|
|
$tester = Xml::tags( 'h2', null, $this->msg( 'abusefilter-examine-test' )->parse() );
|
2009-03-31 15:13:26 +00:00
|
|
|
$tester .= AbuseFilter::buildEditBox( $this->mTestFilter, 'wpTestFilter', false );
|
2009-10-07 13:57:06 +00:00
|
|
|
$tester .=
|
|
|
|
"\n" .
|
|
|
|
Xml::inputLabel(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-test-load-filter' )->text(),
|
2009-10-07 13:57:06 +00:00
|
|
|
'wpInsertFilter',
|
|
|
|
'mw-abusefilter-load-filter',
|
|
|
|
10,
|
|
|
|
''
|
|
|
|
) .
|
2010-05-30 17:33:59 +00:00
|
|
|
' ' .
|
2009-10-07 13:57:06 +00:00
|
|
|
Xml::element(
|
|
|
|
'input',
|
|
|
|
array(
|
|
|
|
'type' => 'button',
|
2012-09-02 11:07:02 +00:00
|
|
|
'value' => $this->msg( 'abusefilter-test-load' )->text(),
|
2009-10-07 13:57:06 +00:00
|
|
|
'id' => 'mw-abusefilter-load'
|
|
|
|
)
|
2009-03-31 15:13:26 +00:00
|
|
|
);
|
2011-11-22 16:08:18 +00:00
|
|
|
$html .= Xml::tags( 'div', array( 'id' => 'mw-abusefilter-examine-editor' ), $tester );
|
|
|
|
$html .= Xml::tags( 'p',
|
2009-10-07 13:57:06 +00:00
|
|
|
null,
|
|
|
|
Xml::element( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'button',
|
2012-09-02 11:07:02 +00:00
|
|
|
'value' => $this->msg( 'abusefilter-examine-test-button' )->text(),
|
2009-10-07 13:57:06 +00:00
|
|
|
'id' => 'mw-abusefilter-examine-test'
|
|
|
|
)
|
2009-03-31 15:13:26 +00:00
|
|
|
) .
|
2009-10-07 13:57:06 +00:00
|
|
|
Xml::element( 'div',
|
|
|
|
array(
|
|
|
|
'id' => 'mw-abusefilter-syntaxresult',
|
|
|
|
'style' => 'display: none;'
|
2010-05-30 17:33:59 +00:00
|
|
|
), ' '
|
2009-10-07 13:57:06 +00:00
|
|
|
)
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-03-31 15:13:26 +00:00
|
|
|
}
|
2009-01-29 22:44:31 +00:00
|
|
|
|
|
|
|
// Variable dump
|
2012-09-02 11:07:02 +00:00
|
|
|
$html .= Xml::tags(
|
|
|
|
'h2',
|
|
|
|
null,
|
|
|
|
$this->msg( 'abusefilter-examine-vars', 'parseinline' )->parse()
|
|
|
|
);
|
2011-11-22 16:08:18 +00:00
|
|
|
$html .= AbuseFilter::buildVarDumpTable( $vars );
|
2009-01-29 22:44:31 +00:00
|
|
|
|
2011-11-22 16:08:18 +00:00
|
|
|
$output->addHTML( $html );
|
2009-01-29 22:44:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadParameters() {
|
2011-11-16 05:34:24 +00:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$searchUsername = $request->getText( 'wpSearchUser' );
|
|
|
|
$this->mSearchPeriodStart = $request->getText( 'wpSearchPeriodStart' );
|
|
|
|
$this->mSearchPeriodEnd = $request->getText( 'wpSearchPeriodEnd' );
|
|
|
|
$this->mSubmit = $request->getCheck( 'submit' );
|
|
|
|
$this->mTestFilter = $request->getText( 'testfilter' );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-25 02:33:09 +00:00
|
|
|
// Normalise username
|
|
|
|
$userTitle = Title::newFromText( $searchUsername );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( $userTitle && $userTitle->getNamespace() == NS_USER ) {
|
2009-02-25 02:33:09 +00:00
|
|
|
$this->mSearchUser = $userTitle->getText(); // Allow User:Blah syntax.
|
2010-08-19 21:12:09 +00:00
|
|
|
} elseif ( $userTitle ) {
|
2009-02-25 02:33:09 +00:00
|
|
|
// Not sure of the value of prefixedText over text, but no need to munge unnecessarily.
|
|
|
|
$this->mSearchUser = $userTitle->getPrefixedText();
|
2010-08-19 21:12:09 +00:00
|
|
|
} else {
|
2009-02-25 02:33:09 +00:00
|
|
|
$this->mSearchUser = '';
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-29 22:44:31 +00:00
|
|
|
}
|
2009-02-07 09:34:11 +00:00
|
|
|
}
|
2009-03-12 11:38:21 +00:00
|
|
|
|
|
|
|
class AbuseFilterExaminePager extends ReverseChronologicalPager {
|
|
|
|
function __construct( $page, $changesList ) {
|
|
|
|
parent::__construct();
|
|
|
|
$this->mChangesList = $changesList;
|
|
|
|
$this->mPage = $page;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 11:38:21 +00:00
|
|
|
function getQueryInfo() {
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
$conds = array( 'rc_user_text' => $this->mPage->mSearchUser );
|
2010-08-19 21:12:09 +00:00
|
|
|
$startTS = strtotime( $this->mPage->mSearchPeriodStart );
|
|
|
|
if ( $startTS ) {
|
2009-03-12 11:38:21 +00:00
|
|
|
$conds[] = 'rc_timestamp>=' . $dbr->addQuotes( $dbr->timestamp( $startTS ) );
|
|
|
|
}
|
2010-08-19 21:12:09 +00:00
|
|
|
$endTS = strtotime( $this->mPage->mSearchPeriodEnd );
|
|
|
|
if ( $endTS ) {
|
2009-03-12 11:38:21 +00:00
|
|
|
$conds[] = 'rc_timestamp<=' . $dbr->addQuotes( $dbr->timestamp( $endTS ) );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 11:38:21 +00:00
|
|
|
// If one of these is true, we're abusefilter compatible.
|
|
|
|
$compatConds = array(
|
2009-04-24 03:27:14 +00:00
|
|
|
'rc_this_oldid != 0',
|
2009-03-22 02:59:01 +00:00
|
|
|
'rc_log_action' => array( 'move', 'create' ),
|
2009-03-12 11:38:21 +00:00
|
|
|
);
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 11:38:21 +00:00
|
|
|
$conds[] = $dbr->makeList( $compatConds, LIST_OR );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 11:38:21 +00:00
|
|
|
$info = array(
|
|
|
|
'tables' => 'recentchanges',
|
|
|
|
'fields' => '*',
|
2009-10-07 13:57:06 +00:00
|
|
|
'conds' => array_filter( $conds ),
|
2009-03-12 11:38:21 +00:00
|
|
|
'options' => array( 'ORDER BY' => 'rc_timestamp DESC' ),
|
|
|
|
);
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 11:38:21 +00:00
|
|
|
return $info;
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 11:38:21 +00:00
|
|
|
function formatRow( $row ) {
|
2010-02-13 14:10:36 +00:00
|
|
|
# Incompatible stuff.
|
2009-03-12 11:38:21 +00:00
|
|
|
$rc = RecentChange::newFromRow( $row );
|
|
|
|
$rc->counter = $this->mPage->mCounter++;
|
|
|
|
return $this->mChangesList->recentChangesLine( $rc, false );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 11:38:21 +00:00
|
|
|
function getIndexField() {
|
|
|
|
return 'rc_id';
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-12 11:38:21 +00:00
|
|
|
function getTitle() {
|
|
|
|
return $this->mPage->getTitle( 'examine' );
|
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-03-22 03:12:53 +00:00
|
|
|
function getEmptyBody() {
|
2012-09-02 11:07:02 +00:00
|
|
|
return $this->msg( 'abusefilter-examine-noresults' )->parseAsBlock();
|
2009-03-22 03:12:53 +00:00
|
|
|
}
|
2009-03-25 02:53:23 +00:00
|
|
|
}
|