2020-11-05 16:07:56 +00:00
|
|
|
var ThreadItem = require( './ThreadItem.js' ),
|
|
|
|
utils = require( './utils.js' );
|
2020-05-22 16:26:05 +00:00
|
|
|
|
2020-06-25 12:23:17 +00:00
|
|
|
/**
|
|
|
|
* A heading item
|
|
|
|
*
|
|
|
|
* @class HeadingItem
|
2020-08-26 22:46:34 +00:00
|
|
|
* @extends ThreadItem
|
2020-06-25 12:23:17 +00:00
|
|
|
* @constructor
|
|
|
|
* @param {Object} range
|
2020-10-01 19:36:11 +00:00
|
|
|
* @param {number} headingLevel Heading level (1-6)
|
2020-06-25 12:23:17 +00:00
|
|
|
* @param {boolean} [placeholderHeading] Item doesn't correspond to a real heading (e.g. 0th section)
|
|
|
|
*/
|
2020-10-01 19:36:11 +00:00
|
|
|
function HeadingItem( range, headingLevel, placeholderHeading ) {
|
2020-05-22 16:26:05 +00:00
|
|
|
// Parent constructor
|
|
|
|
HeadingItem.super.call( this, 'heading', 0, range );
|
|
|
|
|
2020-10-01 19:36:11 +00:00
|
|
|
this.headingLevel = headingLevel;
|
2020-10-07 14:45:19 +00:00
|
|
|
this.placeholderHeading = !!placeholderHeading;
|
2020-05-22 16:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OO.inheritClass( HeadingItem, ThreadItem );
|
|
|
|
|
2020-11-05 16:07:56 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2020-08-29 12:00:51 +00:00
|
|
|
/**
|
|
|
|
* @return {HeadingItem} Closest ancestor which is a HeadingItem
|
|
|
|
*/
|
|
|
|
HeadingItem.prototype.getHeading = function () {
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2020-05-22 16:26:05 +00:00
|
|
|
module.exports = HeadingItem;
|