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.
|
|
|
|
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',
|
|
|
|
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'
|
2010-02-13 14:10:36 +00:00
|
|
|
)
|
2009-02-07 09:34:11 +00:00
|
|
|
);
|
2009-01-28 23:54:41 +00:00
|
|
|
$output = Xml::tags( 'div', array( 'id' => 'mw-abusefilter-test-editor' ), $output );
|
|
|
|
|
2014-01-25 13:04:18 +00:00
|
|
|
$output .= Xml::tags( 'p', null, Xml::checkLabel(
|
2012-09-02 11:07:02 +00:00
|
|
|
$this->msg( 'abusefilter-test-shownegative' )->text(),
|
|
|
|
'wpShowNegative', 'wpShowNegative', $this->mShowNegative )
|
|
|
|
);
|
2009-01-29 22:44:31 +00:00
|
|
|
|
|
|
|
// Selectory stuff
|
|
|
|
$selectFields = array();
|
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
|
|
|
|
2010-10-29 15:14:44 +00:00
|
|
|
$output .= Html::hidden( 'title', $this->getTitle( 'test' )->getPrefixedText() );
|
2009-10-07 13:57:06 +00:00
|
|
|
$output = Xml::tags( 'form',
|
2010-02-13 14:10:36 +00:00
|
|
|
array(
|
|
|
|
'action' => $this->getTitle( 'test' )->getLocalURL(),
|
2010-08-19 21:12:09 +00:00
|
|
|
'method' => 'post'
|
2010-02-13 14:10:36 +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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2009-01-29 22:44:31 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
|
2013-05-24 20:24:06 +00:00
|
|
|
$conds = array(
|
|
|
|
'rc_user_text' => $this->mTestUser,
|
|
|
|
'rc_type != ' . RC_EXTERNAL
|
|
|
|
);
|
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
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
2009-10-07 13:57:06 +00:00
|
|
|
$res = $dbr->select(
|
|
|
|
'recentchanges',
|
|
|
|
'*',
|
|
|
|
array_filter( $conds ),
|
2010-02-13 14:10:36 +00:00
|
|
|
__METHOD__,
|
2009-10-07 13:57:06 +00:00
|
|
|
array( 'LIMIT' => self::$mChangeLimit, 'ORDER BY' => 'rc_timestamp desc' )
|
|
|
|
);
|
2009-01-28 23:54:41 +00:00
|
|
|
|
|
|
|
$counter = 1;
|
|
|
|
|
2010-08-19 21:12:09 +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
|
2009-02-07 09:34:11 +00:00
|
|
|
&& is_numeric( $this->mParams[1] ) )
|
|
|
|
{
|
2009-01-30 19:19:03 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2009-10-07 13:57:06 +00:00
|
|
|
$this->mFilter = $dbr->selectField( 'abuse_filter',
|
2010-02-13 14:10:36 +00:00
|
|
|
'af_pattern',
|
|
|
|
array( '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
|
|
|
|
$userTitle = Title::newFromText( $testUsername );
|
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->mTestUser = $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->mTestUser = $userTitle->getPrefixedText();
|
2010-08-19 21:12:09 +00:00
|
|
|
} else {
|
2009-02-25 02:33:09 +00:00
|
|
|
$this->mTestUser = null; // No user specified.
|
2010-08-19 21:12:09 +00:00
|
|
|
}
|
2009-01-28 23:54:41 +00:00
|
|
|
}
|
2009-01-29 22:44:31 +00:00
|
|
|
}
|