diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js index c9081044b3..a4aecf7bd5 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js @@ -698,7 +698,12 @@ ve.init.mw.DesktopArticleTarget.prototype.loadFail = function ( errorText, error if ( confirmPromptMessage && confirm( confirmPromptMessage ) ) { this.load(); + } else if ( !$( '#wpTextbox1' ).length ) { + // TODO: Some sort of progress bar? + this.switchToWikitextEditor( true, false ); } else { + // If we're switching from the wikitext editor, just deactivate + // don't try to switch back to it fully, that'd discard changes. this.deactivate( true ); } }; diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopWikitextArticleTarget.js b/modules/ve-mw/init/targets/ve.init.mw.DesktopWikitextArticleTarget.js index 4cdfad26f4..6d5c855888 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.DesktopWikitextArticleTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopWikitextArticleTarget.js @@ -44,21 +44,30 @@ ve.init.mw.DesktopWikitextArticleTarget.prototype.switchToWikitextEditor = funct var dataPromise, target = this; - this.serialize( this.getDocToSave() ); - dataPromise = this.serializing.then( function ( response ) { - // HACK - var data = response.visualeditor; - data.etag = target.etag; - data.fromEditedState = modified; - data.notices = target.remoteNotices; - data.protectedClasses = target.protectedClasses; - data.basetimestamp = target.baseTimeStamp; - data.starttimestamp = target.startTimeStamp; - data.oldid = target.revid; - return response; - } ); + if ( discardChanges ) { + dataPromise = mw.libs.ve.targetLoader.requestPageData( + 'source', + this.pageName, + this.requestedRevId, + this.constructor.name + ).then( + function ( response ) { return response; }, + function () { + // TODO: Some sort of progress bar? + ve.init.mw.DesktopWikitextArticleTarget.super.prototype.switchToWikitextEditor.call( + target, + discardChanges, + modified + ); + // Keep everything else waiting so our error handler can do its business + return $.Deferred().promise(); + } + ); + } else { + this.serialize( this.getDocToSave() ); + dataPromise = this.serializing; + } this.setMode( 'source' ); - this.reloadSurface( dataPromise ); };