mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-24 00:13:36 +00:00
Add getHeading method to CommentItem
Change-Id: I14ccdbb432e835fe74760a52f07de172df2aba27
This commit is contained in:
parent
ed70d49285
commit
94511c6bad
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace MediaWiki\Extension\DiscussionTools;
|
||||
|
||||
use MWException;
|
||||
|
||||
class CommentItem extends ThreadItem {
|
||||
private $signatureRanges;
|
||||
private $timestamp;
|
||||
|
@ -58,6 +60,20 @@ class CommentItem extends ThreadItem {
|
|||
return $this->parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HeadingItem Closest ancestor which is a HeadingItem
|
||||
*/
|
||||
public function getHeading() : HeadingItem {
|
||||
$parent = $this;
|
||||
while ( $parent instanceof CommentItem ) {
|
||||
$parent = $parent->getParent();
|
||||
}
|
||||
if ( !( $parent instanceof HeadingItem ) ) {
|
||||
throw new MWException( 'heading parent not found' );
|
||||
}
|
||||
return $parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[] Comment warnings
|
||||
*/
|
||||
|
|
|
@ -273,7 +273,7 @@ CommentController.prototype.postReply = function ( comment ) {
|
|||
};
|
||||
|
||||
CommentController.prototype.save = function ( parsoidData ) {
|
||||
var root, summaryPrefix, summary, savePromise,
|
||||
var heading, summaryPrefix, summary, savePromise,
|
||||
mode = this.replyWidget.getMode(),
|
||||
comment = parsoidData.comment,
|
||||
pageData = parsoidData.pageData,
|
||||
|
@ -282,15 +282,12 @@ CommentController.prototype.save = function ( parsoidData ) {
|
|||
// Update the Parsoid DOM
|
||||
this.postReply( parsoidData.comment );
|
||||
|
||||
root = comment;
|
||||
while ( root && root.type !== 'heading' ) {
|
||||
root = root.parent;
|
||||
}
|
||||
if ( root.placeholderHeading ) {
|
||||
heading = comment.getHeading();
|
||||
if ( heading.placeholderHeading ) {
|
||||
// This comment is in 0th section, there's no section title for the edit summary
|
||||
summaryPrefix = '';
|
||||
} else {
|
||||
summaryPrefix = '/* ' + root.range.startContainer.innerText + ' */ ';
|
||||
summaryPrefix = '/* ' + heading.range.startContainer.innerText + ' */ ';
|
||||
}
|
||||
|
||||
summary = summaryPrefix + mw.msg( 'discussiontools-defaultsummary-reply' );
|
||||
|
|
|
@ -2,6 +2,7 @@ var ThreadItem = require( './ThreadItem.js' );
|
|||
|
||||
/**
|
||||
* @external moment
|
||||
* @external HeadingItem
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -41,4 +42,15 @@ function CommentItem( level, range, signatureRanges, timestamp, author ) {
|
|||
|
||||
OO.inheritClass( CommentItem, ThreadItem );
|
||||
|
||||
/**
|
||||
* @return {HeadingItem} Closest ancestor which is a HeadingItem
|
||||
*/
|
||||
CommentItem.prototype.getHeading = function () {
|
||||
var parent = this;
|
||||
while ( parent && parent.type !== 'heading' ) {
|
||||
parent = parent.parent;
|
||||
}
|
||||
return parent;
|
||||
};
|
||||
|
||||
module.exports = CommentItem;
|
||||
|
|
Loading…
Reference in a new issue