mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-24 16:34:21 +00:00
79c91c3cfc
Change-Id: I03408d2404a99b5bc7795c1c4bf214d4b5fea1e0
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
var ThreadItem = require( './ThreadItem.js' ),
|
|
utils = require( './utils.js' );
|
|
|
|
/**
|
|
* A heading item
|
|
*
|
|
* @class HeadingItem
|
|
* @extends ThreadItem
|
|
* @constructor
|
|
* @param {Object} range
|
|
* @param {number} headingLevel Heading level (1-6)
|
|
* @param {boolean} [placeholderHeading] Item doesn't correspond to a real heading (e.g. 0th section)
|
|
*/
|
|
function HeadingItem( range, headingLevel, placeholderHeading ) {
|
|
// Parent constructor
|
|
HeadingItem.super.call( this, 'heading', 0, range );
|
|
|
|
this.headingLevel = headingLevel;
|
|
this.placeholderHeading = !!placeholderHeading;
|
|
}
|
|
|
|
OO.inheritClass( HeadingItem, ThreadItem );
|
|
|
|
HeadingItem.prototype.getLinkableTitle = function () {
|
|
var headingNode, id,
|
|
title = '';
|
|
// If this comment is in 0th section, there's no section title for the edit summary
|
|
if ( !this.placeholderHeading ) {
|
|
headingNode = utils.getHeadlineNodeAndOffset( this.range.startContainer ).node;
|
|
id = headingNode.getAttribute( 'id' );
|
|
if ( id ) {
|
|
// Replace underscores with spaces to undo Sanitizer::escapeIdInternal().
|
|
// This assumes that $wgFragmentMode is [ 'html5', 'legacy' ] or [ 'html5' ],
|
|
// otherwise the escaped IDs are super garbled and can't be unescaped reliably.
|
|
title = id.replace( /_/g, ' ' );
|
|
}
|
|
// else: Not a real section, probably just HTML markup in wikitext
|
|
}
|
|
return title;
|
|
};
|
|
|
|
module.exports = HeadingItem;
|