From f0757cb0dcb2fb45807bdd765b5cf89272b940d2 Mon Sep 17 00:00:00 2001 From: Fomafix Date: Mon, 11 Mar 2019 07:04:20 +0100 Subject: [PATCH] Do not load module 'ext.CodeMirror' when CodeEditor is active Change-Id: I8fd0de727f2ebb1bf9f23981438d6cafa962ad17 --- includes/CodeMirrorHooks.php | 12 +++++++++--- resources/ext.CodeMirror.js | 4 ---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/includes/CodeMirrorHooks.php b/includes/CodeMirrorHooks.php index 7372f1a1..a14460b3 100644 --- a/includes/CodeMirrorHooks.php +++ b/includes/CodeMirrorHooks.php @@ -5,10 +5,16 @@ class CodeMirrorHooks { /** * Checks if CodeMirror for textarea wikitext editor should be loaded on this page or not. * - * @param IContextSource $context The current ContextSource object + * @param OutputPage $out * @return bool */ - private static function isCodeMirrorOnPage( IContextSource $context ) { + private static function isCodeMirrorOnPage( OutputPage $out ) { + // Disable CodeMirror when CodeEditor is active on this page + // Depends on ext.codeEditor being added by EditPage::showEditForm:initial + if ( in_array( 'ext.codeEditor', $out->getModules() ) ) { + return false; + } + $context = $out->getContext(); return in_array( Action::getActionName( $context ), [ 'edit', 'submit' ] ) && // CodeMirror on textarea wikitext editors doesn't support RTL (T170001) !$context->getTitle()->getPageLanguage()->isRTL(); @@ -23,7 +29,7 @@ class CodeMirrorHooks { * @param Skin &$skin */ public static function onBeforePageDisplay( OutputPage &$out, Skin &$skin ) { - if ( self::isCodeMirrorOnPage( $out->getContext() ) ) { + if ( self::isCodeMirrorOnPage( $out ) ) { $out->addModules( 'ext.CodeMirror' ); } // TODO: for backwards compatibility. Remove in 2019. diff --git a/resources/ext.CodeMirror.js b/resources/ext.CodeMirror.js index 178dde85..309e857c 100644 --- a/resources/ext.CodeMirror.js +++ b/resources/ext.CodeMirror.js @@ -3,10 +3,6 @@ $textbox1, enableContentEditable = true; - if ( mw.config.get( 'wgCodeEditorCurrentLanguage' ) ) { // If the CodeEditor is used then just exit; - return; - } - // 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 ) ) {