Merge "Config: Separate useVisualEditor into enableVisual and use2017Wikitext"

This commit is contained in:
jenkins-bot 2020-05-06 20:27:53 +00:00 committed by Gerrit Code Review
commit 6ee5865228
5 changed files with 25 additions and 14 deletions

View file

@ -34,9 +34,10 @@
] ]
}, },
{ {
"name": "controller/config.json", "name": "config.json",
"config": { "config": {
"useVisualEditor": "DiscussionToolsUseVisualEditor" "enableVisual": "DiscussionToolsEnableVisual",
"enable2017Wikitext": "DiscussionToolsEnable2017Wikitext"
} }
}, },
"CommentController.js", "CommentController.js",
@ -233,9 +234,13 @@
"value": false, "value": false,
"description": "Make DiscussionTools a BetaFeature." "description": "Make DiscussionTools a BetaFeature."
}, },
"DiscussionToolsUseVisualEditor": { "DiscussionToolsEnableVisual": {
"value": false, "value": false,
"description": "Use VisualEditor for editing replies (both visual and wikitext)." "description": "Enable a visual mode for replies."
},
"DiscussionToolsEnable2017Wikitext": {
"value": false,
"description": "Enable the 2017 wikitext editor for wikitext replies (not yet supported)."
}, },
"DTSchemaEditAttemptStepSamplingRate": { "DTSchemaEditAttemptStepSamplingRate": {
"value": false, "value": false,

View file

@ -5,12 +5,13 @@ var
logger = require( './logger.js' ), logger = require( './logger.js' ),
storage = mw.storage.session, storage = mw.storage.session,
scrollPadding = { top: 10, bottom: 10 }, scrollPadding = { top: 10, bottom: 10 },
config = require( './controller/config.json' ), config = require( './config.json' ),
// TODO: Remember last editor used // TODO: Remember last editor used
useVisual = config.useVisualEditor || ( new mw.Uri() ).query.dtvisual; defaultVisual = false,
enableVisual = config.enableVisual || ( new mw.Uri() ).query.dtvisual;
// Start loading reply widget code // Start loading reply widget code
if ( useVisual ) { if ( defaultVisual && enableVisual ) {
mw.loader.using( 'ext.discussionTools.ReplyWidgetVisual' ); mw.loader.using( 'ext.discussionTools.ReplyWidgetVisual' );
} else { } else {
mw.loader.using( 'ext.discussionTools.ReplyWidgetPlain' ); mw.loader.using( 'ext.discussionTools.ReplyWidgetPlain' );
@ -135,10 +136,9 @@ CommentController.prototype.setup = function () {
action: 'init', action: 'init',
type: 'page', type: 'page',
mechanism: 'click', mechanism: 'click',
// TODO: when we have actual visual mode, this needs to do better at // TODO: Use 'wikitext-2017' when config.enable2017Wikitext is set
// working out which will be used:
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
editor_interface: useVisual ? 'wikitext-2017' : 'wikitext' editor_interface: defaultVisual ? 'visual' : 'wikitext'
} ); } );
this.$replyLinkButtons.addClass( 'dt-init-replylink-active' ); this.$replyLinkButtons.addClass( 'dt-init-replylink-active' );
@ -189,7 +189,7 @@ CommentController.prototype.getReplyWidgetClass = function ( visual ) {
var moduleName; var moduleName;
if ( visual === undefined ) { if ( visual === undefined ) {
visual = useVisual; visual = defaultVisual;
} }
moduleName = visual ? 'ext.discussionTools.ReplyWidgetVisual' : 'ext.discussionTools.ReplyWidgetPlain'; moduleName = visual ? 'ext.discussionTools.ReplyWidgetVisual' : 'ext.discussionTools.ReplyWidgetPlain';
@ -203,6 +203,7 @@ CommentController.prototype.createReplyWidget = function ( parsoidData, visual )
return this.getReplyWidgetClass( visual ).then( function ( ReplyWidget ) { return this.getReplyWidgetClass( visual ).then( function ( ReplyWidget ) {
return new ReplyWidget( commentController, parsoidData, { return new ReplyWidget( commentController, parsoidData, {
switchable: enableVisual,
input: { input: {
authors: parser.getAuthors( commentController.thread ) authors: parser.getAuthors( commentController.thread )
} }

View file

@ -26,5 +26,6 @@ module.exports = {
parser: require( './parser.js' ), parser: require( './parser.js' ),
modifier: require( './modifier.js' ), modifier: require( './modifier.js' ),
utils: require( './utils.js' ), utils: require( './utils.js' ),
logger: require( './logger.js' ) logger: require( './logger.js' ),
config: require( './config.json' )
}; };

View file

@ -12,6 +12,7 @@ var controller = require( 'ext.discussionTools.init' ).controller,
* @param {Object} parsoidData Result from controller#getParsoidCommentData * @param {Object} parsoidData Result from controller#getParsoidCommentData
* @param {Object} [config] Configuration options * @param {Object} [config] Configuration options
* @param {Object} [config.input] Configuration options for the comment input widget * @param {Object} [config.input] Configuration options for the comment input widget
* @param {boolean} [config.switchable] Widget can switch modes (visual/source)
*/ */
function ReplyWidget( commentController, parsoidData, config ) { function ReplyWidget( commentController, parsoidData, config ) {
var returnTo, contextNode, inputConfig, var returnTo, contextNode, inputConfig,
@ -106,12 +107,15 @@ function ReplyWidget( commentController, parsoidData, config ) {
// Initialization // Initialization
this.$element.addClass( 'dt-ui-replyWidget' ).append( this.$element.addClass( 'dt-ui-replyWidget' ).append(
this.modeTabSelect.$element,
this.replyBodyWidget.$element, this.replyBodyWidget.$element,
this.$preview, this.$preview,
this.$actionsWrapper this.$actionsWrapper
); );
if ( config.switchable ) {
this.$element.prepend( this.modeTabSelect.$element );
}
if ( mw.user.isAnon() ) { if ( mw.user.isAnon() ) {
returnTo = { returnTo = {
returntoquery: encodeURIComponent( window.location.search ), returntoquery: encodeURIComponent( window.location.search ),

View file

@ -16,7 +16,7 @@ function ReplyWidgetVisual() {
// Parent constructor // Parent constructor
ReplyWidgetVisual.super.apply( this, arguments ); ReplyWidgetVisual.super.apply( this, arguments );
// TODO: Use user preference // TODO: Support 2017 wikitext editor
this.defaultMode = 'visual'; this.defaultMode = 'visual';
this.initialValue = null; this.initialValue = null;