Merge "Set rootNode for items from in ThreadItemSet#newFromAnnotatedNodes"

This commit is contained in:
jenkins-bot 2022-06-21 15:41:49 +00:00 committed by Gerrit Code Review
commit 58a9deb531
3 changed files with 9 additions and 5 deletions

View file

@ -51,10 +51,11 @@ OO.initClass( ThreadItem );
* Create a new ThreadItem from a JSON serialization
*
* @param {string|Object} json JSON serialization or hash object
* @param {HTMLElement} rootNode
* @return {ThreadItem}
* @throws {Error} Unknown ThreadItem type
*/
ThreadItem.static.newFromJSON = function ( json ) {
ThreadItem.static.newFromJSON = function ( json, rootNode ) {
// The page can be served from the HTTP cache (Varnish), and the JSON may be generated
// by an older version of our PHP code. Code below must be able to handle that.
// See ThreadItem::jsonSerialize() in PHP.
@ -92,6 +93,8 @@ ThreadItem.static.newFromJSON = function ( json ) {
item.name = hash.name;
item.id = hash.id;
item.rootNode = rootNode;
var idEscaped = $.escapeSelector( item.id );
var startMarker = document.getElementById( item.id );
var endMarker = document.querySelector( '[data-mw-comment-end="' + idEscaped + '"]' );

View file

@ -21,11 +21,12 @@ OO.initClass( ThreadItemSet );
* Created a ThreadItemSet from DOM nodes that have been annotated by the PHP CommentFormatter with
* metadata about the thread structure.
*
* @param {HTMLElement} nodes
* @param {HTMLElement[]} nodes
* @param {HTMLElement} rootNode
* @param {mw.dt.Parser} parser
* @return {ThreadItemSet}
*/
ThreadItemSet.static.newFromAnnotatedNodes = function ( nodes, parser ) {
ThreadItemSet.static.newFromAnnotatedNodes = function ( nodes, rootNode, parser ) {
var result = new ThreadItemSet();
// The page can be served from the HTTP cache (Varnish), containing data-mw-comment generated
@ -41,7 +42,7 @@ ThreadItemSet.static.newFromAnnotatedNodes = function ( nodes, parser ) {
// Create ThreadItem objects with basic data
for ( i = 0; i < nodes.length; i++ ) {
var hash = JSON.parse( nodes[ i ].getAttribute( 'data-mw-comment' ) );
item = ThreadItem.static.newFromJSON( hash );
item = ThreadItem.static.newFromJSON( hash, rootNode );
result.addThreadItem( item );
// Store info for second pass

View file

@ -254,7 +254,7 @@ function init( $container, state ) {
var parser = new Parser( require( './parser/data.json' ) );
var commentNodes = $pageContainer[ 0 ].querySelectorAll( '[data-mw-comment]' );
pageThreads = ThreadItemSet.static.newFromAnnotatedNodes( commentNodes, parser );
pageThreads = ThreadItemSet.static.newFromAnnotatedNodes( commentNodes, $pageContainer[ 0 ], parser );
if ( featuresEnabled.topicsubscription ) {
topicSubscriptions.initTopicSubscriptions( $container, pageThreads );