Page MenuHomePhabricator

SearchFilters.php: Allow searching for filters that have no consequences
Closed, ResolvedPublicBUG REPORT

Description

What is the problem?

Currently, --consequence parameter allows you to search for a filter with a specific consequence, but you cannot search for filters that have no consequences.

Steps to reproduce problem
  1. The SearchFilters.php maintenance script can be run like so:
    1. Locally on bare metal, run php maintenance/run.php AbuseFilter:SearchFilters.php --consequence="block"
    2. On docker, run docker compose exec mediawiki php maintenance/run.php AbuseFilter:SearchFilters.php --consequence="block"
    3. On beta (if you have access), run mwscript extensions/AbuseFilter/maintenance/SearchFilters --wiki=enwiki --consequence="block"

Expected behaviour: If you run something like SearchFilters.php --consequence="" it should return filters which don't have any consequences checked
Observed behaviour: Running SearchFilters.php --consequence="" returns error One of --consequence or --pattern should be specified.

Environment

Wiki(s): https://en.wikipedia.beta.wmflabs.org Abuse Filter – (aee25cf) 10:19, 27 August 2024.

Event Timeline

Hi @dom_walden , I'd like to work on this.

Reading the script, I see this is a small ambiguity: --consequence="" is currently rejected by the early guard because empty string is falsy, while the existing privacy option already distinguishes "not passed" (null) from "passed empty" ('').

My proposed approach (matching the privacy precedent):

  • Treat --consequence omitted as "no consequence filter" (current behaviour preserved)
  • Treat --consequence="" as "match filters with empty af_actions"
  • Existing tests that pass 'consequence' => '' to mean "don't filter" will be updated to omit the parameter instead — same approach the privacy test cases use

Would you like me to proceed with this, or would you prefer a separate flag like --no-consequence?
Will keep the patch single-file plus the test update.

Would you like me to proceed with this, or would you prefer a separate flag like --no-consequence?
Will keep the patch single-file plus the test update.

I don't have a strong feeling either way. What you propose sounds sensible to me. I think as long as it is well documented, it should be fine.

Change #1296554 had a related patch set uploaded (by Rajveer42; author: Rajveer42):

[mediawiki/extensions/AbuseFilter@master] Allow --consequence="" in SearchFilters to match filters with no consequences

https://gerrit.wikimedia.org/r/1296554

Patch up: https://gerrit.wikimedia.org/r/c/mediawiki/extensions/AbuseFilter/+/1296554

Implements the discussed semantic split: --consequence omitted = no filter; --consequence="" = match filters with empty af_actions. Updates the existing PHPUnit cases to use null for "no filter" and adds a new case asserting empty-string returns the no-consequence filter (id 1 from the fixtures). Help text on the option updated to document the behavior.

cc @dom_walden

Change #1296554 merged by jenkins-bot:

[mediawiki/extensions/AbuseFilter@master] Allow --consequence="" in SearchFilters to match filters with no consequences

https://gerrit.wikimedia.org/r/1296554