mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 14:33:59 +00:00
Template context: Link to source templates in "Generated from:" list
Bug: T328021 Change-Id: I0960f4033f99813ac761daf69abf437b00e7d3f0
This commit is contained in:
parent
247d4cf042
commit
30b0f10c27
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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}
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue