mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-12-18 02:51:26 +00:00
d76143bc08
1. Extend the JS modifier to allow adding top-level comments (that is, replies to headings). PHP modifier doesn't do this because we'll save the changes using paction=addtopic instead. 2. Subclass CommentController to allow adding a new heading and a top-level comment underneath it at the same time. 3. A lot of ugly code in ReplyWidget to customize the interface for this case. Much of it should probably be moved to CommentController/NewTopicController. Bug: T267595 Change-Id: I9c707bb7f7aae1b92c72fb4dee436490f8c8409b
50 lines
1.5 KiB
JavaScript
50 lines
1.5 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;
|
|
};
|
|
|
|
/**
|
|
* @return {HeadingItem} Closest ancestor which is a HeadingItem
|
|
*/
|
|
HeadingItem.prototype.getHeading = function () {
|
|
return this;
|
|
};
|
|
|
|
module.exports = HeadingItem;
|