Move some postReply logic to modifier.js

Re-create the function in PHP

Change-Id: I1c8b505542c3b82c10b7b258e48054bc59cb4836
This commit is contained in:
Ed Sanders 2020-06-26 23:00:34 +01:00
parent 6d4d0962ef
commit fb0d2cbe7f
3 changed files with 50 additions and 14 deletions

View file

@ -294,6 +294,29 @@ class CommentModifier {
return $listItem;
}
/**
* Add a reply to a specific comment
*
* @param CommentItem $comment Comment being replied to
* @param DOMElement $container Container of comment DOM nodes
*/
public static function addReply( CommentItem $comment, DOMElement $container ) {
$newParsoidItem = null;
// Transfer comment DOM to Parsoid DOM
// Wrap every root node of the document in a new list item (dd/li).
// In wikitext mode every root node is a paragraph.
// In visual mode the editor takes care of preventing problematic nodes
// like <table> or <h2> from ever occurring in the comment.
while ( $container->childNodes->length ) {
if ( !$newParsoidItem ) {
$newParsoidItem = self::addListItem( $comment );
} else {
$newParsoidItem = self::addSiblingListItem( $newParsoidItem );
}
$newParsoidItem->appendChild( $container->firstChild );
}
}
/**
* Create an element that will convert to the provided wikitext
*

View file

@ -304,7 +304,7 @@ CommentController.prototype.createCommentContainerFromHtml = function ( doc, htm
};
CommentController.prototype.postReply = function ( comment ) {
var container, newParsoidItem, wikitext,
var container, wikitext,
doc = comment.range.endContainer.ownerDocument;
if ( this.replyWidget.getMode() === 'source' ) {
@ -319,19 +319,7 @@ CommentController.prototype.postReply = function ( comment ) {
container = this.createCommentContainerFromHtml( doc, this.replyWidget.getValue() );
}
// Transfer comment DOM to Parsoid DOM
// Wrap every root node of the document in a new list item (dd/li).
// In wikitext mode every root node is a paragraph.
// In visual mode the editor takes care of preventing problematic nodes
// like <table> or <h2> from ever occurring in the comment.
while ( container.children.length ) {
if ( !newParsoidItem ) {
newParsoidItem = modifier.addListItem( comment );
} else {
newParsoidItem = modifier.addSiblingListItem( newParsoidItem );
}
newParsoidItem.appendChild( container.firstChild );
}
modifier.addReply( comment, container );
};
CommentController.prototype.save = function ( parsoidData ) {

View file

@ -292,6 +292,30 @@ function addSiblingListItem( previousItem ) {
return listItem;
}
/**
* Add a reply to a specific comment
*
* @param {CommentItem} comment Comment being replied to
* @param {HTMLElement} container Container of comment DOM nodes
*/
function addReply( comment, container ) {
var newParsoidItem;
// Transfer comment DOM to Parsoid DOM
// Wrap every root node of the document in a new list item (dd/li).
// In wikitext mode every root node is a paragraph.
// In visual mode the editor takes care of preventing problematic nodes
// like <table> or <h2> from ever occurring in the comment.
while ( container.childNodes.length ) {
if ( !newParsoidItem ) {
newParsoidItem = addListItem( comment );
} else {
newParsoidItem = addSiblingListItem( newParsoidItem );
}
newParsoidItem.appendChild( container.firstChild );
}
}
function createWikitextNode( doc, wt ) {
var span = doc.createElement( 'span' );
@ -303,6 +327,7 @@ function createWikitextNode( doc, wt ) {
module.exports = {
addReplyLink: addReplyLink,
addReply: addReply,
addListItem: addListItem,
removeAddedListItem: removeAddedListItem,
addSiblingListItem: addSiblingListItem,