Show visual diffs in wikitext mode

Bug: T170371
Change-Id: I8fd9ed4f804444ec486c4df72125cdeb04da0d5f
This commit is contained in:
Ed Sanders 2017-07-17 17:38:32 +01:00
parent 4a60a3e147
commit 581847acb3
2 changed files with 51 additions and 51 deletions

View file

@ -32,7 +32,7 @@ ve.init.mw.ArticleTarget = function VeInitMwArticleTarget( config ) {
this.saveDeferred = null;
this.captcha = null;
this.docToSave = null;
this.originalDmDoc = null;
this.originalDmDocPromise = null;
this.originalHtml = null;
this.toolbarSaveButton = null;
this.pageExists = mw.config.get( 'wgRelevantArticleId', 0 ) !== 0;
@ -1047,43 +1047,45 @@ ve.init.mw.ArticleTarget.prototype.onSaveDialogReviewComplete = function ( wikit
/**
* Get a visual diff object for the current document state
*
* @return {jQuery.Promise|null} Promise resolving with a generator for a ve.dm.VisualDiff visual diff, or null if not known
* @return {jQuery.Promise} Promise resolving with a generator for a ve.dm.VisualDiff visual diff
*/
ve.init.mw.ArticleTarget.prototype.getVisualDiffGeneratorPromise = function () {
var deferred, dmDoc,
target = this;
var target = this;
if ( this.getSurface().getMode() === 'source' ) {
return null;
}
deferred = $.Deferred();
dmDoc = this.getSurface().getModel().getDocument();
return mw.loader.using( 'ext.visualEditor.diffLoader' ).then( function () {
var newRevPromise;
if ( !this.originalDmDoc ) {
if ( !this.fromEditedState ) {
this.originalDmDoc = this.constructor.static.createModelFromDom( this.doc, 'visual' );
} else {
mw.libs.ve.targetLoader.requestParsoidData( this.pageName, {
oldId: this.revid,
targetName: 'diff'
} ).then( function ( response ) {
var doc, data = response ? ( response.visualeditor || response.visualeditoredit ) : null;
if ( data && typeof data.content === 'string' ) {
doc = target.constructor.static.parseDocument( data.content, 'visual' );
target.originalDmDoc = target.constructor.static.createModelFromDom( doc, 'visual' );
deferred.resolve( function () {
return new ve.dm.VisualDiff( target.originalDmDoc, dmDoc );
} );
if ( !target.originalDmDocPromise ) {
if ( !target.fromEditedState && target.getSurface().getMode() === 'visual' ) {
// If this.doc was loaded from an un-edited state and in visual mode,
// then just parse it to get originalDmDoc, otherwise we need to
// re-fetch the HTML
target.originalDmDocPromise = $.Deferred().resolve( target.constructor.static.createModelFromDom( target.doc, 'visual' ) ).promise();
} else {
target.originalDmDocPromise = mw.libs.ve.diffLoader.fetchRevision( target.revid, target.pageName );
}
}
if ( target.getSurface().getMode() === 'source' ) {
newRevPromise = mw.libs.ve.targetLoader.requestParsoidData(
mw.config.get( 'wgRelevantPageName' ),
{
oldId: target.revid,
targetName: 'diff',
modified: true,
wikitext: ve.init.target.getSurface().getDom()
}
).then( mw.libs.ve.diffLoader.getModelFromResponse );
return mw.libs.ve.diffLoader.getVisualDiffGeneratorPromise( target.originalDmDocPromise, newRevPromise );
} else {
return target.originalDmDocPromise.then( function ( originalDmDoc ) {
return function () {
return new ve.dm.VisualDiff( originalDmDoc, target.getSurface().getModel().getDocument() );
};
} );
}
}
if ( this.originalDmDoc ) {
deferred.resolve( function () {
return new ve.dm.VisualDiff( target.originalDmDoc, dmDoc );
} );
}
return deferred.promise();
} );
};
/**
@ -1183,7 +1185,7 @@ ve.init.mw.ArticleTarget.prototype.clearState = function () {
this.startTimeStamp = null;
this.checkboxes = null;
this.doc = null;
this.originalDmDoc = null;
this.originalDmDocPromise = null;
this.originalHtml = null;
this.toolbarSaveButton = null;
this.section = null;

View file

@ -134,7 +134,7 @@ ve.ui.MWSaveDialog.static.actions = [
* Set review content and show review panel.
*
* @param {jQuery.Promise} wikitextDiffPromise Wikitext diff HTML promise
* @param {jQuery.Promise} [visualDiffGeneratorPromise] Visual diff promise
* @param {jQuery.Promise} visualDiffGeneratorPromise Visual diff promise
* @param {HTMLDocument} [baseDoc] Base document against which to normalise links when rendering visualDiff
*/
ve.ui.MWSaveDialog.prototype.setDiffAndReview = function ( wikitextDiffPromise, visualDiffGeneratorPromise, baseDoc ) {
@ -142,26 +142,24 @@ ve.ui.MWSaveDialog.prototype.setDiffAndReview = function ( wikitextDiffPromise,
this.clearDiff();
function createDiffElement( visualDiff ) {
var diffElement = new ve.ui.DiffElement( visualDiff );
diffElement.$document.addClass( 'mw-body-content' );
// Run styles so links render with their appropriate classes
ve.init.platform.linkCache.styleParsoidElements( diffElement.$document, baseDoc );
return diffElement;
}
// Visual diff
this.$reviewVisualDiff.append( new OO.ui.ProgressBarWidget().$element );
if ( visualDiffGeneratorPromise ) {
// Don't generate the DiffElement until the tab is switched to
this.getDiffElementPromise = function () {
return visualDiffGeneratorPromise.then( function ( visualDiff ) {
var diffElement = new ve.ui.DiffElement( visualDiff() );
diffElement.$document.addClass( 'mw-body-content' );
// Run styles so links render with their appropriate classes
ve.init.platform.linkCache.styleParsoidElements( diffElement.$document, baseDoc );
return diffElement;
} );
};
this.baseDoc = baseDoc;
this.reviewModeButtonSelect.getItemFromData( 'visual' ).setDisabled( false );
} else {
// TODO: Support visual diffs in source mode (epic)
this.reviewModeButtonSelect.getItemFromData( 'visual' ).setDisabled( true );
this.reviewModeButtonSelect.selectItemByData( 'source' );
}
// Don't generate the DiffElement until the tab is switched to
this.getDiffElementPromise = function () {
return visualDiffGeneratorPromise.then( function ( visualDiffGenerator ) {
return createDiffElement( visualDiffGenerator() );
} );
};
this.baseDoc = baseDoc;
// Wikitext diff
this.$reviewWikitextDiff.append( new OO.ui.ProgressBarWidget().$element );