2024-05-24 12:31:30 +00:00
|
|
|
const ThreadItem = require( './ThreadItem.js' );
|
2022-06-06 17:35:43 +00:00
|
|
|
// Placeholder headings must have a level higher than real headings (1-6)
|
2024-05-24 12:31:30 +00:00
|
|
|
const PLACEHOLDER_HEADING_LEVEL = 99;
|
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
|
2022-06-06 17:35:43 +00:00
|
|
|
* @param {number|null} headingLevel Heading level (1-6). Use null for a placeholder heading.
|
2020-06-25 12:23:17 +00:00
|
|
|
*/
|
2022-06-06 17:35:43 +00:00
|
|
|
function HeadingItem( range, headingLevel ) {
|
2020-05-22 16:26:05 +00:00
|
|
|
// Parent constructor
|
|
|
|
HeadingItem.super.call( this, 'heading', 0, range );
|
|
|
|
|
2022-06-06 17:35:43 +00:00
|
|
|
this.placeholderHeading = headingLevel === null;
|
|
|
|
this.headingLevel = this.placeholderHeading ? PLACEHOLDER_HEADING_LEVEL : headingLevel;
|
2020-05-22 16:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OO.inheritClass( HeadingItem, ThreadItem );
|
|
|
|
|
2020-11-05 16:07:56 +00:00
|
|
|
HeadingItem.prototype.getLinkableTitle = function () {
|
2024-05-24 12:20:50 +00:00
|
|
|
let title = '';
|
2020-11-05 16:07:56 +00:00
|
|
|
// If this comment is in 0th section, there's no section title for the edit summary
|
|
|
|
if ( !this.placeholderHeading ) {
|
2024-05-24 12:20:50 +00:00
|
|
|
const headline = this.range.startContainer;
|
|
|
|
const id = headline.getAttribute( 'id' );
|
2020-11-05 16:07:56 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2021-12-20 16:30:07 +00:00
|
|
|
/**
|
|
|
|
* Check whether this heading can be used for topic subscriptions.
|
|
|
|
*
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
HeadingItem.prototype.isSubscribable = function () {
|
|
|
|
return (
|
|
|
|
// Placeholder headings have nothing to attach the button to.
|
|
|
|
!this.placeholderHeading &&
|
|
|
|
// We only allow subscribing to level 2 headings, because the user interface for sub-headings
|
|
|
|
// would be difficult to present.
|
|
|
|
this.headingLevel === 2 &&
|
|
|
|
// Check if the name corresponds to a section that contain no comments (only sub-sections).
|
|
|
|
// They can't be distinguished from each other, so disallow subscribing.
|
|
|
|
this.name !== 'h-'
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-05-22 16:26:05 +00:00
|
|
|
module.exports = HeadingItem;
|