mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
4e10d5b975
Various checks didn't think a rel attribute could contain multiple values. Mostly they don't, but to play it safe let's adjust the checks. Change-Id: I29823b7c8c65ef6b2ff41ce9a801840000972e9c Depends-On: I33a456351ab025d0c81cfb1a1577d5a2ae9df51a
105 lines
3.1 KiB
JavaScript
105 lines
3.1 KiB
JavaScript
/*!
|
|
* VisualEditor DataModel MWExternalLinkAnnotation class.
|
|
*
|
|
* @copyright 2011-2018 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* DataModel MediaWiki external link annotation.
|
|
*
|
|
* Example HTML sources:
|
|
*
|
|
* <a rel="mw:ExtLink">
|
|
* <a rel="mw:ExtLink/Numbered">
|
|
*
|
|
* Each example is semantically slightly different, but they don't need special treatment (yet).
|
|
*
|
|
* @class
|
|
* @extends ve.dm.LinkAnnotation
|
|
* @constructor
|
|
* @param {Object} element
|
|
*/
|
|
ve.dm.MWExternalLinkAnnotation = function VeDmMWExternalLinkAnnotation() {
|
|
// Parent constructor
|
|
ve.dm.MWExternalLinkAnnotation.super.apply( this, arguments );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.dm.MWExternalLinkAnnotation, ve.dm.LinkAnnotation );
|
|
|
|
/* Static Properties */
|
|
|
|
ve.dm.MWExternalLinkAnnotation.static.name = 'link/mwExternal';
|
|
|
|
ve.dm.MWExternalLinkAnnotation.static.matchFunction = function ( domElement ) {
|
|
var type = domElement.getAttribute( 'rel' ) || domElement.getAttribute( 'typeof' ) || domElement.getAttribute( 'property' );
|
|
// Match explicitly mw:ExtLink (external links), mw:WikiLink/Interwiki
|
|
// (interwiki links), or plain RDFa-less links with an href
|
|
// (e.g. from external paste)
|
|
if ( type ) {
|
|
type = type.split( ' ' );
|
|
return type.indexOf( 'mw:ExtLink' ) !== -1 || type.indexOf( 'mw:WikiLink/Interwiki' ) !== -1;
|
|
}
|
|
return domElement.hasAttribute( 'href' );
|
|
};
|
|
|
|
ve.dm.MWExternalLinkAnnotation.static.toDataElement = function ( domElements, converter ) {
|
|
var dataElement, annotation,
|
|
rel = domElements[ 0 ].getAttribute( 'rel' );
|
|
|
|
// If a plain link is pasted, auto-convert it to the correct type (internal/external)
|
|
if ( !rel ) {
|
|
annotation = ve.ui.MWLinkAction.static.getLinkAnnotation( domElements[ 0 ].getAttribute( 'href' ), converter.getHtmlDocument() );
|
|
return annotation.element;
|
|
}
|
|
|
|
// Parent method
|
|
dataElement = ve.dm.MWExternalLinkAnnotation.super.static.toDataElement.apply( this, arguments );
|
|
|
|
dataElement.attributes.rel = rel;
|
|
return dataElement;
|
|
};
|
|
|
|
ve.dm.MWExternalLinkAnnotation.static.toDomElements = function ( dataElement ) {
|
|
// Parent method
|
|
var domElements = ve.dm.MWExternalLinkAnnotation.super.static.toDomElements.apply( this, arguments );
|
|
|
|
domElements[ 0 ].setAttribute( 'rel', dataElement.attributes.rel || 'mw:ExtLink' );
|
|
return domElements;
|
|
};
|
|
|
|
ve.dm.MWExternalLinkAnnotation.static.describeChange = function ( key, change ) {
|
|
if ( key === 'href' ) {
|
|
return ve.msg( 'visualeditor-changedesc-link-href', change.from, change.to );
|
|
}
|
|
return null;
|
|
};
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* @return {Object}
|
|
*/
|
|
ve.dm.MWExternalLinkAnnotation.prototype.getComparableObject = function () {
|
|
return {
|
|
type: this.getType(),
|
|
href: this.getAttribute( 'href' ),
|
|
rel: this.getAttribute( 'rel' ) || 'mw:ExtLink'
|
|
};
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
ve.dm.MWExternalLinkAnnotation.prototype.getComparableHtmlAttributes = function () {
|
|
// Assume that wikitext never adds meaningful html attributes for comparison purposes,
|
|
// although ideally this should be decided by Parsoid (Bug T95028).
|
|
return {};
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.MWExternalLinkAnnotation );
|