diff --git a/includes/CommentModifier.php b/includes/CommentModifier.php index 2c00693d9..d6d56c88d 100644 --- a/includes/CommentModifier.php +++ b/includes/CommentModifier.php @@ -2,6 +2,7 @@ namespace MediaWiki\Extension\DiscussionTools; +use DOMDocument; use DOMElement; use DOMNode; use stdClass; @@ -290,11 +291,13 @@ class CommentModifier { /** * Create an element that will convert to the provided wikitext + * + * @param DOMDocument $doc Document * @param string $wt Wikitext * @return DOMElement Element */ - public static function createWikitextNode( string $wt ) : DOMElement { - $span = $document->createElement( 'span' ); + public static function createWikitextNode( DOMDocument $doc, string $wt ) : DOMElement { + $span = $doc->createElement( 'span' ); $span->setAttribute( 'typeof', 'mw:Transclusion' ); $span->setAttribute( 'data-mw', json_encode( [ 'parts' => [ $wt ] ] ) ); diff --git a/modules/CommentController.js b/modules/CommentController.js index 19f98f862..c56e1db45 100644 --- a/modules/CommentController.js +++ b/modules/CommentController.js @@ -258,7 +258,7 @@ CommentController.prototype.postReply = function ( parsoidData ) { wikitext = controller.sanitizeWikitextLinebreaks( controller.autoSignWikitext( wikitext ) ); wikitext.split( '\n' ).forEach( function ( line ) { var p = doc.createElement( 'p' ); - p.appendChild( modifier.createWikitextNode( line ) ); + p.appendChild( modifier.createWikitextNode( doc, line ) ); container.appendChild( p ); } ); } else { @@ -271,7 +271,7 @@ CommentController.prototype.postReply = function ( parsoidData ) { // Sign the last line // TODO: Check if the user tried to sign in visual mode by typing wikitext? // TODO: When we implement posting new topics, the leading space will create an indent-pre - container.lastChild.appendChild( modifier.createWikitextNode( ' ~~~~' ) ); + container.lastChild.appendChild( modifier.createWikitextNode( doc, ' ~~~~' ) ); } // Transfer comment DOM to Parsoid DOM diff --git a/modules/modifier.js b/modules/modifier.js index da27aa335..9492ff961 100644 --- a/modules/modifier.js +++ b/modules/modifier.js @@ -253,8 +253,8 @@ function addSiblingListItem( previousItem ) { return listItem; } -function createWikitextNode( wt ) { - var span = document.createElement( 'span' ); +function createWikitextNode( doc, wt ) { + var span = doc.createElement( 'span' ); span.setAttribute( 'typeof', 'mw:Transclusion' ); span.setAttribute( 'data-mw', JSON.stringify( { parts: [ wt ] } ) );