Catrope has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/231481

Change subject: BoardDescriptionWidget: Don't fetch wikitext when initializing 
VE
......................................................................

BoardDescriptionWidget: Don't fetch wikitext when initializing VE

BoardDescriptionWidget had code that tried to determine which content
format to fetch, but it never worked and always fell back to wikitext.
That meant that if VE was going to be loaded, it would do two API
requests: one to fetch wikitext, then another to convert that to HTML.

Change-Id: I154dcb418b7e0d06448b0625f841eae76924dd99
---
M modules/flow/ui/widgets/editor/mw.flow.ui.EditorSwitcherWidget.js
M modules/flow/ui/widgets/editor/mw.flow.ui.EditorWidget.js
M modules/flow/ui/widgets/mw.flow.ui.BoardDescriptionWidget.js
3 files changed, 35 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/81/231481/1

diff --git a/modules/flow/ui/widgets/editor/mw.flow.ui.EditorSwitcherWidget.js 
b/modules/flow/ui/widgets/editor/mw.flow.ui.EditorSwitcherWidget.js
index 1e24a9c..8d16a2c 100644
--- a/modules/flow/ui/widgets/editor/mw.flow.ui.EditorSwitcherWidget.js
+++ b/modules/flow/ui/widgets/editor/mw.flow.ui.EditorSwitcherWidget.js
@@ -162,6 +162,16 @@
        };
 
        /**
+        * Get the format used by a given editor type.
+        * @param {string} name Editor name
+        * @return {string|null} Format used by that editor, or null if no such 
editor exists
+        */
+       mw.flow.ui.EditorSwitcherWidget.prototype.getEditorFormat = function ( 
name ) {
+               var definition = 
this.constructor.static.editorDefinitions[name];
+               return definition ? definition.static.format : null;
+       };
+
+       /**
         * Create an editor and add it to this.editors.
         *
         * This method is safe to call multiple times. If the requested editor 
has already been
diff --git a/modules/flow/ui/widgets/editor/mw.flow.ui.EditorWidget.js 
b/modules/flow/ui/widgets/editor/mw.flow.ui.EditorWidget.js
index aa2cadc..6a998fd 100644
--- a/modules/flow/ui/widgets/editor/mw.flow.ui.EditorWidget.js
+++ b/modules/flow/ui/widgets/editor/mw.flow.ui.EditorWidget.js
@@ -132,6 +132,30 @@
        };
 
        /**
+        * Get the name of the editor that would be loaded if this widget were 
to be
+        * activated right now.
+        *
+        * Note that the return value of this function can change over time as 
the user switches
+        * editors in different EditorWidgets. The editor that is actually 
loaded when activating
+        * is determined by calling this function at activation time, no 
earlier.
+        *
+        * @return {string} Name of initial editor that will be used
+        */
+       mw.flow.ui.EditorWidget.prototype.getInitialEditorName = function () {
+               return this.initialEditor || mw.user.options.get( 'flow-editor' 
);
+       };
+
+       /**
+        * Get the format of the editor that would be loaded if this widget 
were to be
+        * activated right now.
+        * @return {string} Format used by initial editor
+        * @see #getInitialEditorName
+        */
+       mw.flow.ui.EditorWidget.prototype.getInitialFormat = function () {
+               return this.editorSwitcherWidget.getEditorFormat( 
this.getInitialEditorName() );
+       };
+
+       /**
         * Toggle whether the editor is automatically focused after switching.
         * @param {boolean} [autoFocus] Whether to focus automatically; if 
unset, flips current value
         */
diff --git a/modules/flow/ui/widgets/mw.flow.ui.BoardDescriptionWidget.js 
b/modules/flow/ui/widgets/mw.flow.ui.BoardDescriptionWidget.js
index e788dd0..b799167 100644
--- a/modules/flow/ui/widgets/mw.flow.ui.BoardDescriptionWidget.js
+++ b/modules/flow/ui/widgets/mw.flow.ui.BoardDescriptionWidget.js
@@ -91,10 +91,7 @@
         */
        mw.flow.ui.BoardDescriptionWidget.prototype.onEditButtonClick = 
function () {
                var widget = this,
-                       contentFormat = (
-                               
this.editor.editorSwitcherWidget.getActiveEditor() &&
-                               
this.editor.editorSwitcherWidget.getActiveEditor().getFormat()
-                       ) || 'wikitext';
+                       contentFormat = this.editor.getInitialFormat();
 
                // Hide the edit button, any errors, and the content
                this.button.toggle( false );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I154dcb418b7e0d06448b0625f841eae76924dd99
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Catrope <[email protected]>

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

Reply via email to