CodeMirror uses the BeforePageDisplay hook, and checks if the action is edit or submit, along with other conditions (Hooks::shouldLoadCodeMirror). It's unclear why this was used over the EditPage::showEditForm:initial hook. As a result, the CodeMirror module gets predelivered even when it isn't used, such as on read-only pages.
Browsing to a page you are unable to edit…
Before r1007746, with $wgCodeMirrorV6 = false;:
> mw.loader.getState( 'ext.CodeMirror.WikiEditor' ) "ready"
and afterwards:
> mw.loader.getState( 'ext.CodeMirror.WikiEditor' ) "registered"
which is what we want.
The module is also loaded pretty much anywhere action=edit is and CodeEditor isn't, so it could unnecessarily be in the startup module in a variety of scenarios. To further address this, we should check the content model to make sure it is one that is supported (as of the time of writing, only wikitext).
Possible risk
- It is possible that some gadget or script out there is assuming CodeMirror is available upfront, when it won't be following this task. A Global Search for CodeMirror.fromTextArea shows most usages already require the ext.CodeMirorr.WikiEditor module (or the CM library directly), so hopefully we won't see much breakage. Nonetheless we should monitor for an increase of JS errors.
Acceptance criteria
- ext.CodeMirror.WikiEditor (or ext.CodeMirror.v6.WikiEditor in the case of CM6) should only be "ready" where CodeMirror is actually usable
- Extensions that have content models needing CodeMirror should register a CodeMirrorContentModels. In our cluster, I *think* this only includes ProofreadPage (r1007747)
QA Results - Beta
AC | Status | Details |
---|---|---|
1 | ✅ | https://phabricator.wikimedia.org/T359206 here |