Merge "Fix a few risky places for a multi-valued rel attributes"

This commit is contained in:
jenkins-bot 2022-08-25 00:13:22 +00:00 committed by Gerrit Code Review
commit 012458f4ca
5 changed files with 7 additions and 3 deletions

View file

@ -20,7 +20,9 @@ ve.ce.MWExternalLinkAnnotation = function VeCeMWExternalLinkAnnotation( model )
ve.ce.MWExternalLinkAnnotation.super.apply( this, arguments );
// DOM changes
if ( model.getAttribute( 'rel' ) === 'mw:WikiLink/Interwiki' ) {
var rel = model.getAttribute( 'rel' ) || '';
var relValues = rel.split( /\s+/ );
if ( relValues.indexOf( 'mw:WikiLink/Interwiki' ) >= 0 ) {
this.$anchor.addClass( 'extiw' );
} else {
this.$anchor.addClass( 'external' );

View file

@ -210,7 +210,7 @@ ve.ce.MWTransclusionNode.prototype.getRenderedDomElements = function () {
*/
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:"])';
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();
};

View file

@ -75,6 +75,7 @@ ve.dm.MWExternalLinkAnnotation.static.toDomElements = function ( dataElement, do
domElements[ 0 ].setAttribute( 'class', 'external' );
}
// we just created that link so the 'rel' attribute should be safe
domElements[ 0 ].setAttribute( 'rel', dataElement.attributes.rel || 'mw:ExtLink' );
return domElements;
};

View file

@ -108,6 +108,7 @@ ve.dm.MWInternalLinkAnnotation.static.newFromTitle = function ( title, rawTitle
ve.dm.MWInternalLinkAnnotation.static.toDomElements = function () {
var parentResult = ve.dm.LinkAnnotation.static.toDomElements.apply( this, arguments );
// we just created that link so the 'rel' attribute should be safe
parentResult[ 0 ].setAttribute( 'rel', 'mw:WikiLink' );
return parentResult;
};

View file

@ -100,7 +100,7 @@ mw.libs.ve.stripRestbaseIds = function ( doc ) {
* @param {HTMLElement} element Parent element, e.g. document body
*/
mw.libs.ve.reduplicateStyles = function ( element ) {
Array.prototype.forEach.call( element.querySelectorAll( 'link[rel="mw-deduplicated-inline-style"]' ), function ( link ) {
Array.prototype.forEach.call( element.querySelectorAll( 'link[rel~="mw-deduplicated-inline-style"]' ), function ( link ) {
var href = link.getAttribute( 'href' );
if ( !href || href.slice( 0, 'mw-data:'.length ) !== 'mw-data:' ) {
return;