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' ); widgetPromise = mw.loader.using( 'oojs-ui-core' );
/** /**
@ -34,9 +34,39 @@ function setupComment( comment ) {
widgetPromise.then( function () { widgetPromise.then( function () {
var replyWidget = new OO.ui.MultilineTextInputWidget( { var replyWidget = new OO.ui.MultilineTextInputWidget( {
value: 'Reply to ' + comment.author value: 'Reply to ' + comment.author
} ),
replyButton = new OO.ui.ButtonWidget( {
flags: [ 'primary', 'progressive' ],
label: 'Reply'
} );
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 );
$( newListItem ).empty().append(
replyWidget.$element, replyButton.$element
);
replyWidget.focus(); replyWidget.focus();
} ); } );
} ) } )
@ -53,7 +83,40 @@ function traverseNode( parent ) {
if ( new mw.Uri().query.dtdebug ) { if ( new mw.Uri().query.dtdebug ) {
mw.loader.load( 'ext.discussionTools.debug' ); mw.loader.load( 'ext.discussionTools.debug' );
} else { } else {
comments = mw.dt.parser.getComments( document.getElementById( 'mw-content-text' ) ); pageComments = mw.dt.parser.getComments( document.getElementById( 'mw-content-text' ) );
threads = mw.dt.parser.groupThreads( comments ); pageThreads = mw.dt.parser.groupThreads( pageComments );
threads.forEach( traverseNode ); 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 ];
} );
} );
} }