From db5f13fc935f640a0ac8e2563eed25fd501cdec2 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Thu, 20 Jan 2022 00:50:10 +0000 Subject: [PATCH] Show redirect meta items in visual diff Bug: T161290 Change-Id: Icf68f6d085ab2de802350df0d29208f0653ceb66 --- .../dm/metaitems/ve.dm.MWFlaggedMetaItem.js | 18 ++++++---- .../dm/metaitems/ve.dm.MWRedirectMetaItem.js | 35 +++++++++++++++---- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/modules/ve-mw/dm/metaitems/ve.dm.MWFlaggedMetaItem.js b/modules/ve-mw/dm/metaitems/ve.dm.MWFlaggedMetaItem.js index 2d7f85c59d..e87134564e 100644 --- a/modules/ve-mw/dm/metaitems/ve.dm.MWFlaggedMetaItem.js +++ b/modules/ve-mw/dm/metaitems/ve.dm.MWFlaggedMetaItem.js @@ -40,18 +40,22 @@ ve.dm.MWFlaggedMetaItem.static.toDataElement = function ( domElements ) { return { type: this.name, attributes: { property: property } }; }; -ve.dm.MWFlaggedMetaItem.static.toDomElements = function ( dataElement, doc ) { - var meta = doc.createElement( 'meta' ), - property = OO.getProp( dataElement, 'attributes', 'property' ); +ve.dm.MWFlaggedMetaItem.static.toDomElements = function ( dataElement, doc, converter ) { + var domElement; + var property = OO.getProp( dataElement, 'attributes', 'property' ); if ( !property || this.matchRdfaTypes.indexOf( property ) === -1 ) { // Fallback to first item if somehow unset property = this.matchRdfaTypes[ 0 ]; } - - meta.setAttribute( 'property', property ); - - return [ meta ]; + if ( converter.isForPreview() ) { + domElement = doc.createElement( 'div' ); + domElement.innerText = property; + } else { + domElement = doc.createElement( 'meta' ); + domElement.setAttribute( 'property', property ); + } + return [ domElement ]; }; /* No registration, as this is not a valid meta item, just an abstract class. */ diff --git a/modules/ve-mw/dm/metaitems/ve.dm.MWRedirectMetaItem.js b/modules/ve-mw/dm/metaitems/ve.dm.MWRedirectMetaItem.js index 3d5d1a8bb7..1d1aa80f0d 100644 --- a/modules/ve-mw/dm/metaitems/ve.dm.MWRedirectMetaItem.js +++ b/modules/ve-mw/dm/metaitems/ve.dm.MWRedirectMetaItem.js @@ -39,12 +39,19 @@ ve.dm.MWRedirectMetaItem.static.toDataElement = function ( domElements, converte return linkData; }; -ve.dm.MWRedirectMetaItem.static.toDomElements = function ( dataElement, doc ) { - var meta = doc.createElement( 'link' ); - meta.setAttribute( 'rel', 'mw:PageProp/redirect' ); - // HACK piggy-back on MWInternalLinkAnnotation's logic - meta.setAttribute( 'href', ve.dm.MWInternalLinkAnnotation.static.getHref( dataElement ) ); - return [ meta ]; +ve.dm.MWRedirectMetaItem.static.toDomElements = function ( dataElement, doc, converter ) { + var domElement; + var href = ve.dm.MWInternalLinkAnnotation.static.getHref( dataElement ); + if ( converter.isForPreview() ) { + // TODO: Move this a DM utility that doesn't use jQuery internally + domElement = ve.init.mw.ArticleTarget.static.buildRedirectMsg( dataElement.attributes.title )[ 0 ]; + } else { + domElement = doc.createElement( 'link' ); + domElement.setAttribute( 'rel', 'mw:PageProp/redirect' ); + // HACK piggy-back on MWInternalLinkAnnotation's logic + domElement.setAttribute( 'href', href ); + } + return [ domElement ]; }; ve.dm.MWRedirectMetaItem.static.describeChange = function ( key, change ) { @@ -57,3 +64,19 @@ ve.dm.MWRedirectMetaItem.static.describeChange = function ( key, change ) { /* Registration */ ve.dm.modelRegistry.register( ve.dm.MWRedirectMetaItem ); + +ve.ui.metaListDiffRegistry.register( 'mwRedirect', function ( diffElement, diffQueue, documentNode, documentSpacerNode ) { + diffQueue = diffElement.processQueue( diffQueue ); + + if ( !diffQueue.length ) { + return; + } + + var redirects = document.createElement( 'div' ); + diffElement.renderQueue( + diffQueue, + redirects, + documentSpacerNode + ); + documentNode.insertBefore( redirects, documentNode.firstChild ); +} );