mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-20 10:11:12 +00:00
25019d7f55
Our encoding for the hrefs like "./Foo" that we send to Parsoid differed slightly from how Parsoid outputs them, so to avoid dirty diffs, we had to store the original ones we received from Parsoid and send them back if they were unchanged. Change the encoding to match Parsoid's exactly (by referring to the Parsoid source code), and then remove 'rawTitle'/'origTitle'. On a historical note, 'rawTitle'/'origTitle' were originally added to fix other issues with links, which I hope are long behind us: *bb45d984ca
(T145978) *fda2e6c1b5
(T44140) Follow-up to362df66b47
, which removed some other old stuff from the handling of Parsoid links. Bug: T325766 Change-Id: I0ad0a655380eb2fb29b5ac01e2e399ac550ce34a
69 lines
2 KiB
JavaScript
69 lines
2 KiB
JavaScript
/*!
|
|
* VisualEditor DataModel MWCategoryMetaItem class.
|
|
*
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* DataModel category meta item.
|
|
*
|
|
* @class
|
|
* @extends ve.dm.MetaItem
|
|
* @constructor
|
|
* @param {Object} element Reference to element in meta-linmod
|
|
*/
|
|
ve.dm.MWCategoryMetaItem = function VeDmMWCategoryMetaItem() {
|
|
// Parent constructor
|
|
ve.dm.MWCategoryMetaItem.super.apply( this, arguments );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.dm.MWCategoryMetaItem, ve.dm.MetaItem );
|
|
|
|
/* Static Properties */
|
|
|
|
ve.dm.MWCategoryMetaItem.static.name = 'mwCategory';
|
|
|
|
ve.dm.MWCategoryMetaItem.static.group = 'mwCategory';
|
|
|
|
ve.dm.MWCategoryMetaItem.static.matchTagNames = [ 'link' ];
|
|
|
|
ve.dm.MWCategoryMetaItem.static.matchRdfaTypes = [ 'mw:PageProp/Category' ];
|
|
|
|
ve.dm.MWCategoryMetaItem.static.toDataElement = function ( domElements ) {
|
|
// Parsoid: LinkHandlerUtils::serializeAsWikiLink
|
|
var href = domElements[ 0 ].getAttribute( 'href' ),
|
|
titleAndFragment = href.match( /^(.*?)(?:#(.*))?\s*$/ );
|
|
return {
|
|
type: this.name,
|
|
attributes: {
|
|
category: mw.libs.ve.parseParsoidResourceName( titleAndFragment[ 1 ] ).title,
|
|
sortkey: titleAndFragment[ 2 ] ? decodeURIComponent( titleAndFragment[ 2 ] ) : ''
|
|
}
|
|
};
|
|
};
|
|
|
|
ve.dm.MWCategoryMetaItem.static.toDomElements = function ( dataElement, doc ) {
|
|
var domElement = doc.createElement( 'link' ),
|
|
category = dataElement.attributes.category || '',
|
|
sortkey = dataElement.attributes.sortkey || '';
|
|
domElement.setAttribute( 'rel', 'mw:PageProp/Category' );
|
|
|
|
// Parsoid: WikiLinkHandler::renderCategory
|
|
var href = mw.libs.ve.encodeParsoidResourceName( category );
|
|
if ( sortkey !== '' ) {
|
|
href += '#' + sortkey.replace( /[%? [\]#|<>]/g, function ( match ) {
|
|
return encodeURIComponent( match );
|
|
} );
|
|
}
|
|
|
|
domElement.setAttribute( 'href', href );
|
|
return [ domElement ];
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.MWCategoryMetaItem );
|