Merge "Fetch Parsoid document for modification"

This commit is contained in:
jenkins-bot 2019-11-05 21:57:03 +00:00 committed by Gerrit Code Review
commit eb0c09ad1d

View file

@ -1,4 +1,4 @@
var comments, threads,
var pageComments, pageThreads, parsoidPromise, parsoidComments, parsoidDoc,
widgetPromise = mw.loader.using( 'oojs-ui-core' );
/**
@ -35,8 +35,38 @@ function setupComment( comment ) {
widgetPromise.then( function () {
var replyWidget = new OO.ui.MultilineTextInputWidget( {
value: 'Reply to ' + comment.author
} ),
replyButton = new OO.ui.ButtonWidget( {
flags: [ 'primary', 'progressive' ],
label: 'Reply'
} );
$( newListItem ).empty().append( replyWidget.$element );
replyButton.on( 'click', function () {
comment.parsoidCommentPromise.then( function ( parsoidComment ) {
var html,
newParsoidList = mw.dt.modifier.addListAtComment( parsoidComment );
replyWidget.getValue().split( '\n' ).forEach( function ( line, i, arr ) {
var lineItem = mw.dt.modifier.addListItem( newParsoidList );
if ( i === arr.length - 1 && line.trim().slice( -4 ) !== '~~~~' ) {
line += ' ~~~~';
}
lineItem.appendChild( mw.dt.modifier.createWikitextNode( line ) );
} );
// TODO: We need an ArticleTargetSaver that is separate from
// Target logic.
html = ve.init.mw.Target.prototype.getHtml(
parsoidComment.range.endContainer.ownerDocument
);
// eslint-disable-next-line
console.log( html );
} );
} );
$( newListItem ).empty().append(
replyWidget.$element, replyButton.$element
);
replyWidget.focus();
} );
} )
@ -53,7 +83,40 @@ function traverseNode( parent ) {
if ( new mw.Uri().query.dtdebug ) {
mw.loader.load( 'ext.discussionTools.debug' );
} else {
comments = mw.dt.parser.getComments( document.getElementById( 'mw-content-text' ) );
threads = mw.dt.parser.groupThreads( comments );
threads.forEach( traverseNode );
pageComments = mw.dt.parser.getComments( document.getElementById( 'mw-content-text' ) );
pageThreads = mw.dt.parser.groupThreads( pageComments );
pageThreads.forEach( traverseNode );
// For debugging
mw.dt.pageThreads = pageThreads;
parsoidPromise = mw.loader.using( [
'ext.visualEditor.targetLoader',
// TODO: We are loading ext.visualEditor.base just for ve.createDocumentFromHTML
'ext.visualEditor.base',
// TODO: Loading mw.Target class for save testing
'ext.visualEditor.mediawiki'
] ).then( function () {
return mw.libs.ve.targetLoader.requestPageData(
'visual', mw.config.get( 'wgRelevantPageName' ), {
oldId: mw.config.get( 'wgRevisionId' )
}
).then( function ( response ) {
// TODO: error handling
parsoidDoc = ve.createDocumentFromHtml( response.visualeditor.content );
parsoidComments = mw.dt.parser.getComments( parsoidDoc.body );
// getThreads build the tree structure, currently only
// used to set 'replies'
mw.dt.parser.groupThreads( parsoidComments );
} );
} );
// Map PHP comments to Parsoid comments.
// TODO: Handle when these don't align
pageComments.forEach( function ( comment, i ) {
comment.parsoidCommentPromise = parsoidPromise.then( function () {
return parsoidComments[ i ];
} );
} );
}