User:Msz2001/AbuseFilter analyzer
![](http://upload.wikimedia.org/wikipedia/commons/thumb/2/26/AbuseFilter_analyzer_gadget.png/220px-AbuseFilter_analyzer_gadget.png)
The AbuseFilter analyzer is a user script that's capable of parsing the AbuseFilter conditions and evaluate them. All the processing is done in the user browser and values in all the intermediate nodes are recorded as well as is the final result.
The script might be especially useful when debugging filters and checking for a reason why a false-positive was generated.
This script is hosted in a GitHub repository whpac/abusefilter-analyzer and the compiled version is hosted on plwiki: w:pl:Wikipedysta:Msz2001/abusefilter-analyzer.js. It's written in TypeScript.
How does it work
[edit]When you navigate to AbuseLog and display details of a log entry, the evaluation tree will render above the attempted diff. From there you can see the value of every expression that is part of the filter conditions.
The script is shipped with its own AF rule parser and evaluator that are executed in the user browser. This is done to reduce the dependency on AbuseFilter's limited API and can allow to create more complex applications of the library.
Install
[edit]Add to your common.js file:
mw.loader.load("//pl.wikipedia.org/w/index.php?title=Wikipedysta:Msz2001/abusefilter-analyzer-primer.js&action=raw&ctype=text/javascript");
This will load the script only on abuse log page.
Features
[edit]- Display a calculated value in every tree node.
- Evaluate the whole tree, regardless of conditional and short-circuiting operators (but some of it is calculated speculatively, without effect of the result).
- Report evaluation errors where they happen but continue evaluation.
- Process PCRE syntax of regex.
- Code architecture is highly modular and designed to be reusable.
Known limitations
[edit]- The log entry is tested against the most recent version of the filter, so evaluation can yield
false
as the result. - Some variables are generated and saved by AbuseFilter only if they are explicitly read by the filter (in the specific execution path). Therefore some variables will be
null
, even though they would have another value at the actual execution. - Functions from the
ccnorm
family are executed on server and are available only for those who can use theabusefilterevalexpression
endpoint. - Regular expressions are translated into JS ones using a custom-made library for that purpose. It may be imperfect.
- Only English interface messages are supported, some errors are reported with code string like
dividebyzero
.
Plans for the future
[edit]- For now the gadget is shipped with the huge library for analyzing abuse filters. They will be separated.
- The library will be available for other scripts as eg.
mw.libs.AbuseFilter
. - Internationalize the gadget.