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;
|
|
|
|
|
2013-10-15 13:22:05 +00:00
|
|
|
public $mCounter, $mSearchUser, $mSearchPeriodStart, $mSearchPeriodEnd,
|
|
|
|
$mTestFilter;
|
|
|
|
|
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'
|
2017-07-08 18:49:13 +00:00
|
|
|
&& 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() {
|
2017-06-15 14:23:16 +00:00
|
|
|
$formDescriptor = [
|
|
|
|
'SearchUser' => [
|
2016-04-10 13:12:43 +00:00
|
|
|
'label-message' => 'abusefilter-test-user',
|
|
|
|
'type' => 'user',
|
|
|
|
'default' => $this->mSearchUser,
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
|
|
|
'SearchPeriodStart' => [
|
2016-04-10 13:12:43 +00:00
|
|
|
'label-message' => 'abusefilter-test-period-start',
|
|
|
|
'type' => 'text',
|
|
|
|
'default' => $this->mSearchPeriodStart,
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
|
|
|
'SearchPeriodEnd' => [
|
2016-04-10 13:12:43 +00:00
|
|
|
'label-message' => 'abusefilter-test-period-end',
|
|
|
|
'type' => 'text',
|
|
|
|
'default' => $this->mSearchPeriodEnd,
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
|
|
|
];
|
2016-04-10 13:12:43 +00:00
|
|
|
$htmlForm = HTMLForm::factory( 'table', $formDescriptor, $this->getContext() );
|
|
|
|
$htmlForm->setWrapperLegendMsg( 'abusefilter-examine-legend' )
|
|
|
|
->addHiddenField( 'submit', 1 )
|
|
|
|
->setSubmitTextMsg( 'abusefilter-examine-submit' )
|
|
|
|
->setMethod( 'get' )
|
|
|
|
->prepareForm()
|
|
|
|
->displayForm( false );
|
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
|
2017-08-30 02:51:39 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2017-10-12 19:44:48 +00:00
|
|
|
$rcQuery = RecentChange::getQueryInfo();
|
2017-08-30 17:06:44 +00:00
|
|
|
$row = $dbr->selectRow(
|
2017-10-12 19:44:48 +00:00
|
|
|
$rcQuery['tables'],
|
|
|
|
$rcQuery['fields'],
|
2017-08-30 17:06:44 +00:00
|
|
|
[ 'rc_id' => $rcid ],
|
2017-10-12 19:44:48 +00:00
|
|
|
__METHOD__,
|
|
|
|
[],
|
|
|
|
$rcQuery['joins']
|
2017-08-30 17:06:44 +00:00
|
|
|
);
|
2014-07-29 23:46:29 +00:00
|
|
|
$out = $this->getOutput();
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( !$row ) {
|
2014-07-29 23:46:29 +00:00
|
|
|
$out->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 );
|
2014-07-29 23:46:29 +00:00
|
|
|
$out->addJsConfigVars( 'wgAbuseFilterVariables', $vars->dumpAllVars( true ) );
|
2009-02-04 19:51:03 +00:00
|
|
|
$this->showExaminer( $vars );
|
|
|
|
}
|
|
|
|
|
|
|
|
function showExaminerForLogEntry( $logid ) {
|
|
|
|
// Get data
|
2017-08-30 02:51:39 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2017-06-15 14:23:16 +00:00
|
|
|
$row = $dbr->selectRow( 'abuse_filter_log', '*', [ 'afl_id' => $logid ], __METHOD__ );
|
2014-07-29 23:46:29 +00:00
|
|
|
$out = $this->getOutput();
|
2009-02-04 19:51:03 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( !$row ) {
|
2014-07-29 23:46:29 +00:00
|
|
|
$out->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 ) ) {
|
2014-07-29 23:46:29 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-log-cannot-see-details' );
|
2011-12-27 23:35:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $row->afl_deleted && !SpecialAbuseLog::canSeeHidden() ) {
|
2014-07-29 23:46:29 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-log-details-hidden' );
|
2011-12-27 23:35:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-27 03:06:19 +00:00
|
|
|
$vars = AbuseFilter::loadVarDump( $row->afl_var_dump );
|
2014-07-29 23:46:29 +00:00
|
|
|
$out->addJsConfigVars( 'wgAbuseFilterVariables', $vars->dumpAllVars( true ) );
|
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',
|
2017-06-15 14:23:16 +00:00
|
|
|
[
|
2009-10-07 13:57:06 +00:00
|
|
|
'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'
|
2017-06-15 14:23:16 +00:00
|
|
|
]
|
2009-03-31 15:13:26 +00:00
|
|
|
);
|
2017-06-15 14:23:16 +00:00
|
|
|
$html .= Xml::tags( 'div', [ 'id' => 'mw-abusefilter-examine-editor' ], $tester );
|
2011-11-22 16:08:18 +00:00
|
|
|
$html .= Xml::tags( 'p',
|
2009-10-07 13:57:06 +00:00
|
|
|
null,
|
|
|
|
Xml::element( 'input',
|
2017-06-15 14:23:16 +00:00
|
|
|
[
|
2009-10-07 13:57:06 +00:00
|
|
|
'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'
|
2017-06-15 14:23:16 +00:00
|
|
|
]
|
2009-03-31 15:13:26 +00:00
|
|
|
) .
|
2009-10-07 13:57:06 +00:00
|
|
|
Xml::element( 'div',
|
2017-06-15 14:23:16 +00:00
|
|
|
[
|
2009-10-07 13:57:06 +00:00
|
|
|
'id' => 'mw-abusefilter-syntaxresult',
|
|
|
|
'style' => 'display: none;'
|
2017-06-15 14:23:16 +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,
|
2017-08-20 12:48:51 +00:00
|
|
|
$this->msg( 'abusefilter-examine-vars' )->parse()
|
2012-09-02 11:07:02 +00:00
|
|
|
);
|
2016-09-17 07:03:42 +00:00
|
|
|
$html .= AbuseFilter::buildVarDumpTable( $vars, $this->getContext() );
|
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
|
|
|
}
|