jenkins-bot has submitted this change and it was merged.
Change subject: Reduce edit form latency and work around bug 55682
......................................................................
Reduce edit form latency and work around bug 55682
Request edit content in the format accepted by the appropriate editor, instead
of
always in wikitext and then converting to HTML as appropriate
Change-Id: I1a3bdaed5bf2eacd55462e46a19e7ef4a1e24d89
---
M includes/Block/Header.php
M includes/Block/Topic.php
M modules/base/ui-functions.js
M modules/discussion/forms.js
M modules/editor/ext.flow.editor.js
M modules/header/forms.js
6 files changed, 63 insertions(+), 12 deletions(-)
Approvals:
Matthias Mullie: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/Block/Header.php b/includes/Block/Header.php
index 5103a80..14f9540 100644
--- a/includes/Block/Header.php
+++ b/includes/Block/Header.php
@@ -99,8 +99,15 @@
$output = array();
$output['type'] = 'header';
+ $contentFormat = 'wikitext';
+
+ if ( isset( $options['contentFormat'] ) ) {
+ $contentFormat = $options['contentFormat'];
+ }
+
if ( $this->header !== null ) {
- $output['*'] = $this->header->getContent( $this->user,
'wikitext' );
+ $output['*'] = $this->header->getContent( $this->user,
$contentFormat );
+ $output['format'] = $contentFormat;
$output['header-id'] =
$this->header->getRevisionId()->getHex();
} else {
$output['missing'] = 'missing';
diff --git a/includes/Block/Topic.php b/includes/Block/Topic.php
index 0696699..7df215d 100644
--- a/includes/Block/Topic.php
+++ b/includes/Block/Topic.php
@@ -390,11 +390,19 @@
$output = array();
$output['post-id'] = $post->getPostId()->getHex();
+ $contentFormat = 'wikitext';
+
+ if ( isset( $options['contentFormat'] ) ) {
+ $contentFormat = $options['contentFormat'];
+ }
if ( $post->isModerated() ) {
$output['post-moderated'] = 'post-moderated';
} else {
- $output['content'] = array( '*' => $post->getContent(
null, 'wikitext' ) );
+ $output['content'] = array(
+ '*' => $post->getContent( null, $contentFormat
),
+ 'format' => $contentFormat
+ );
$output['user'] = $post->getUserText();
}
diff --git a/modules/base/ui-functions.js b/modules/base/ui-functions.js
index 9279196..c8fd09a 100644
--- a/modules/base/ui-functions.js
+++ b/modules/base/ui-functions.js
@@ -67,6 +67,16 @@
return $form;
},
+ /**
+ * Sets up an edit form.
+ * @param {string} type The type of
edit form (single word)
+ * @param {string|object} initialContent The content
to pre-fill.
+ * An object, with the keys 'content' and 'format'. Or
a plain string of wikitext.
+ * @param {function} submitFunction Function to
call in order to submit the form.
+ * One parameter, the content.
+ * @return {Promise} A promise
that will be resolved or rejected
+ * when the form submission has returned.
+ */
'setupEditForm' : function( type, initialContent,
submitFunction ) {
var deferredObject = $.Deferred();
var $contentContainer = $(this);
@@ -112,7 +122,14 @@
)
.insertAfter( $contentContainer
);
- mw.flow.editor.load( $postForm.find(
'textarea' ), initialContent );
+ if ( typeof initialContent != 'object'
) {
+ initialContent = {
+ 'content' :
initialContent,
+ 'format' : 'wikitext'
+ };
+ }
+
+ mw.flow.editor.load( $postForm.find(
'textarea' ), initialContent.content, initialContent.format );
$contentContainer.hide();
diff --git a/modules/discussion/forms.js b/modules/discussion/forms.js
index 9bec656..2ee3544 100644
--- a/modules/discussion/forms.js
+++ b/modules/discussion/forms.js
@@ -143,7 +143,8 @@
{
'topic' : {
'no-children' : true,
- 'postId' : postId
+ 'postId' : postId,
+ 'contentFormat' :
mw.flow.editor.getFormat()
}
}
)
@@ -162,7 +163,10 @@
$contentContainer.flow( 'setupEditForm',
'post',
- data[0].content['*'],
+ {
+ 'content' :
data[0].content['*'],
+ 'format' :
data[0].content.format
+ },
function( content ) {
return
mw.flow.api.editPost( workflowId, postId, content );
}
diff --git a/modules/editor/ext.flow.editor.js
b/modules/editor/ext.flow.editor.js
index 3953870..4586b21 100644
--- a/modules/editor/ext.flow.editor.js
+++ b/modules/editor/ext.flow.editor.js
@@ -36,19 +36,24 @@
/**
* @param {jQuery} $node
- * @param {string} [content] Existing content to load, in
wikitext format
+ * @param {string} [content] Existing content to load, in any
format
+ * @param {string} [contentFormat] The format that content is
in, or null (defaults to wikitext)
*/
- load: function ( $node, content ) {
+ load: function ( $node, content, contentFormat ) {
/**
* When calling load(), init() may nog yet have
completed loading the
* dependencies. To make sure it doesn't break, this
will in interval,
* check for it and only start loading once
initialization is complete.
*/
- var load = function ( $node, content ) {
+ var load = function ( $node, content, contentFormat ) {
if ( mw.flow.editor.editor === null ) {
return;
} else {
clearTimeout( interval );
+ }
+
+ if ( contentFormat === undefined ) {
+ contentFormat = 'wikitext';
}
// quit early if editor is already loaded
@@ -57,14 +62,14 @@
}
if ( content ) {
- content = mw.flow.parsoid.convert(
'wikitext', mw.flow.editor.getFormat(), content );
+ content = mw.flow.parsoid.convert(
contentFormat, mw.flow.editor.getFormat(), content );
} else {
content = '';
}
mw.flow.editor.create( $node, content );
},
- interval = setInterval( load.bind( this, $node, content
), 10 );
+ interval = setInterval( load.bind( this, $node,
content, contentFormat ), 10 );
},
/**
diff --git a/modules/header/forms.js b/modules/header/forms.js
index 4d343fe..b49e281 100644
--- a/modules/header/forms.js
+++ b/modules/header/forms.js
@@ -12,7 +12,13 @@
mw.flow.api.readHeader(
pageName,
- workflowId
+ workflowId,
+ {
+ 'header' :
+ {
+ 'contentFormat' :
mw.flow.editor.getFormat()
+ }
+ }
).done( function( data ) {
if ( ! data[0] ) {
console.dir( data );
@@ -26,12 +32,16 @@
}
var startContent = data[0].missing ? '' :
data[0]['*'];
+ var dataFormat = data[0].missing ? 'wikitext' :
data[0].format;
$headerContainer
.find( '#flow-header-content' )
.flow( 'setupEditForm',
'header',
- startContent,
+ {
+ 'content' :
startContent,
+ 'format' : dataFormat
+ },
function( content ) {
var spec = {
'workflowId' :
workflowId,
--
To view, visit https://gerrit.wikimedia.org/r/89611
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1a3bdaed5bf2eacd55462e46a19e7ef4a1e24d89
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Werdna <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits