mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-28 16:20:52 +00:00
Merge "Preserve data when switching from NWE to VE"
This commit is contained in:
commit
572e7375d7
|
@ -75,11 +75,28 @@ ve.init.mw.DesktopWikitextArticleTarget.prototype.switchToWikitextEditor = funct
|
|||
this.reloadSurface( dataPromise );
|
||||
};
|
||||
|
||||
/**
|
||||
* Switch to the visual editor.
|
||||
*/
|
||||
ve.init.mw.DesktopWikitextArticleTarget.prototype.switchToVisualEditor = function () {
|
||||
var dataPromise;
|
||||
|
||||
this.setMode( 'visual' );
|
||||
this.reloadSurface();
|
||||
|
||||
dataPromise = mw.libs.ve.targetLoader.requestParsoidData(
|
||||
this.pageName,
|
||||
this.requestedRevId,
|
||||
this.constructor.name,
|
||||
this.edited,
|
||||
this.getWikitextFromDocument( this.getSurface().getDom() )
|
||||
);
|
||||
|
||||
this.reloadSurface( dataPromise );
|
||||
};
|
||||
|
||||
/**
|
||||
* Reload the target surface in the new editor mode
|
||||
*/
|
||||
ve.init.mw.DesktopWikitextArticleTarget.prototype.reloadSurface = function ( dataPromise ) {
|
||||
var target = this;
|
||||
// Create progress - will be discarded when surface is destroyed.
|
||||
|
@ -228,7 +245,7 @@ ve.init.mw.DesktopWikitextArticleTarget.prototype.tryWithPreparedCacheKey = func
|
|||
if ( this.mode === 'source' ) {
|
||||
data = ve.extendObject( {}, options, { format: 'json' } );
|
||||
|
||||
data.wikitext = Array.prototype.map.call( doc.body.children, function ( p ) { return p.innerText; } ).join( '\n' );
|
||||
data.wikitext = this.getWikitextFromDocument( doc );
|
||||
|
||||
return new mw.Api().post( data, { contentType: 'multipart/form-data' } );
|
||||
} else {
|
||||
|
@ -237,6 +254,16 @@ ve.init.mw.DesktopWikitextArticleTarget.prototype.tryWithPreparedCacheKey = func
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get wikitext for the whole document
|
||||
*
|
||||
* @param {ve.dm.Document} doc Document
|
||||
* @return {string} Wikitext
|
||||
*/
|
||||
ve.init.mw.DesktopWikitextArticleTarget.prototype.getWikitextFromDocument = function ( doc ) {
|
||||
return Array.prototype.map.call( doc.body.children, function ( p ) { return p.innerText; } ).join( '\n' );
|
||||
};
|
||||
|
||||
/* Registration */
|
||||
|
||||
ve.init.mw.targetFactory.register( ve.init.mw.DesktopWikitextArticleTarget );
|
||||
|
|
|
@ -113,7 +113,7 @@
|
|||
}
|
||||
},
|
||||
|
||||
requestParsoidData: function ( pageName, oldid, targetName, modified ) {
|
||||
requestParsoidData: function ( pageName, oldid, targetName, modified, wikitext ) {
|
||||
var start, apiXhr, restbaseXhr, apiPromise, restbasePromise, dataPromise, pageHtmlUrl,
|
||||
switched = false,
|
||||
fromEditedState = false,
|
||||
|
@ -151,7 +151,7 @@
|
|||
ve.track( 'trace.restbaseLoad.enter' );
|
||||
if (
|
||||
conf.fullRestbaseUrl &&
|
||||
$( '#wpTextbox1' ).textSelection( 'getContents' ) &&
|
||||
( wikitext || ( wikitext = $( '#wpTextbox1' ).textSelection( 'getContents' ) ) ) &&
|
||||
!$( '[name=wpSection]' ).val()
|
||||
) {
|
||||
switched = true;
|
||||
|
@ -166,7 +166,7 @@
|
|||
data: {
|
||||
title: pageName,
|
||||
oldid: oldid,
|
||||
wikitext: $( '#wpTextbox1' ).textSelection( 'getContents' ),
|
||||
wikitext: wikitext,
|
||||
stash: 'true'
|
||||
},
|
||||
// Should be synchronised with ApiVisualEditor.php
|
||||
|
|
Loading…
Reference in a new issue