Pastakhov has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/348677 )

Change subject: Remove some outdated code
......................................................................

Remove some outdated code

Since WikiEditor uses wikiEditor-toolbar-doneInitialSections event
  we don't need to add it to ResourceLoader dependencies.

Bug: T161475
Change-Id: I7c7c3ba495c0292d2df052145e7930c86fcb48f5
---
M CodeMirror.hooks.php
M extension.json
M resources/ext.CodeMirror.js
3 files changed, 17 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CodeMirror 
refs/changes/77/348677/1

diff --git a/CodeMirror.hooks.php b/CodeMirror.hooks.php
index f425499..1f8b369 100644
--- a/CodeMirror.hooks.php
+++ b/CodeMirror.hooks.php
@@ -39,11 +39,6 @@
                        'dependencies' => [ 'ext.CodeMirror.lib' => true ],
                ];
 
-               // Check if WikiEditor is installed and add it as a dependency
-               if ( \ExtensionRegistry::getInstance()->isLoaded( 'WikiEditor' 
) ) {
-                       $extResources['dependencies']['ext.wikiEditor'] = true;
-               }
-
                // enable other extensions to add additional resources and modes
                Hooks::run( 'CodeMirrorGetAdditionalResources', [ 
&$extResources, &self::$extModes ] );
 
diff --git a/extension.json b/extension.json
index d81a116..042c1d6 100644
--- a/extension.json
+++ b/extension.json
@@ -22,10 +22,10 @@
                        "dependencies": [
                                "ext.CodeMirror.lib",
                                "ext.CodeMirror.other",
-                               "mediawiki.api",
                                "jquery.textSelection",
-                               "user.options",
-                               "mediawiki.api.options"
+                               "mediawiki.api",
+                               "mediawiki.api.options",
+                               "user.options"
                        ],
                        "scripts": [
                                "ext.CodeMirror.js"
diff --git a/resources/ext.CodeMirror.js b/resources/ext.CodeMirror.js
index 3d48d0b..5ebccee 100644
--- a/resources/ext.CodeMirror.js
+++ b/resources/ext.CodeMirror.js
@@ -1,5 +1,5 @@
 ( function ( mw, $ ) {
-       var origTextSelection, useCodeMirror, codeMirror, api, 
originHooksTextarea;
+       var origTextSelection, useCodeMirror, codeMirror, api, 
originHooksTextarea, wikiEditorToolbarEnabled = false;
 
        if ( mw.config.get( 'wgCodeEditorCurrentLanguage' ) ) { // If the 
CodeEditor is used then just exit;
                return;
@@ -11,6 +11,13 @@
        useCodeMirror = mw.user.options.get( 'usecodemirror' ) > 0;
        api = new mw.Api();
        originHooksTextarea = $.valHooks.textarea;
+
+       if ( mw.loader.getState( 'ext.wikiEditor' ) ) {  // The WikiEditor 
extension exists
+               // This can be the string "0" if the user disabled the 
preference - Bug T54542#555387
+               if ( mw.user.options.get( 'usebetatoolbar' ) > 0 ) { // And the 
WikiEditor beta toolbar is used by the user
+                       wikiEditorToolbarEnabled = true;
+               }
+       }
 
        // function for a textselection function for CodeMirror
        function cmTextSelection( command, options ) {
@@ -356,7 +363,7 @@
         *
         * @param {boolean} [useWikiEditor]
         */
-       function enableCodeMirror( useWikiEditor ) {
+       function enableCodeMirror() {
                var $codeMirror,
                        $textbox1 = $( '#wpTextbox1' );
 
@@ -386,7 +393,7 @@
                        'line-height': $textbox1.css( 'line-height' )
                } );
 
-               if ( !useWikiEditor ) {
+               if ( !wikiEditorToolbarEnabled ) {
                        $codeMirror.addClass( 'mw-codeMirror-classicToolbar' );
                }
 
@@ -398,10 +405,7 @@
 
        /* Check if view is in edit mode and that the required modules are 
available. Then, customize the toolbar … */
        if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== 
-1 ) {
-               // This function shouldn't be called without user.options is 
loaded, but it's not guaranteed
-               mw.loader.using( 'user.options', function () {
-                       // This 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 ( wikiEditorToolbarEnabled ) {
                                // load wikiEditor's toolbar (if not already) 
and add our button
                                $( '#wpTextbox1' ).on( 
'wikiEditor-toolbar-doneInitialSections', addCodeMirrorToWikiEditor );
                        } else {
@@ -419,15 +423,14 @@
                                        $( function () { updateToolbarButton(); 
} );
                                } );
                        }
-               } );
        }
 
        // enable CodeMirror
        if ( useCodeMirror ) {
-               if ( mw.loader.getState( 'ext.wikiEditor' ) ) {
-                       $( '#wpTextbox1' ).on( 
'wikiEditor-toolbar-doneInitialSections', enableCodeMirror.bind( this, true ) );
+               if ( wikiEditorToolbarEnabled ) {
+                       $( '#wpTextbox1' ).on( 
'wikiEditor-toolbar-doneInitialSections', enableCodeMirror.bind( this ) );
                } else {
-                       enableCodeMirror( false );
+                       enableCodeMirror();
                }
        }
 }( mediaWiki, jQuery ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/348677
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7c7c3ba495c0292d2df052145e7930c86fcb48f5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CodeMirror
Gerrit-Branch: master
Gerrit-Owner: Pastakhov <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to