Show redirect meta items in visual diff

Bug: T161290
Change-Id: Icf68f6d085ab2de802350df0d29208f0653ceb66
This commit is contained in:
Ed Sanders 2022-01-20 00:50:10 +00:00 committed by Bartosz Dziewoński
parent 860d9ae926
commit db5f13fc93
2 changed files with 40 additions and 13 deletions

View file

@ -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. */

View file

@ -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 );
} );