Modifier: Pass document to createWikitext

Change-Id: I1793e1d690835af746a4e25a50e2e0a474811e8e
This commit is contained in:
Ed Sanders 2020-05-15 22:35:50 +01:00
parent 21a892d5e7
commit 5e996fdfdd
3 changed files with 9 additions and 6 deletions

View file

@ -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 ] ] ) );

View file

@ -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

View file

@ -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 ] } ) );