Template context: Link to source templates in "Generated from:" list

Bug: T328021
Change-Id: I0960f4033f99813ac761daf69abf437b00e7d3f0
This commit is contained in:
Ed Sanders 2023-02-20 15:33:52 +00:00 committed by Esanders
parent 247d4cf042
commit 30b0f10c27
2 changed files with 51 additions and 0 deletions

View file

@ -68,6 +68,44 @@ ve.ce.MWTransclusionNode.static.getDescription = function ( model ) {
.join( ve.msg( 'comma-separator' ) );
};
/**
* Get a formatted description of the template parts in a transclusion node, excluding raw wikitext
* snippets.
*
* Like #getDescription, but parts generated from templates are linked to
* those templates
*
* @static
* @param {ve.dm.MWTransclusionNode} model
* @return {HTMLElement} DOM node with comma-separated list of template names
*/
ve.ce.MWTransclusionNode.static.getDescriptionDom = function ( model ) {
var nodes = model.getPartsList()
.map( function ( part ) {
if ( part.templatePage ) {
var title = mw.Title.newFromText( part.templatePage );
var link = document.createElement( 'a' );
link.textContent = title.getRelativeText( mw.config.get( 'wgNamespaceIds' ).template );
link.setAttribute( 'href', title.getUrl() );
return link;
}
// Not actually a template, but e.g. a parser function
return part.template ? document.createTextNode( part.template ) : null;
} )
.filter( function ( desc ) {
return desc;
} );
var span = document.createElement( 'span' );
nodes.forEach( function ( node, i ) {
if ( i ) {
span.appendChild( document.createTextNode( ve.msg( 'comma-separator' ) ) );
}
span.appendChild( node );
} );
ve.targetLinksToNewWindow( span );
return span;
};
/**
* Filter rendering to remove auto-generated content and wrappers
*

View file

@ -76,6 +76,19 @@ ve.ui.MWTransclusionContextItem.prototype.getDescription = function () {
);
};
/**
* @inheritdoc
*/
ve.ui.MWTransclusionContextItem.prototype.renderBody = function () {
var nodeClass = ve.ce.nodeFactory.lookup( this.model.constructor.static.name );
// eslint-disable-next-line no-jquery/no-append-html
this.$body.append( ve.htmlMsg(
'visualeditor-dialog-transclusion-contextitem-description',
nodeClass.static.getDescriptionDom( this.model ),
this.model.getPartsList().length
) );
};
/**
* @param {string} [source] Source for tracking in {@see ve.ui.WindowAction.open}
*/