Merge "Modifier: Pass document to createWikitext"

This commit is contained in:
jenkins-bot 2020-05-18 17:54:15 +00:00 committed by Gerrit Code Review
commit a41eadfc51
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 ] } ) );