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
|
|
|
|
2018-03-30 00:57:57 +00:00
|
|
|
public $mShowNegative, $mTestPeriodStart, $mTestPeriodEnd, $mTestPage;
|
2018-05-01 09:27:00 +00:00
|
|
|
public $mTestUser, $mExcludeBots, $mTestAction;
|
2013-10-15 13:22:05 +00:00
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* Shows the page
|
|
|
|
*/
|
|
|
|
public 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
|
|
|
|
2018-05-04 19:56:45 +00:00
|
|
|
if ( !$this->canViewPrivate() ) {
|
|
|
|
$out->addWikiMsg( 'abusefilter-mustviewprivateoredit' );
|
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 );
|
2018-03-15 17:22:37 +00:00
|
|
|
$out->enableOOUI();
|
2009-01-28 23:54:41 +00:00
|
|
|
|
|
|
|
$output = '';
|
2010-02-13 14:10:36 +00:00
|
|
|
$output .=
|
2018-04-08 15:57:23 +00:00
|
|
|
$this->buildEditBox(
|
2018-03-15 17:22:37 +00:00
|
|
|
$this->mFilter,
|
|
|
|
'wpTestFilter',
|
|
|
|
true,
|
2018-05-04 19:56:45 +00:00
|
|
|
true,
|
|
|
|
false
|
2018-03-15 17:22:37 +00:00
|
|
|
) . "\n";
|
2009-01-29 22:44:31 +00:00
|
|
|
|
2018-12-09 13:33:30 +00:00
|
|
|
$output .= $this->buildFilterLoader();
|
2018-03-15 17:22:37 +00:00
|
|
|
$output = Xml::tags( 'div', [ 'id' => 'mw-abusefilter-test-editor' ], $output );
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-03-15 17:22:37 +00:00
|
|
|
$RCMaxAge = $this->getConfig()->get( 'RCMaxAge' );
|
|
|
|
$min = wfTimestamp( TS_ISO_8601, time() - $RCMaxAge );
|
|
|
|
$max = wfTimestampNow();
|
2009-10-07 13:57:06 +00:00
|
|
|
|
2018-03-15 17:22:37 +00:00
|
|
|
// Search form
|
|
|
|
$formFields = [];
|
2018-05-01 09:27:00 +00:00
|
|
|
$formFields['wpTestAction'] = [
|
|
|
|
'name' => 'wpTestAction',
|
|
|
|
'type' => 'select',
|
|
|
|
'label-message' => 'abusefilter-test-action',
|
|
|
|
'options' => [
|
|
|
|
$this->msg( 'abusefilter-test-search-type-all' )->text() => 0,
|
|
|
|
$this->msg( 'abusefilter-test-search-type-edit' )->text() => 'edit',
|
|
|
|
$this->msg( 'abusefilter-test-search-type-move' )->text() => 'move',
|
|
|
|
$this->msg( 'abusefilter-test-search-type-delete' )->text() => 'delete',
|
|
|
|
$this->msg( 'abusefilter-test-search-type-createaccount' )->text() => 'createaccount'
|
|
|
|
// @ToDo: add 'upload' once T170249 is resolved
|
|
|
|
]
|
|
|
|
];
|
2018-03-15 17:22:37 +00:00
|
|
|
$formFields['wpTestUser'] = [
|
|
|
|
'name' => 'wpTestUser',
|
|
|
|
'type' => 'user',
|
|
|
|
'ipallowed' => true,
|
|
|
|
'label-message' => 'abusefilter-test-user',
|
|
|
|
'default' => $this->mTestUser
|
|
|
|
];
|
2018-05-07 15:25:40 +00:00
|
|
|
$formFields['wpExcludeBots'] = [
|
|
|
|
'name' => 'wpExcludeBots',
|
|
|
|
'type' => 'check',
|
|
|
|
'label-message' => 'abusefilter-test-nobots',
|
|
|
|
'default' => $this->mExcludeBots
|
|
|
|
];
|
2018-03-15 17:22:37 +00:00
|
|
|
$formFields['wpTestPeriodStart'] = [
|
|
|
|
'name' => 'wpTestPeriodStart',
|
|
|
|
'type' => 'datetime',
|
|
|
|
'label-message' => 'abusefilter-test-period-start',
|
|
|
|
'default' => $this->mTestPeriodStart,
|
|
|
|
'min' => $min,
|
|
|
|
'max' => $max
|
|
|
|
];
|
|
|
|
$formFields['wpTestPeriodEnd'] = [
|
|
|
|
'name' => 'wpTestPeriodEnd',
|
|
|
|
'type' => 'datetime',
|
|
|
|
'label-message' => 'abusefilter-test-period-end',
|
|
|
|
'default' => $this->mTestPeriodEnd,
|
|
|
|
'min' => $min,
|
|
|
|
'max' => $max
|
|
|
|
];
|
|
|
|
$formFields['wpTestPage'] = [
|
|
|
|
'name' => 'wpTestPage',
|
|
|
|
'type' => 'title',
|
|
|
|
'label-message' => 'abusefilter-test-page',
|
|
|
|
'default' => $this->mTestPage,
|
2018-05-10 20:20:05 +00:00
|
|
|
'creatable' => true,
|
|
|
|
'required' => false
|
2018-03-15 17:22:37 +00:00
|
|
|
];
|
|
|
|
$formFields['wpShowNegative'] = [
|
|
|
|
'name' => 'wpShowNegative',
|
|
|
|
'type' => 'check',
|
|
|
|
'label-message' => 'abusefilter-test-shownegative',
|
|
|
|
'selected' => $this->mShowNegative
|
|
|
|
];
|
2009-01-28 23:54:41 +00:00
|
|
|
|
2018-03-15 17:22:37 +00:00
|
|
|
$htmlForm = HTMLForm::factory( 'ooui', $formFields, $this->getContext() )
|
|
|
|
->addHiddenField( 'title', $this->getTitle( 'test' )->getPrefixedDBkey() )
|
|
|
|
->setId( 'wpFilterForm' )
|
|
|
|
->setWrapperLegendMsg( 'abusefilter-list-options' )
|
|
|
|
->setAction( $this->getTitle( 'test' )->getLocalURL() )
|
|
|
|
->setSubmitTextMsg( 'abusefilter-test-submit' )
|
|
|
|
->setMethod( 'post' )
|
2018-04-29 17:52:45 +00:00
|
|
|
->prepareForm()
|
|
|
|
->getHTML( true );
|
2009-01-28 23:54:41 +00:00
|
|
|
|
2018-03-15 17:22:37 +00:00
|
|
|
$output = Xml::fieldset( $this->msg( 'abusefilter-test-legend' )->text(), $output . $htmlForm );
|
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
|
|
|
/**
|
2018-10-03 12:02:00 +00:00
|
|
|
* Loads the revisions and checks the given syntax against them
|
2017-07-13 08:19:09 +00:00
|
|
|
*/
|
2018-04-04 21:14:25 +00:00
|
|
|
public function doTest() {
|
2009-01-28 23:54:41 +00:00
|
|
|
// 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 = [];
|
2018-03-09 21:23:38 +00:00
|
|
|
|
|
|
|
if ( (string)$this->mTestUser !== '' ) {
|
|
|
|
$conds[] = ActorMigration::newMigration()->getWhere(
|
|
|
|
$dbr, 'rc_user', User::newFromName( $this->mTestUser, false )
|
|
|
|
)['conds'];
|
|
|
|
}
|
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
|
|
|
|
2018-05-07 15:25:40 +00:00
|
|
|
if ( $this->mExcludeBots ) {
|
|
|
|
$conds['rc_bot'] = 0;
|
|
|
|
}
|
2017-07-13 08:19:09 +00:00
|
|
|
|
2018-09-24 12:34:53 +00:00
|
|
|
$action = $this->mTestAction != '0' ? $this->mTestAction : false;
|
|
|
|
$conds[] = $this->buildTestConditions( $dbr, $action );
|
|
|
|
|
2009-01-28 23:54:41 +00:00
|
|
|
// Get our ChangesList
|
2018-02-04 18:50:43 +00:00
|
|
|
$changesList = new AbuseFilterChangesList( $this->getSkin(), $this->mFilter );
|
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'],
|
2018-05-07 15:25:40 +00:00
|
|
|
$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 );
|
2019-02-24 05:29:18 +00:00
|
|
|
// @phan-suppress-next-line PhanUndeclaredProperty not a big deal
|
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
|
|
|
}
|
|
|
|
|
2018-04-04 21:14:25 +00:00
|
|
|
/**
|
|
|
|
* Loads parameters from request
|
|
|
|
*/
|
|
|
|
public 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' );
|
2018-05-07 15:25:40 +00:00
|
|
|
$this->mExcludeBots = $request->getBool( 'wpExcludeBots' );
|
2018-05-01 09:27:00 +00:00
|
|
|
$this->mTestAction = $request->getText( 'wpTestAction' );
|
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
|
|
|
}
|