Debug: Introduce "vote" debug mode

Bug: T269163
Change-Id: Ie8da7acf3660a6d30b92d7803d87ad51a3275369
This commit is contained in:
Ed Sanders 2020-12-12 12:52:28 +00:00
parent 15cb419f56
commit 633cc9a7b3

View file

@ -1,14 +1,23 @@
var
Parser = require( 'ext.discussionTools.init' ).Parser,
modifier = require( 'ext.discussionTools.init' ).modifier,
utils = require( 'ext.discussionTools.init' ).utils,
highlighter = require( './highlighter.js' ),
parser = new Parser( document.getElementById( 'mw-content-text' ) ),
comments = parser.getCommentItems(),
threads = parser.getThreads(),
timestampRegexps = parser.getLocalTimestampRegexps();
timestampRegexps = parser.getLocalTimestampRegexps(),
debug = +( new mw.Uri().query.dtdebug ),
DEBUG_HIGHLIGHT = 1,
DEBUG_VOTE = 2,
DEBUG_VOTE_PERMISSIVE = 4;
highlighter.markThreads( threads );
// eslint-disable-next-line no-bitwise
if ( debug & DEBUG_HIGHLIGHT ) {
highlighter.markThreads( threads );
comments.forEach( function ( comment ) {
// TODO: Use comment.signatureRanges to mark up signatures/timestamps
comments.forEach( function ( comment ) {
comment.signatureRanges.forEach( function ( signatureRange ) {
var signature, emptySignature, node, match;
@ -27,4 +36,51 @@ comments.forEach( function ( comment ) {
highlighter.markSignature( signature );
}
} );
} );
} );
}
// eslint-disable-next-line no-bitwise
if ( ( debug & DEBUG_VOTE ) || ( debug & DEBUG_VOTE_PERMISSIVE ) ) {
threads.forEach( function ( thread ) {
var level, lastReply, listItem, firstVote,
firstComment = thread.replies[ 0 ];
if ( firstComment && firstComment.type === 'comment' ) {
// eslint-disable-next-line no-bitwise
if ( !( debug & DEBUG_VOTE_PERMISSIVE ) && firstComment.level <= 1 ) {
// Not in permissive vote mode, and first reply was not indented
return;
}
firstVote = firstComment.level === 1 ?
// In permissive mode, the first vote is the replies to the OP
firstComment.replies[ 0 ] :
firstComment;
if ( !firstVote ) {
return;
}
level = firstVote.level;
firstVote.parent.replies.forEach( function ( reply ) {
if ( reply.type === 'comment' && reply.level <= level ) {
lastReply = reply;
}
} );
listItem = modifier.addSiblingListItem(
utils.closestElement( lastReply.range.endContainer, [ 'li', 'dd', 'p' ] )
);
if ( listItem && listItem.tagName.toLowerCase() === 'li' ) {
$( listItem )
// Hide bullet/number
.css( 'list-style', 'none' )
.append(
'[ ',
$( '<a>' ).text( 'add comment' ),
' ]'
);
}
}
} );
}