Merge "Visual diffs in source mode section edits"

This commit is contained in:
jenkins-bot 2018-04-02 16:05:34 +00:00 committed by Gerrit Code Review
commit 45afe665c1
4 changed files with 25 additions and 21 deletions

View file

@ -215,7 +215,7 @@ ve.init.mw.ArticleTarget.static.documentCommands = ve.init.mw.ArticleTarget.supe
/**
* @inheritdoc
*/
ve.init.mw.ArticleTarget.static.parseDocument = function ( documentString, mode ) {
ve.init.mw.ArticleTarget.static.parseDocument = function ( documentString, mode, section ) {
// Add trailing linebreak to non-empty wikitext documents for consistency
// with old editor and usability. Will be stripped on save. T156609
if ( mode === 'source' && documentString ) {
@ -223,7 +223,7 @@ ve.init.mw.ArticleTarget.static.parseDocument = function ( documentString, mode
}
// Parent method
return ve.init.mw.ArticleTarget.super.static.parseDocument.call( this, documentString, mode );
return ve.init.mw.ArticleTarget.super.static.parseDocument.call( this, documentString, mode, section );
};
/* Methods */
@ -1153,7 +1153,7 @@ ve.init.mw.ArticleTarget.prototype.getVisualDiffGeneratorPromise = function () {
// 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 );
target.originalDmDocPromise = mw.libs.ve.diffLoader.fetchRevision( target.revid, target.pageName, undefined, target.section !== null ? target.section : undefined );
}
}

View file

@ -22,15 +22,16 @@
* Get a ve.dm.Document model from a Parsoid response
*
* @param {Object} response Parsoid response from the VisualEditor API
* @param {number} [section] Section
* @return {ve.dm.Document|null} Document, or null if an invalid response
*/
getModelFromResponse: function ( response ) {
getModelFromResponse: function ( response, section ) {
var doc,
targetClass = ve.init.mw.DesktopArticleTarget,
metadataIdRegExp = ve.init.platform.getMetadataIdRegExp(),
data = response ? ( response.visualeditor || response.visualeditoredit ) : null;
if ( data && typeof data.content === 'string' ) {
doc = targetClass.static.parseDocument( data.content, 'visual' );
doc = targetClass.static.parseDocument( data.content, 'visual', section );
// Strip RESTBase IDs
Array.prototype.forEach.call( doc.querySelectorAll( '[id^="mw"]' ), function ( element ) {
if ( element.id.match( metadataIdRegExp ) ) {
@ -48,22 +49,23 @@
* @param {number} revId Revision ID
* @param {string} [pageName] Page name, defaults to wgRelevantPageName
* @param {jQuery.Promise} [parseDocumentModulePromise] Promise which resolves when Target#parseDocument is available
* @param {number} [section] Section
* @return {jQuery.Promise} Promise which resolves with a document model
*/
fetchRevision: function ( revId, pageName, parseDocumentModulePromise ) {
fetchRevision: function ( revId, pageName, parseDocumentModulePromise, section ) {
var cacheKey = revId + ( section !== undefined ? '/' + section : '' );
parseDocumentModulePromise = parseDocumentModulePromise || $.Deferred().resolve().promise();
pageName = pageName || mw.config.get( 'wgRelevantPageName' );
revCache[ pageName ] = revCache[ pageName ] || {};
revCache[ pageName ][ revId ] =
revCache[ pageName ][ revId ] ||
revCache[ cacheKey ] = revCache[ cacheKey ] ||
mw.libs.ve.targetLoader.requestParsoidData( pageName, { oldId: revId, targetName: 'diff' } ).then( function ( response ) {
return parseDocumentModulePromise.then( function () {
return mw.libs.ve.diffLoader.getModelFromResponse( response );
return mw.libs.ve.diffLoader.getModelFromResponse( response, section );
} );
} );
return revCache[ pageName ][ revId ];
return revCache[ cacheKey ];
},
/**

View file

@ -187,15 +187,23 @@ ve.init.mw.Target.prototype.createModelFromDom = function () {
/**
* @inheritdoc
* @param {number} [section] Section
*/
ve.init.mw.Target.static.parseDocument = function ( documentString, mode ) {
var doc;
ve.init.mw.Target.static.parseDocument = function ( documentString, mode, section ) {
var doc, sectionNode;
if ( mode === 'source' ) {
// Parent method
doc = ve.init.mw.Target.super.static.parseDocument.call( this, documentString, mode );
} else {
// Parsoid documents are XHTML so we can use parseXhtml which fixed some IE issues.
doc = ve.parseXhtml( documentString );
if ( section !== undefined ) {
sectionNode = doc.body.querySelector( '[data-mw-section-id="' + section + '"]' );
doc.body.innerHTML = '';
if ( sectionNode ) {
doc.body.appendChild( sectionNode );
}
}
// Strip Parsoid sections
ve.unwrapParsoidSections( doc.body );
// Strip legacy IDs, for example in section headings

View file

@ -782,10 +782,7 @@ ve.ui.MWSaveDialog.prototype.positionDiffElement = function () {
ve.ui.MWSaveDialog.prototype.getSetupProcess = function ( data ) {
return ve.ui.MWSaveDialog.super.prototype.getSetupProcess.call( this, data )
.next( function () {
var surfaceMode = ve.init.target.getSurface().getMode(),
section = ve.init.target.section,
// Can't do visual diffs for source mode section edits yet
canReviewVisual = !( surfaceMode === 'source' && section !== null );
var surfaceMode = ve.init.target.getSurface().getMode();
this.canReview = !!data.canReview;
this.canPreview = !!data.canPreview;
@ -802,14 +799,11 @@ ve.ui.MWSaveDialog.prototype.getSetupProcess = function ( data ) {
}
}
this.reviewModeButtonSelect.findItemFromData( 'visual' ).setDisabled( !canReviewVisual );
// Config values used here:
// * visualeditor-diffmode-visual
// * visualeditor-diffmode-source
this.reviewModeButtonSelect.selectItemByData(
!canReviewVisual ? 'source' :
ve.userConfig( 'visualeditor-diffmode-' + surfaceMode ) || surfaceMode
ve.userConfig( 'visualeditor-diffmode-' + surfaceMode ) || surfaceMode
);
// Old messages should not persist