mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-28 02:00:57 +00:00
Merge "Fetch Parsoid document for modification"
This commit is contained in:
commit
eb0c09ad1d
|
@ -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' );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,8 +35,38 @@ 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'
|
||||||
} );
|
} );
|
||||||
$( 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();
|
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 ];
|
||||||
|
} );
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue