TemplateStyles support

MWTransclusionNode will preserve TemplateData <style> in its generated content.

Disable TemplateStyles stylesheets in the original page content, and reenable
them when the surface deactivates.

Remaining TODO: if multiple copies of a template with deduplicated styles are
on the page, and the one containing the actual <style> is removed, all will
lose their styling.

Bug: T197563
Change-Id: Ibd8939eef7d8eb532719f4ee0ce200600449ef81
Depends-On: Ia9f2afcdba5456238e3ef444c202c9b0c78838bf
This commit is contained in:
David Lynch 2018-08-20 12:32:43 -05:00 committed by Esanders
parent 2ee76a4df4
commit 26f6429702
2 changed files with 16 additions and 1 deletions

View file

@ -207,6 +207,15 @@ ve.ce.MWTransclusionNode.prototype.getRenderedDomElements = function () {
return elements;
};
/**
* @inheritdoc
*/
ve.ce.MWTransclusionNode.prototype.filterRenderedDomElements = function ( domElements ) {
// We want to remove all styles and links which aren't from TemplateStyles.
var selector = 'style:not([data-mw-deduplicate^="TemplateStyles:"]), link:not([rel="mw-deduplicated-inline-style"][href^="mw-data:TemplateStyles:"])';
return $( domElements ).find( selector ).addBack( selector ).remove().end().end().toArray();
};
/**
* Handle an unsuccessful response from the parser for the wikitext fragment.
*

View file

@ -670,7 +670,9 @@ ve.init.mw.DesktopArticleTarget.prototype.teardown = function ( trackMechanism )
$( 'html' ).removeClass( 've-deactivating' );
// Move original content back out of the target
target.$element.parent().append( target.$originalContent.children() );
target.$element.parent().append( target.$originalContent.children() )
// Restore TemplateStyles within it
.find( 'style[data-mw-deduplicate^="TemplateStyles:"]' ).prop( 'disabled', false );
$( '.ve-init-mw-desktopArticleTarget-uneditableContent' )
.removeClass( 've-init-mw-desktopArticleTarget-uneditableContent' );
@ -1212,6 +1214,10 @@ ve.init.mw.DesktopArticleTarget.prototype.transformPage = function () {
// Move all native content inside the target
// Exclude notification area to work around T143837
this.$originalContent.append( this.$element.siblings().not( '.mw-notification-area' ) );
// Disable TemplateStyles in originalContent
this.$originalContent.find( 'style[data-mw-deduplicate^="TemplateStyles:"]' ).prop( 'disabled', true );
this.$originalCategories = $( '#catlinks' ).clone( true );
// Mark every non-direct ancestor between editableContent and the container as uneditable