2009-01-29 22:44:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if (!defined( 'MEDIAWIKI' ))
|
|
|
|
die();
|
|
|
|
|
|
|
|
class AbuseFilterViewExamine extends AbuseFilterView {
|
|
|
|
|
|
|
|
function show( ) {
|
|
|
|
global $wgOut, $wgUser;
|
|
|
|
|
|
|
|
$wgOut->setPageTitle( wfMsg( 'abusefilter-examine' ) );
|
|
|
|
$wgOut->addWikiMsg( 'abusefilter-examine-intro' );
|
|
|
|
|
|
|
|
$this->loadParameters();
|
|
|
|
|
|
|
|
// Check if we've got a subpage
|
|
|
|
if ( count($this->mParams)>1 && is_numeric($this->mParams[1]) ) {
|
2009-02-04 19:51:03 +00:00
|
|
|
$this->showExaminerForRC( $this->mParams[1] );
|
2009-02-07 09:34:11 +00:00
|
|
|
} elseif ( count($this->mParams)>2
|
|
|
|
&& $this->mParams[1] == 'log'
|
|
|
|
&& is_numeric( $this->mParams[2] ) )
|
|
|
|
{
|
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() {
|
|
|
|
global $wgUser, $wgOut;
|
|
|
|
|
|
|
|
// Add selector
|
|
|
|
$selector = '';
|
|
|
|
|
|
|
|
$selectFields = array(); ## Same fields as in Test
|
|
|
|
$selectFields['abusefilter-test-user'] = wfInput( 'wpSearchUser', 45, $this->mSearchUser );
|
2009-02-07 09:34:11 +00:00
|
|
|
$selectFields['abusefilter-test-period-start'] =
|
|
|
|
wfInput( 'wpSearchPeriodStart', 45, $this->mSearchPeriodStart );
|
|
|
|
$selectFields['abusefilter-test-period-end'] =
|
|
|
|
wfInput( 'wpSearchPeriodEnd', 45, $this->mSearchPeriodEnd );
|
2009-01-29 22:44:31 +00:00
|
|
|
|
|
|
|
$selector .= Xml::buildForm( $selectFields, 'abusefilter-examine-submit' );
|
|
|
|
$selector .= Xml::hidden( 'submit', 1 );
|
|
|
|
$selector .= Xml::hidden( 'title', $this->getTitle( 'examine' )->getPrefixedText() );
|
2009-02-07 09:34:11 +00:00
|
|
|
$selector = Xml::tags( 'form',
|
|
|
|
array(
|
|
|
|
'action' => $this->getTitle( 'examine' )->getLocalURL(),
|
|
|
|
'method' => 'GET'
|
|
|
|
),
|
|
|
|
$selector );
|
|
|
|
$selector = Xml::fieldset(
|
|
|
|
wfMsg( 'abusefilter-examine-legend' ),
|
|
|
|
$selector );
|
2009-01-29 22:44:31 +00:00
|
|
|
$wgOut->addHTML( $selector );
|
|
|
|
|
2009-02-07 09:34:11 +00:00
|
|
|
if ( $this->mSubmit ) {
|
2009-01-29 22:44:31 +00:00
|
|
|
$this->showResults();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function showResults() {
|
|
|
|
global $wgUser, $wgOut;
|
|
|
|
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
|
|
|
|
$conds = array( 'rc_user_text' => $this->mSearchUser );
|
|
|
|
if ( $startTS = strtotime($this->mSearchPeriodStart) ) {
|
|
|
|
$conds[] = 'rc_timestamp>=' . $dbr->addQuotes( $dbr->timestamp( $startTS ) );
|
|
|
|
}
|
|
|
|
if ( $endTS = strtotime($this->mSearchPeriodEnd) ) {
|
|
|
|
$conds[] = 'rc_timestamp<=' . $dbr->addQuotes( $dbr->timestamp( $endTS ) );
|
|
|
|
}
|
|
|
|
|
2009-02-07 09:34:11 +00:00
|
|
|
$res = $dbr->select( 'recentchanges', '*', array_filter($conds), __METHOD__,
|
|
|
|
array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => '500' ) );
|
2009-01-29 22:44:31 +00:00
|
|
|
|
|
|
|
$changesList = new AbuseFilterChangesList( $wgUser->getSkin() );
|
|
|
|
$output = $changesList->beginRecentChangesList();
|
|
|
|
$counter = 1;
|
|
|
|
|
|
|
|
while ( $row = $dbr->fetchObject( $res ) ) {
|
2009-01-29 23:04:06 +00:00
|
|
|
## Incompatible stuff.
|
2009-02-07 09:34:11 +00:00
|
|
|
if ( !$row->rc_this_oldid
|
|
|
|
&& !in_array( $row->rc_log_action, array( 'move', 'newusers' ) ) )
|
|
|
|
{
|
2009-01-29 23:04:06 +00:00
|
|
|
continue;
|
2009-02-07 09:34:11 +00:00
|
|
|
}
|
2009-01-29 23:04:06 +00:00
|
|
|
|
2009-01-29 22:44:31 +00:00
|
|
|
$rc = RecentChange::newFromRow( $row );
|
|
|
|
$rc->counter = $counter++;
|
|
|
|
$output .= $changesList->recentChangesLine( $rc, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
$output .= $changesList->endRecentChangesList();
|
|
|
|
|
|
|
|
$wgOut->addHTML( $output );
|
|
|
|
}
|
|
|
|
|
2009-02-04 19:51:03 +00:00
|
|
|
function showExaminerForRC( $rcid ) {
|
|
|
|
global $wgOut;
|
|
|
|
|
2009-01-29 22:44:31 +00:00
|
|
|
// Get data
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
$row = $dbr->selectRow( 'recentchanges', '*', array( 'rc_id' => $rcid ), __METHOD__ );
|
|
|
|
|
|
|
|
if (!$row) {
|
|
|
|
$wgOut->addWikiMsg( 'abusefilter-examine-notfound' );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$vars = AbuseFilter::getVarsFromRCRow( $row );
|
|
|
|
|
2009-02-04 19:51:03 +00:00
|
|
|
$this->showExaminer( $vars );
|
|
|
|
}
|
|
|
|
|
|
|
|
function showExaminerForLogEntry( $logid ) {
|
|
|
|
global $wgOut;
|
|
|
|
|
|
|
|
// Get data
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
$row = $dbr->selectRow( 'abuse_filter_log', '*', array( 'afl_id' => $logid ), __METHOD__ );
|
|
|
|
|
|
|
|
if (!$row) {
|
|
|
|
$wgOut->addWikiMsg( 'abusefilter-examine-notfound' );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$vars = unserialize( $row->afl_var_dump );
|
2009-02-26 12:15:14 +00:00
|
|
|
|
2009-02-04 19:51:03 +00:00
|
|
|
$this->showExaminer( $vars );
|
|
|
|
}
|
|
|
|
|
|
|
|
function showExaminer( $vars ) {
|
|
|
|
global $wgOut, $wgUser;
|
|
|
|
|
2009-01-29 22:44:31 +00:00
|
|
|
if (!$vars) {
|
|
|
|
$wgOut->addWikiMsg( 'abusefilter-examine-incompatible' );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = '';
|
|
|
|
|
|
|
|
// Send armoured as JSON -- I totally give up on trying to send it as a proper object.
|
2009-02-07 09:34:11 +00:00
|
|
|
$wgOut->addInlineScript( "var wgExamineVars = ".
|
|
|
|
Xml::encodeJsVar( json_encode( $vars ) ) .";" );
|
2009-01-29 22:44:31 +00:00
|
|
|
$wgOut->addInlineScript( file_get_contents( dirname( __FILE__ ) . "/examine.js" ) );
|
|
|
|
|
|
|
|
// Add messages
|
|
|
|
$msg = array();
|
|
|
|
$msg['match'] = wfMsg( 'abusefilter-examine-match' );
|
|
|
|
$msg['nomatch'] = wfMsg( 'abusefilter-examine-nomatch' );
|
|
|
|
$msg['syntaxerror'] = wfMsg( 'abusefilter-examine-syntaxerror' );
|
2009-02-07 09:34:11 +00:00
|
|
|
$wgOut->addInlineScript(
|
|
|
|
"var wgMessageMatch = ".Xml::encodeJsVar( $msg['match'] ) . ";\n".
|
|
|
|
"var wgMessageNomatch = ".Xml::encodeJsVar( $msg['nomatch'] ) . ";\n".
|
|
|
|
"var wgMessageError = ".Xml::encodeJsVar( $msg['syntaxerror'] ) . ";\n" );
|
2009-01-29 22:44:31 +00:00
|
|
|
|
|
|
|
// Add test bit
|
|
|
|
$tester = Xml::tags( 'h2', null, wfMsgExt( 'abusefilter-examine-test', 'parseinline' ) );
|
2009-01-30 23:24:11 +00:00
|
|
|
$tester .= AbuseFilter::buildEditBox( $this->mTestFilter, 'wpTestFilter', false );
|
2009-02-07 09:34:11 +00:00
|
|
|
$tester .=
|
|
|
|
"\n" .
|
|
|
|
Xml::inputLabel(
|
|
|
|
wfMsg( 'abusefilter-test-load-filter' ),
|
|
|
|
'wpInsertFilter',
|
|
|
|
'mw-abusefilter-load-filter',
|
|
|
|
10,
|
|
|
|
''
|
|
|
|
) .
|
|
|
|
' ' .
|
|
|
|
Xml::element(
|
|
|
|
'input',
|
|
|
|
array(
|
|
|
|
'type' => 'button',
|
|
|
|
'value' => wfMsg( 'abusefilter-test-load' ),
|
|
|
|
'id' => 'mw-abusefilter-load'
|
|
|
|
)
|
|
|
|
);
|
2009-01-29 22:44:31 +00:00
|
|
|
$output .= Xml::tags( 'div', array( 'id' => 'mw-abusefilter-examine-editor' ), $tester );
|
2009-02-07 09:34:11 +00:00
|
|
|
$output .= Xml::tags( 'p',
|
|
|
|
null,
|
|
|
|
Xml::element( 'input',
|
|
|
|
array(
|
|
|
|
'type' => 'button',
|
|
|
|
'value' => wfMsg( 'abusefilter-examine-test-button' ),
|
|
|
|
'id' => 'mw-abusefilter-examine-test'
|
|
|
|
)
|
|
|
|
) .
|
|
|
|
Xml::element( 'div',
|
|
|
|
array(
|
|
|
|
'id' => 'mw-abusefilter-syntaxresult',
|
|
|
|
'style' => 'display: none;'
|
|
|
|
), ' '
|
|
|
|
)
|
|
|
|
);
|
2009-01-29 22:44:31 +00:00
|
|
|
|
|
|
|
// Variable dump
|
|
|
|
$output .= Xml::tags( 'h2', null, wfMsgExt( 'abusefilter-examine-vars', 'parseinline' ) );
|
|
|
|
$output .= AbuseFilter::buildVarDumpTable( $vars );
|
|
|
|
|
|
|
|
$wgOut->addHTML( $output );
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadParameters() {
|
|
|
|
global $wgRequest;
|
2009-02-25 02:33:09 +00:00
|
|
|
$searchUsername = $wgRequest->getText( 'wpSearchUser' );
|
2009-01-29 22:44:31 +00:00
|
|
|
$this->mSearchPeriodStart = $wgRequest->getText( 'wpSearchPeriodStart' );
|
|
|
|
$this->mSearchPeriodEnd = $wgRequest->getText( 'wpSearchPeriodEnd' );
|
|
|
|
$this->mSubmit = $wgRequest->getCheck( 'submit' );
|
2009-01-30 23:24:11 +00:00
|
|
|
$this->mTestFilter = $wgRequest->getText( 'testfilter' );
|
2009-02-25 02:33:09 +00:00
|
|
|
|
|
|
|
// Normalise username
|
|
|
|
$userTitle = Title::newFromText( $searchUsername );
|
|
|
|
|
2009-02-25 02:40:05 +00:00
|
|
|
if ( $userTitle && $userTitle->getNamespace() == NS_USER )
|
2009-02-25 02:33:09 +00:00
|
|
|
$this->mSearchUser = $userTitle->getText(); // Allow User:Blah syntax.
|
|
|
|
elseif ( $userTitle )
|
|
|
|
// Not sure of the value of prefixedText over text, but no need to munge unnecessarily.
|
|
|
|
$this->mSearchUser = $userTitle->getPrefixedText();
|
|
|
|
else
|
|
|
|
$this->mSearchUser = '';
|
2009-01-29 22:44:31 +00:00
|
|
|
}
|
2009-02-07 09:34:11 +00:00
|
|
|
}
|