2009-01-28 23:54:41 +00:00
|
|
|
<?php
|
|
|
|
|
2009-01-29 22:44:31 +00:00
|
|
|
class AbuseFilterViewTestBatch extends AbuseFilterView {
|
2009-01-28 23:54:41 +00:00
|
|
|
// Hard-coded for now.
|
2015-09-28 18:03:35 +00:00
|
|
|
protected static $mChangeLimit = 100;
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2013-10-15 13:22:05 +00:00
|
|
|
public $mShowNegative, $mTestPeriodStart, $mTestPeriodEnd, $mTestPage,
|
|
|
|
$mTestUser;
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
function show() {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out = $this->getOutput();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-01-28 23:54:41 +00:00
|
|
|
AbuseFilter::disableConditionLimit();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
if ( !$this->getUser()->isAllowed( 'abusefilter-modify' ) ) {
|
|
|
|
$out->addWikiMsg( 'abusefilter-mustbeeditor' );
|
2009-03-31 15:13:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-01-28 23:54:41 +00:00
|
|
|
|
|
|
|
$this->loadParameters();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2012-09-02 11:07:02 +00:00
|
|
|
$out->setPageTitle( $this->msg( 'abusefilter-test' ) );
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-test-intro', self::$mChangeLimit );
|
2009-01-28 23:54:41 +00:00
|
|
|
|
|
|
|
$output = '';
|
|
|
|
$output .= AbuseFilter::buildEditBox( $this->mFilter, 'wpTestFilter' ) . "\n";
|
2010-02-13 14:10:36 +00:00
|
|
|
$output .=
|
2009-10-07 13:57:06 +00:00
|
|
|
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-02-13 14:10:36 +00:00
|
|
|
) .
|
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-02-07 09:34:11 +00:00
|
|
|
);
|
2017-06-15 14:23:16 +00:00
|
|
|
$output = Xml::tags( 'div', [ 'id' => 'mw-abusefilter-test-editor' ], $output );
|
2009-01-28 23:54:41 +00:00
|
|
|
|
2014-01-25 13:04:18 +00:00
|
|
|
$output .= Xml::tags( 'p', null, Xml::checkLabel(
|
2017-07-08 18:49:13 +00:00
|
|
|
$this->msg( 'abusefilter-test-shownegative' )->text(),
|
|
|
|
'wpShowNegative', 'wpShowNegative', $this->mShowNegative )
|
|
|
|
);
|
2009-01-29 22:44:31 +00:00
|
|
|
|
|
|
|
// Selectory stuff
|
2017-06-15 14:23:16 +00:00
|
|
|
$selectFields = [];
|
2009-03-21 18:47:26 +00:00
|
|
|
$selectFields['abusefilter-test-user'] = Xml::input( 'wpTestUser', 45, $this->mTestUser );
|
2010-02-13 14:10:36 +00:00
|
|
|
$selectFields['abusefilter-test-period-start'] =
|
2009-03-21 18:47:26 +00:00
|
|
|
Xml::input( 'wpTestPeriodStart', 45, $this->mTestPeriodStart );
|
2010-02-13 14:10:36 +00:00
|
|
|
$selectFields['abusefilter-test-period-end'] =
|
2009-03-21 18:47:26 +00:00
|
|
|
Xml::input( 'wpTestPeriodEnd', 45, $this->mTestPeriodEnd );
|
2009-04-23 04:30:17 +00:00
|
|
|
$selectFields['abusefilter-test-page'] =
|
|
|
|
Xml::input( 'wpTestPage', 45, $this->mTestPage );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-01-29 22:44:31 +00:00
|
|
|
$output .= Xml::buildForm( $selectFields, 'abusefilter-test-submit' );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2014-12-25 18:20:47 +00:00
|
|
|
$output .= Html::hidden( 'title', $this->getTitle( 'test' )->getPrefixedDBkey() );
|
2009-10-07 13:57:06 +00:00
|
|
|
$output = Xml::tags( 'form',
|
2017-06-15 14:23:16 +00:00
|
|
|
[
|
2010-02-13 14:10:36 +00:00
|
|
|
'action' => $this->getTitle( 'test' )->getLocalURL(),
|
2010-08-19 21:12:09 +00:00
|
|
|
'method' => 'post'
|
2017-06-15 14:23:16 +00:00
|
|
|
],
|
2009-10-07 13:57:06 +00:00
|
|
|
$output
|
|
|
|
);
|
2009-01-28 23:54:41 +00:00
|
|
|
|
2012-09-02 11:07:02 +00:00
|
|
|
$output = Xml::fieldset( $this->msg( 'abusefilter-test-legend' )->text(), $output );
|
2009-01-28 23:54:41 +00:00
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addHTML( $output );
|
2009-01-28 23:54:41 +00:00
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
if ( $this->getRequest()->wasPosted() ) {
|
2009-01-28 23:54:41 +00:00
|
|
|
$this->doTest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-13 08:19:09 +00:00
|
|
|
/**
|
|
|
|
* @fixme this is similar to AbuseFilterExaminePager::getQueryInfo
|
|
|
|
*/
|
2009-01-28 23:54:41 +00:00
|
|
|
function doTest() {
|
|
|
|
// Quick syntax check.
|
2011-11-16 05:34:24 +00:00
|
|
|
$out = $this->getOutput();
|
2010-11-04 01:29:10 +00:00
|
|
|
$result = AbuseFilter::checkSyntax( $this->mFilter );
|
|
|
|
if ( $result !== true ) {
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addWikiMsg( 'abusefilter-test-syntaxerr' );
|
2009-01-28 23:54:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-08-30 02:51:39 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2009-01-29 22:44:31 +00:00
|
|
|
|
2017-07-13 08:19:09 +00:00
|
|
|
$conds = [];
|
|
|
|
$conds['rc_user_text'] = $this->mTestUser;
|
2009-01-29 22:44:31 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $this->mTestPeriodStart ) {
|
|
|
|
$conds[] = 'rc_timestamp >= ' .
|
2009-02-07 09:34:11 +00:00
|
|
|
$dbr->addQuotes( $dbr->timestamp( strtotime( $this->mTestPeriodStart ) ) );
|
2009-01-29 22:44:31 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $this->mTestPeriodEnd ) {
|
|
|
|
$conds[] = 'rc_timestamp <= ' .
|
2009-02-07 09:34:11 +00:00
|
|
|
$dbr->addQuotes( $dbr->timestamp( strtotime( $this->mTestPeriodEnd ) ) );
|
2009-01-29 22:44:31 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $this->mTestPage ) {
|
2009-04-23 04:30:17 +00:00
|
|
|
$title = Title::newFromText( $this->mTestPage );
|
2014-01-04 03:03:59 +00:00
|
|
|
if ( $title instanceof Title ) {
|
|
|
|
$conds['rc_namespace'] = $title->getNamespace();
|
|
|
|
$conds['rc_title'] = $title->getDBkey();
|
|
|
|
} else {
|
|
|
|
$out->addWikiMsg( 'abusefilter-test-badtitle' );
|
|
|
|
return;
|
|
|
|
}
|
2009-04-23 04:30:17 +00:00
|
|
|
}
|
2009-01-28 23:54:41 +00:00
|
|
|
|
2017-07-13 08:19:09 +00:00
|
|
|
$conds[] = $this->buildTestConditions( $dbr );
|
|
|
|
|
2009-01-28 23:54:41 +00:00
|
|
|
// Get our ChangesList
|
2011-11-16 05:34:24 +00:00
|
|
|
$changesList = new AbuseFilterChangesList( $this->getSkin() );
|
2009-01-28 23:54:41 +00:00
|
|
|
$output = $changesList->beginRecentChangesList();
|
|
|
|
|
2017-10-12 19:44:48 +00:00
|
|
|
$rcQuery = RecentChange::getQueryInfo();
|
2009-10-07 13:57:06 +00:00
|
|
|
$res = $dbr->select(
|
2017-10-12 19:44:48 +00:00
|
|
|
$rcQuery['tables'],
|
|
|
|
$rcQuery['fields'],
|
2009-10-07 13:57:06 +00:00
|
|
|
array_filter( $conds ),
|
2010-02-13 14:10:36 +00:00
|
|
|
__METHOD__,
|
2017-10-12 19:44:48 +00:00
|
|
|
[ 'LIMIT' => self::$mChangeLimit, 'ORDER BY' => 'rc_timestamp desc' ],
|
|
|
|
$rcQuery['joins']
|
2009-10-07 13:57:06 +00:00
|
|
|
);
|
2009-01-28 23:54:41 +00:00
|
|
|
|
|
|
|
$counter = 1;
|
|
|
|
|
2015-09-28 18:03:35 +00:00
|
|
|
foreach ( $res as $row ) {
|
2009-01-28 23:54:41 +00:00
|
|
|
$vars = AbuseFilter::getVarsFromRCRow( $row );
|
|
|
|
|
2010-08-19 21:12:09 +00:00
|
|
|
if ( !$vars ) {
|
2009-01-28 23:54:41 +00:00
|
|
|
continue;
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-28 23:54:41 +00:00
|
|
|
|
|
|
|
$result = AbuseFilter::checkConditions( $this->mFilter, $vars );
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( $result || $this->mShowNegative ) {
|
2009-01-30 00:54:20 +00:00
|
|
|
// Stash result in RC item
|
2009-01-28 23:54:41 +00:00
|
|
|
$rc = RecentChange::newFromRow( $row );
|
2009-01-30 23:24:11 +00:00
|
|
|
$rc->examineParams['testfilter'] = $this->mFilter;
|
2009-01-30 00:54:20 +00:00
|
|
|
$rc->filterResult = $result;
|
2009-01-28 23:54:41 +00:00
|
|
|
$rc->counter = $counter++;
|
|
|
|
$output .= $changesList->recentChangesLine( $rc, false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$output .= $changesList->endRecentChangesList();
|
|
|
|
|
2011-11-16 05:34:24 +00:00
|
|
|
$out->addHTML( $output );
|
2009-01-28 23:54:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadParameters() {
|
2011-11-16 05:34:24 +00:00
|
|
|
$request = $this->getRequest();
|
|
|
|
|
|
|
|
$this->mFilter = $request->getText( 'wpTestFilter' );
|
|
|
|
$this->mShowNegative = $request->getBool( 'wpShowNegative' );
|
|
|
|
$testUsername = $request->getText( 'wpTestUser' );
|
|
|
|
$this->mTestPeriodEnd = $request->getText( 'wpTestPeriodEnd' );
|
|
|
|
$this->mTestPeriodStart = $request->getText( 'wpTestPeriodStart' );
|
|
|
|
$this->mTestPage = $request->getText( 'wpTestPage' );
|
2009-01-30 19:19:03 +00:00
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
if ( !$this->mFilter
|
|
|
|
&& count( $this->mParams ) > 1
|
2017-07-08 18:49:13 +00:00
|
|
|
&& is_numeric( $this->mParams[1] )
|
|
|
|
) {
|
2017-08-30 02:51:39 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->mFilter = $dbr->selectField( 'abuse_filter',
|
2010-02-13 14:10:36 +00:00
|
|
|
'af_pattern',
|
2017-06-15 14:23:16 +00:00
|
|
|
[ 'af_id' => $this->mParams[1] ],
|
2009-10-07 13:57:06 +00:00
|
|
|
__METHOD__
|
|
|
|
);
|
2009-01-30 19:19:03 +00:00
|
|
|
}
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2009-02-25 02:33:09 +00:00
|
|
|
// Normalise username
|
2017-09-20 14:14:02 +00:00
|
|
|
$userTitle = Title::newFromText( $testUsername, NS_USER );
|
|
|
|
$this->mTestUser = $userTitle ? $userTitle->getText() : null;
|
2009-01-28 23:54:41 +00:00
|
|
|
}
|
2009-01-29 22:44:31 +00:00
|
|
|
}
|