Merge "Introduce CommentDetails to group up and document stuff we pass around"

This commit is contained in:
jenkins-bot 2021-07-01 17:18:58 +00:00 committed by Gerrit Code Review
commit 3676f3881d
7 changed files with 46 additions and 24 deletions

View file

@ -63,6 +63,7 @@
"ThreadItem.js",
"CommentItem.js",
"HeadingItem.js",
"CommentDetails.js",
"lib/moment-timezone/moment-timezone-with-data-1970-2030.js",
{
"name": "parser/data.json",

View file

@ -1,5 +1,6 @@
/**
* @external CommentItem
* @external CommentDetails
* @external ThreadItem
*/
@ -74,7 +75,7 @@ function getLatestRevId( pageName ) {
* and then follows transclusions to determine the source page where it is written.
*
* @param {CommentItem} comment Comment
* @return {jQuery.Promise} Promise which resolves with pageName+oldId, or rejects with an error
* @return {jQuery.Promise} Promise which resolves with a CommentDetails object, or rejects with an error
*/
CommentController.prototype.getTranscludedFromSource = function ( comment ) {
var pageName = mw.config.get( 'wgRelevantPageName' ),
@ -161,8 +162,8 @@ CommentController.prototype.setup = function ( mode, hideErrors ) {
this.$replyLinkButtons.addClass( 'ext-discussiontools-init-replylink-active' );
if ( !this.replyWidgetPromise ) {
this.replyWidgetPromise = this.getTranscludedFromSource( comment ).then( function ( pageData ) {
return commentController.createReplyWidget( comment, pageData.pageName, pageData.oldId, { mode: mode } );
this.replyWidgetPromise = this.getTranscludedFromSource( comment ).then( function ( commentDetails ) {
return commentController.createReplyWidget( comment, commentDetails, { mode: mode } );
}, function ( code, data ) {
commentController.teardown();
@ -213,10 +214,16 @@ CommentController.prototype.getReplyWidgetClass = function ( visual ) {
} );
};
CommentController.prototype.createReplyWidget = function ( comment, pageName, oldId, config ) {
/**
* @param {CommentItem} comment
* @param {CommentDetails} commentDetails
* @param {Object} config
* @return {jQuery.Promise} Promise resolved with a ReplyWidget
*/
CommentController.prototype.createReplyWidget = function ( comment, commentDetails, config ) {
var commentController = this;
return this.getReplyWidgetClass( config.mode === 'visual' ).then( function ( ReplyWidget ) {
return new ReplyWidget( commentController, comment, pageName, oldId, config );
return new ReplyWidget( commentController, comment, commentDetails, config );
} );
};
@ -381,8 +388,7 @@ CommentController.prototype.switchToWikitext = function () {
var wikitextPromise = target.getWikitextFragment( target.getSurface().getModel().getDocument() );
this.replyWidgetPromise = this.createReplyWidget(
oldWidget.comment,
oldWidget.pageName,
oldWidget.oldId,
oldWidget.commentDetails,
{ mode: 'source' }
);
@ -503,8 +509,7 @@ CommentController.prototype.switchToVisual = function () {
}
this.replyWidgetPromise = this.createReplyWidget(
oldWidget.comment,
oldWidget.pageName,
oldWidget.oldId,
oldWidget.commentDetails,
{ mode: 'visual' }
);

16
modules/CommentDetails.js Normal file
View file

@ -0,0 +1,16 @@
/**
* More information about a comment obtained from various APIs, rather than parsed from the page.
*
* @class CommentDetails
* @constructor
* @param {string} pageName Page name the reply is being saved to
* @param {number} oldId Revision ID of page at time of editing
*/
function CommentDetails( pageName, oldId ) {
this.pageName = pageName;
this.oldId = oldId;
}
OO.initClass( CommentDetails );
module.exports = CommentDetails;

View file

@ -2,6 +2,7 @@
/**
* @external CommentItem
* @external CommentDetails
*/
var
@ -10,6 +11,7 @@ var
featuresEnabled = mw.config.get( 'wgDiscussionToolsFeaturesEnabled' ) || {},
Parser = require( './Parser.js' ),
ThreadItem = require( './ThreadItem.js' ),
CommentDetails = require( './CommentDetails.js' ),
logger = require( './logger.js' ),
utils = require( './utils.js' ),
pageDataCache = {};
@ -130,7 +132,7 @@ function getPageData( pageName, oldId, isNewTopic ) {
* @param {string} pageName Page title
* @param {number} oldId Revision ID
* @param {CommentItem} comment Comment
* @return {jQuery.Promise} Resolves with the pageName+oldId if the comment appears on the page.
* @return {jQuery.Promise} Resolved with a CommentDetails object if the comment appears on the page.
* Rejects with error data if the comment is transcluded, or there are lint errors on the page.
*/
function checkCommentOnPage( pageName, oldId, comment ) {
@ -206,10 +208,7 @@ function checkCommentOnPage( pageName, oldId, comment ) {
} ] } ).promise();
}
return {
pageName: pageName,
oldId: oldId
};
return new CommentDetails( pageName, oldId );
} );
}

View file

@ -13,6 +13,7 @@ require( './AbandonTopicDialog.js' );
/**
* @external CommentController
* @external CommentItem
* @external CommentDetails
*/
/**
@ -23,12 +24,11 @@ require( './AbandonTopicDialog.js' );
* @constructor
* @param {CommentController} commentController Comment controller
* @param {CommentItem} comment Comment item
* @param {string} pageName Page name the reply is being saved to
* @param {number} oldId Revision ID of page at time of editing
* @param {CommentDetails} commentDetails
* @param {Object} [config] Configuration options
* @param {Object} [config.input] Configuration options for the comment input widget
*/
function ReplyWidget( commentController, comment, pageName, oldId, config ) {
function ReplyWidget( commentController, comment, commentDetails, config ) {
var widget = this;
config = config || {};
@ -39,9 +39,10 @@ function ReplyWidget( commentController, comment, pageName, oldId, config ) {
this.pending = false;
this.commentController = commentController;
this.comment = comment;
this.commentDetails = commentDetails;
this.isNewTopic = !!comment.isNewTopic;
this.pageName = pageName;
this.oldId = oldId;
this.pageName = commentDetails.pageName;
this.oldId = commentDetails.oldId;
var contextNode = utils.closestElement( comment.range.endContainer, [ 'dl', 'ul', 'ol' ] );
this.context = contextNode ? contextNode.nodeName.toLowerCase() : 'dl';
// TODO: Should storagePrefix include pageName?

View file

@ -1,6 +1,7 @@
/**
* @external CommentController
* @external CommentItem
* @external CommentDetails
*/
var utils = require( 'ext.discussionTools.init' ).utils;
@ -13,8 +14,7 @@ var utils = require( 'ext.discussionTools.init' ).utils;
* @constructor
* @param {CommentController} commentController
* @param {CommentItem} comment
* @param {string} pageName
* @param {number} oldId
* @param {CommentDetails} commentDetails
* @param {Object} [config]
*/
function ReplyWidgetPlain() {

View file

@ -11,6 +11,7 @@ require( './dt-ve/dt.ce.PingNode.js' );
/**
* @external CommentController
* @external CommentItem
* @external CommentDetails
*/
/**
@ -21,11 +22,10 @@ require( './dt-ve/dt.ce.PingNode.js' );
* @constructor
* @param {CommentController} commentController
* @param {CommentItem} comment
* @param {string} pageName
* @param {number} oldId
* @param {CommentDetails} commentDetails
* @param {Object} [config]
*/
function ReplyWidgetVisual( commentController, comment, pageName, oldId, config ) {
function ReplyWidgetVisual( commentController, comment, commentDetails, config ) {
this.defaultMode = config.mode;
// Parent constructor