mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-15 03:44:02 +00:00
8c6fadeb65
This matches the PHP implementation and was only used in one place (when fetching authors in new topic tool). Change-Id: I9d9e774616112e8dc6ab4919846e3abecc24553d
60 lines
1.9 KiB
JavaScript
60 lines
1.9 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 title = '';
|
|
// If this comment is in 0th section, there's no section title for the edit summary
|
|
if ( !this.placeholderHeading ) {
|
|
var headingNode = utils.getHeadlineNodeAndOffset( this.range.startContainer ).node;
|
|
var 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;
|
|
};
|
|
|
|
/**
|
|
* 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-'
|
|
);
|
|
};
|
|
|
|
module.exports = HeadingItem;
|