Page MenuHomePhabricator

Add Syntax Highlighting to mobile web wikitext editor
Open, Needs TriagePublicFeature

Description

Feature summary (what you would like to be able to do and where):
Add support for CodeMirror Syntax Highlighting on the mobile skin's wikitext editor.

Use case(s) and Benefits (Describe the actual underlying problem which you want to solve. Why should this be implemented? Do not describe only a solution):
On the mobile skin (at least on iOS) the source editor is a bare-bones black and white text-area with no advanced functionality. Adding Syntax Highlighting would help with this, and make the source editor a lot easier to navigate. This would also be a lifesaver for mobile template editing, which is currently extremely difficult. It could look similar to how Minerva's editor looks on mobile.
See also: T106267: mobile phone wikitext editor should have edit toolbar.

Event Timeline

With the current mobile editor, this is actually pretty straightforward. I have an old WIP patch I can submit when I get a chance.

The outstanding issue of course is there's no simple way to disable CM in this editor. Maybe we could add a toggle button to the currently very-limited toolbar.

The outstanding issue of course is there's no simple way to disable CM in this editor. Maybe we could add a toggle button to the currently very-limited toolbar.

Actually if you look closer, there is no toolbar at all in the mentioned mobile web wikitext editing surface (also known as MobileFrontend editor), which is a rather surprising and unacceptable to me (as mentioned by me at T106267#12300683 ). @DLynch , do you have any ideas regarding this issue?

Screenshot_2026-09-09-07-00-42-557_com.android.chrome-edit.jpg (1,220×2,448 px, 572 KB)

You could argue it's not a toolbar (as there are no tools to select from), but I was referring to the whatever-you-call-it at the top with editor switch, etc.

@DLynch , do you have any ideas regarding this issue?

@Hakimi97 my preferred approach would be "turn on the 2017 editor on mobile". 🤩 (Yes, I know, I'm very one-note in these discussions.)

There's an existing mediawiki config for it: MFEnableVEWikitextEditor. If you have access to a debug environment on mobile (or just visit on desktop with ?useformat=mobile) you can see it by typing mw.config.set( 'wgMFEnableVEWikitextEditor', true ) in the browser console.

CleanShot 2026-09-10 at 5.07.16 PM@2x.png (792×1,696 px, 275 KB)

...and then you'd get equivalency with mobile VE.

We could make the mobile editor respect the 2017 editor preference, then everybody wins :) If that were the case, with the 2017 editor turned off, we are stuck with the MobileFrontend for now, but we can look forward to a mobile-friendly standalone CodeMirror experience after T95148.

Regardless, there are quick wins to get syntax highlighting in the mobile editor, be it purely via 2017 editor, or MobileFrontend + CM.

If going the VE route, I would recommend we ship T432558 first as mobile devices are more prone to performance issues. That hopefully will happen as soon as this coming Monday.

Err… it seems CodeMirror is not yet available in the mobile 2017 editor (?), though I imagine that's not difficult to add.

It's a side-effect of how CodeMirror is activated in NWE, which is sort of peculiar: CodeMirror's gateway into NWE is that it registers ve.ui.CodeMirrorTool, which is the toolbar button that toggles highlighting. The initial-toggle when the editor is loaded is handled by that tool having an onSurfaceChange listener registered. However, the mobile toolbar doesn't have a place for this toolbar button to go, and so it never sets up the tool...

The advantage of this approach is that it's literally impossible to have CodeMirror active in NWE without there being a way to toggle it on/off.

It'd be reasonably easy to move the initial toggle into ve.ui.CodeMirror.init.js, which already has all the lifecycle hooks we'd need, and we could more directly allowlist surfaces it could engage with.

The absolute simplest thing to do would be to change ve.init.mw.MobileArticleTarget.js line 103 to:

include: [ { group: 'editMode' }, { group: 'utility' } ],

Which immediately gives us all the pageMenu items folded into that menu:

CleanShot 2026-09-13 at 10.51.50 AM@2x.png (788×1,694 px, 205 KB)

(That's with no CSS tweaks whatsoever. Would probably make sense to e.g. tighten up the line number spacing on mobile.)

This would actually make a bit more sense under T423146's regime, which includes changing the icon for that menu to a ....

Brief testing suggests that this only works okay with cmhighlight=1. The expected alignments for the classic codemirror integration just plain don't work.

We could make the mobile editor respect the 2017 editor preference, then everybody wins :) If that were the case, with the 2017 editor turned off, we are stuck with the MobileFrontend for now, but we can look forward to a mobile-friendly standalone CodeMirror experience after T95148.

I think that it would be nice if the preference was separate, as someone who dislikes the 2017 Wikitext Editor on desktop but would like a toolbar on mobile. Just my opinion though.

In T437148#12315480, Axolitl wrote:

We could make the mobile editor respect the 2017 editor preference, then everybody wins :) If that were the case, with the 2017 editor turned off, we are stuck with the MobileFrontend for now, but we can look forward to a mobile-friendly standalone CodeMirror experience after T95148.

I think that it would be nice if the preference was separate, as someone who dislikes the 2017 Wikitext Editor on desktop but would like a toolbar on mobile. Just my opinion though.

Yes, for similar reasons I never jumped on offering standalone CM in DiscussionTools either. T95148 is a reasonable prerequisite.

If we get 2017 editor working easily enough (related: Highlight API version will be enabled for everyone starting very soon), then I think that's sufficient to consider this task resolved.