summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'AbuseFilter/includes/Views/AbuseFilterViewTestBatch.php')
-rw-r--r--AbuseFilter/includes/Views/AbuseFilterViewTestBatch.php89
1 files changed, 62 insertions, 27 deletions
diff --git a/AbuseFilter/includes/Views/AbuseFilterViewTestBatch.php b/AbuseFilter/includes/Views/AbuseFilterViewTestBatch.php
index 168933ec..89ae088a 100644
--- a/AbuseFilter/includes/Views/AbuseFilterViewTestBatch.php
+++ b/AbuseFilter/includes/Views/AbuseFilterViewTestBatch.php
@@ -1,11 +1,45 @@
<?php
+use MediaWiki\Extension\AbuseFilter\VariableGenerator\RCVariableGenerator;
+
class AbuseFilterViewTestBatch extends AbuseFilterView {
- // Hard-coded for now.
+ /**
+ * @var int The limit of changes to test, hard coded for now
+ */
protected static $mChangeLimit = 100;
- public $mShowNegative, $mTestPeriodStart, $mTestPeriodEnd, $mTestPage;
- public $mTestUser, $mExcludeBots, $mTestAction;
+ /**
+ * @var bool Whether to show changes that don't trigger the specified pattern
+ */
+ public $mShowNegative;
+ /**
+ * @var string The start time of the lookup period
+ */
+ public $mTestPeriodStart;
+ /**
+ * @var string The end time of the lookup period
+ */
+ public $mTestPeriodEnd;
+ /**
+ * @var string The page of which edits we're interested in
+ */
+ public $mTestPage;
+ /**
+ * @var string The user whose actions we want to test
+ */
+ public $mTestUser;
+ /**
+ * @var bool Whether to exclude bot edits
+ */
+ public $mExcludeBots;
+ /**
+ * @var string The action (performed by the user) we want to search for
+ */
+ public $mTestAction;
+ /**
+ * @var string The text of the rule to test changes against
+ */
+ private $testPattern;
/**
* Shows the page
@@ -13,9 +47,7 @@ class AbuseFilterViewTestBatch extends AbuseFilterView {
public function show() {
$out = $this->getOutput();
- AbuseFilter::disableConditionLimit();
-
- if ( !$this->canViewPrivate() ) {
+ if ( !AbuseFilter::canViewPrivate( $this->getUser() ) ) {
$out->addWikiMsg( 'abusefilter-mustviewprivateoredit' );
return;
}
@@ -29,14 +61,13 @@ class AbuseFilterViewTestBatch extends AbuseFilterView {
$output = '';
$output .=
$this->buildEditBox(
- $this->mFilter,
- 'wpTestFilter',
+ $this->testPattern,
true,
true,
false
) . "\n";
- $output .= AbuseFilter::buildFilterLoader();
+ $output .= $this->buildFilterLoader();
$output = Xml::tags( 'div', [ 'id' => 'mw-abusefilter-test-editor' ], $output );
$RCMaxAge = $this->getConfig()->get( 'RCMaxAge' );
@@ -54,8 +85,8 @@ class AbuseFilterViewTestBatch extends AbuseFilterView {
$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
+ $this->msg( 'abusefilter-test-search-type-createaccount' )->text() => 'createaccount',
+ $this->msg( 'abusefilter-test-search-type-upload' )->text() => 'upload'
]
];
$formFields['wpTestUser'] = [
@@ -126,8 +157,10 @@ class AbuseFilterViewTestBatch extends AbuseFilterView {
public function doTest() {
// Quick syntax check.
$out = $this->getOutput();
- $result = AbuseFilter::checkSyntax( $this->mFilter );
- if ( $result !== true ) {
+ $parser = AbuseFilter::getDefaultParser();
+
+ $validSyntax = $parser->checkSyntax( $this->testPattern );
+ if ( $validSyntax !== true ) {
$out->addWikiMsg( 'abusefilter-test-syntaxerr' );
return;
}
@@ -160,18 +193,15 @@ class AbuseFilterViewTestBatch extends AbuseFilterView {
}
}
- $action = $this->mTestAction != '0' ? $this->mTestAction : false;
- $conds[] = $this->buildTestConditions( $dbr, $action );
-
- $conds = array_filter( $conds );
-
- // To be added after filtering, otherwise it gets stripped
if ( $this->mExcludeBots ) {
$conds['rc_bot'] = 0;
}
+ $action = $this->mTestAction !== '0' ? $this->mTestAction : false;
+ $conds[] = $this->buildTestConditions( $dbr, $action );
+
// Get our ChangesList
- $changesList = new AbuseFilterChangesList( $this->getSkin(), $this->mFilter );
+ $changesList = new AbuseFilterChangesList( $this->getSkin(), $this->testPattern );
$output = $changesList->beginRecentChangesList();
$rcQuery = RecentChange::getQueryInfo();
@@ -186,19 +216,24 @@ class AbuseFilterViewTestBatch extends AbuseFilterView {
$counter = 1;
+ $contextUser = $this->getUser();
+ $parser->toggleConditionLimit( false );
foreach ( $res as $row ) {
- $vars = AbuseFilter::getVarsFromRCRow( $row );
+ $vars = new AbuseFilterVariableHolder();
+ $rc = RecentChange::newFromRow( $row );
+ $varGenerator = new RCVariableGenerator( $vars, $rc, $contextUser );
+ $vars = $varGenerator->getVars();
if ( !$vars ) {
continue;
}
- $result = AbuseFilter::checkConditions( $this->mFilter, $vars );
+ $parser->setVariables( $vars );
+ $result = $parser->checkConditions( $this->testPattern );
if ( $result || $this->mShowNegative ) {
// Stash result in RC item
- $rc = RecentChange::newFromRow( $row );
- /** @suppress PhanUndeclaredProperty for $rc->filterResult, which isn't a big deal */
+ // @phan-suppress-next-line PhanUndeclaredProperty not a big deal
$rc->filterResult = $result;
$rc->counter = $counter++;
$output .= $changesList->recentChangesLine( $rc, false );
@@ -216,7 +251,7 @@ class AbuseFilterViewTestBatch extends AbuseFilterView {
public function loadParameters() {
$request = $this->getRequest();
- $this->mFilter = $request->getText( 'wpTestFilter' );
+ $this->testPattern = $request->getText( 'wpFilterRules' );
$this->mShowNegative = $request->getBool( 'wpShowNegative' );
$testUsername = $request->getText( 'wpTestUser' );
$this->mTestPeriodEnd = $request->getText( 'wpTestPeriodEnd' );
@@ -225,12 +260,12 @@ class AbuseFilterViewTestBatch extends AbuseFilterView {
$this->mExcludeBots = $request->getBool( 'wpExcludeBots' );
$this->mTestAction = $request->getText( 'wpTestAction' );
- if ( !$this->mFilter
+ if ( !$this->testPattern
&& count( $this->mParams ) > 1
&& is_numeric( $this->mParams[1] )
) {
$dbr = wfGetDB( DB_REPLICA );
- $this->mFilter = $dbr->selectField( 'abuse_filter',
+ $this->testPattern = $dbr->selectField( 'abuse_filter',
'af_pattern',
[ 'af_id' => $this->mParams[1] ],
__METHOD__