Page MenuHomePhabricator

Add CodeMirror mode for AbuseFilter syntax
Closed, ResolvedPublic

Description

There are efforts to explore MediaWiki-extensions-CodeMirror as an alternative for CodeEditor across the wikiverse. That effort would not be feature-complete without CodeMirror integration in AbuseFilter.

AbuseFilter has a custom Ace mode that depends on the ext.codeEditor.ace module. While not trivial, things appear to work similarly enough that it should be doable to port this to a CodeMirror 6 StreamParser. Better would be to write a grammar for the Lezer parser system, if the AbuseFilter language allows for it.

After we have a working mode, there's a good bit of backend work to go with it. I propose a configuration similar to what we're doing for all the other CodeEditor integrations, with the feature flags $wgAbuseFilterUseCodeEditor and $wgAbuseFilterUseCodeMirror. A new CodeMirrorEditBoxBuilder class could be created to parity AceEditBoxBuilder, and so on.

Event Timeline

There are short-term goals to enable CodeMirror as the editor for some non-wikitext pages (T373711) for users with the Improved Syntax Highlighting beta preference turned on (CodeMirror 6). This task won't make that release, but I personally see it as a priority for the CodeMirror 6 project.

I have started working on a Lezer mode. Please feel free to try the GitHub page playground, leave comments, and/or contribute.

The Lezer mode for AbuseFilter is more or less completed as an external library, and I have published it to NPM.

I wonder if we should create a new ticket for following integration (frontend and backend) with the CodeMirror extension.

The Lezer mode for AbuseFilter is more or less completed as an external library, and I have published it to NPM.

I wonder if we should create a new ticket for following integration (frontend and backend) with the CodeMirror extension.

Looks and works fantastically!

I want to make sure @Daimona sees this. I imagine we are fine to go the same route we did for T373711 and have a pair of config settings $wgAbuseFilterUseCodeEditor and $wgAbuseFilterUseCodeMirror and carry on in the same way as the other extensions.

This task is isolated to one mode (abusefilter) and not five of them as I carelessly did with T373711, but yeah, if anything feels like a large chunk of work, feel free to create a subtask :)

Thanks for doing this! What is proposed here makes sense to me. The Ace mode was a bit experimental and messy IIRC, so I'm happy to see a proper grammar implementation :)

If possible, can there be an overlap period where both CodeEditor And CodeMirror are available to user scripts? One of mine loads CodeEditor manually and I'd like some time to test it with CodeMirror. Thanks!

Yep! There will definitely be a period where you can load ResourceLoader modules from either CodeEditor or CodeMirror for purposes of user scripts. We'll deprecate the CodeEditor modules and give it a month or two (or however long we need) before removing them entirely.

Thanks, that sounds more than adequate.

Change #1254268 had a related patch set uploaded (by Bhsd; author: Bhsd):

[mediawiki/extensions/CodeMirror@master] [POC] ext.CodeMirror.v6.abusefilter

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

Change #1255283 had a related patch set uploaded (by Bhsd; author: Bhsd):

[mediawiki/extensions/AbuseFilter@master] [POC] CodeMirror editor

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

Bhsd changed the task status from Open to In Progress.EditedMar 20 2026, 10:46 AM
Bhsd claimed this task.

If possible, can there be an overlap period where both CodeEditor And CodeMirror are available to user scripts? One of mine loads CodeEditor manually and I'd like some time to test it with CodeMirror. Thanks!

In my submitted patch, ext.abuseFilter.ace will remain available as long as CodeEditor is installed.

Change #1256318 had a related patch set uploaded (by Bhsd; author: Bhsd):

[integration/config@master] Zuul: [CodeMirror] Add AbuseFilter dependencies

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

Change #1256318 merged by jenkins-bot:

[integration/config@master] Zuul: [mediawiki/extensions/AbuseFilter] Add dependency on CodeMirror

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

Mentioned in SAL (#wikimedia-releng) [2026-03-20T14:59:29Z] <James_F> Zuul: [mediawiki/extensions/AbuseFilter] Add dependency on CodeMirror, for T399673

Change #1254268 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] ext.CodeMirror.v6.abusefilter: new RL module

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

Change #1255283 merged by jenkins-bot:

[mediawiki/extensions/AbuseFilter@master] EditBoxBuilder: CodeMirror editor

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

Change #1268652 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[operations/mediawiki-config@master] CommonSettings: use CodeMirror instead of CodeEditor in AbuseFilter

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

I guess this could use a shoutout in Tech News ahead of time, in the event there are other user scripts and gadgets like T399673#11693805. I've added an entry to the next issue and will wait until Thursday, April 16 to deploy r1268652.

Change #1271182 had a related patch set uploaded (by MusikAnimal; author: MusikAnimal):

[mediawiki/extensions/AbuseFilter@master] ext.abuseFilter.edit: target newly updated CodeMirror modules

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

Change #1271182 merged by jenkins-bot:

[mediawiki/extensions/AbuseFilter@master] ext.abuseFilter.edit: target newly updated CodeMirror modules

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

As a user without abusefilter status, I still have the CodeEditor view of AbuseFilter. Is it the expected behavior?

image_2026-04-17_004632776.png (628×1 px, 37 KB)

Change #1268652 merged by jenkins-bot:

[operations/mediawiki-config@master] CommonSettings: use CodeMirror instead of CodeEditor in AbuseFilter

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

Mentioned in SAL (#wikimedia-operations) [2026-04-16T23:18:39Z] <musikanimal@deploy1003> Started scap sync-world: Backport for [[gerrit:1268652|CommonSettings: use CodeMirror instead of CodeEditor in AbuseFilter (T399673)]]

Mentioned in SAL (#wikimedia-operations) [2026-04-16T23:20:18Z] <musikanimal@deploy1003> musikanimal: Backport for [[gerrit:1268652|CommonSettings: use CodeMirror instead of CodeEditor in AbuseFilter (T399673)]] synced to the testservers (see https://wikitech.wikimedia.org/wiki/Mwdebug). Changes can now be verified there.

Mentioned in SAL (#wikimedia-operations) [2026-04-16T23:25:14Z] <musikanimal@deploy1003> Finished scap sync-world: Backport for [[gerrit:1268652|CommonSettings: use CodeMirror instead of CodeEditor in AbuseFilter (T399673)]] (duration: 06m 35s)

As a user without abusefilter status, I still have the CodeEditor view of AbuseFilter. Is it the expected behavior?

Try now :) This was a configuration change so it got deployed via a backport window, as opposed to the usual deployment train.

Thanks again to @Bhsd for the amazing work!