From b17c8b755758dff5bbcf7c5cae1d2cb4040e7114 Mon Sep 17 00:00:00 2001 From: Fomafix Date: Mon, 11 Mar 2019 07:17:13 +0100 Subject: [PATCH] Move check for 'usebetatoolbar' from JS to PHP This change avoids useless loading of the module 'ext.CodeMirror'. Change-Id: I2637487b72c028d272748f2891239401412f77b5 --- includes/CodeMirrorHooks.php | 4 ++++ resources/ext.CodeMirror.js | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/includes/CodeMirrorHooks.php b/includes/CodeMirrorHooks.php index bc42ca5c..1ac072b6 100644 --- a/includes/CodeMirrorHooks.php +++ b/includes/CodeMirrorHooks.php @@ -14,6 +14,10 @@ class CodeMirrorHooks { if ( in_array( 'ext.codeEditor', $out->getModules() ) ) { return false; } + // Disable CodeMirror when the WikiEditor toolbar is not enabled in preferences + if ( !$out->getUser()->getOption( 'usebetatoolbar' ) ) { + return false; + } $context = $out->getContext(); return in_array( Action::getActionName( $context ), [ 'edit', 'submit' ] ) && // CodeMirror on textarea wikitext editors doesn't support RTL (T170001) diff --git a/resources/ext.CodeMirror.js b/resources/ext.CodeMirror.js index 0760bad6..4a493e67 100644 --- a/resources/ext.CodeMirror.js +++ b/resources/ext.CodeMirror.js @@ -9,8 +9,7 @@ ]; // Exit if WikiEditor is disabled - // usebetatoolbar can be the string "0" if the user disabled the preference - Bug T54542#555387 - if ( !( mw.loader.getState( 'ext.wikiEditor' ) && mw.user.options.get( 'usebetatoolbar' ) > 0 ) ) { + if ( !mw.loader.getState( 'ext.wikiEditor' ) ) { return; }