ve.ui.MWSaveDialog: Allow limiting comment length by characters rather than bytes

Bug: T185948
Change-Id: I882d69beb1cd442868c8d73988f5b3a2bbb084bc
This commit is contained in:
Bartosz Dziewo??ski 2018-02-27 22:34:27 +01:00 committed by Bartosz Dziewoński
parent c44390e6f8
commit dbfe6c0b5a
4 changed files with 35 additions and 17 deletions

View file

@ -555,8 +555,8 @@
"modules/ve-mw/ui/styles/dialogs/ve.ui.MWSaveDialog.css"
],
"dependencies": [
"jquery.byteLength",
"jquery.byteLimit",
"mediawiki.String",
"jquery.lengthLimit",
"ext.visualEditor.mediawiki",
"ext.visualEditor.core",
"ext.visualEditor.mwcore",
@ -1355,6 +1355,7 @@
"visualeditor-editnotices-tool",
"visualeditor-editnotices-tooltip",
"visualeditor-editsummary",
"visualeditor-editsummary-characters-remaining",
"visualeditor-editsummary-bytes-remaining",
"visualeditor-educationpopup-dismiss",
"visualeditor-feedback-defaultmessage",

View file

@ -246,6 +246,7 @@
"visualeditor-editnotices-tool": "$1 {{PLURAL:$1|notice|notices}}",
"visualeditor-editnotices-tooltip": "Edit notices",
"visualeditor-editsummary": "Describe what you changed",
"visualeditor-editsummary-characters-remaining": "The number of characters remaining",
"visualeditor-editsummary-bytes-remaining": "The number of bytes remaining",
"visualeditor-educationpopup-dismiss": "Okay, got it",
"visualeditor-feedback-defaultmessage": "URL: $1",

View file

@ -259,6 +259,7 @@
"visualeditor-editnotices-tool": "Text of tool in the toolbar that shows edit notices (such as [[MediaWiki:Editnotice-0]] and [[MediaWiki:Editnotice-8/en]]) as a pop-up.\n\nParameters:\n* $1 - the number of notices\n{{Identical|Notice}}",
"visualeditor-editnotices-tooltip": "Text of tooltip for the tool in the toolbar that shows edit notices (i.e. “messages about the editing”), e.g. the “you are not currently logged in” notice",
"visualeditor-editsummary": "Label for the edit summary box",
"visualeditor-editsummary-characters-remaining": "Tooltip for the number of characters remaining in the edit summary",
"visualeditor-editsummary-bytes-remaining": "Tooltip for the number of bytes remaining in the edit summary",
"visualeditor-educationpopup-dismiss": "Text on dismiss button shown on the educational popups drawing user attention to specific tools.",
"visualeditor-feedback-defaultmessage": "Default message text for the feedback dialog.\nParameters:\n\n* $1 - URL of the page\n{{Identical|URL}}",

View file

@ -22,7 +22,8 @@ ve.ui.MWSaveDialog = function VeUiMwSaveDialog( config ) {
ve.ui.MWSaveDialog.super.call( this, config );
// Properties
this.editSummaryByteLimit = 255;
this.editSummaryByteLimit = mw.config.get( 'wgCommentByteLimit' );
this.editSummaryCodePointLimit = mw.config.get( 'wgCommentCodePointLimit' );
this.restoring = false;
this.messages = {};
this.setupDeferred = $.Deferred();
@ -510,7 +511,8 @@ ve.ui.MWSaveDialog.prototype.setEditSummary = function ( summary ) {
* @inheritdoc
*/
ve.ui.MWSaveDialog.prototype.initialize = function () {
var dialog = this;
var dialog = this,
mwString = require( 'mediawiki.String' );
// Parent method
ve.ui.MWSaveDialog.super.prototype.initialize.call( this );
@ -527,8 +529,9 @@ ve.ui.MWSaveDialog.prototype.initialize = function () {
// Byte counter in edit summary
this.editSummaryCountLabel = new OO.ui.LabelWidget( {
classes: [ 've-ui-mwSaveDialog-editSummary-count' ],
label: String( this.editSummaryByteLimit ),
title: ve.msg( 'visualeditor-editsummary-bytes-remaining' )
label: String( this.editSummaryCodePointLimit || this.editSummaryByteLimit ),
title: ve.msg( this.editSummaryCodePointLimit ?
'visualeditor-editsummary-characters-remaining' : 'visualeditor-editsummary-bytes-remaining' )
} );
// Save panel
@ -558,17 +561,29 @@ ve.ui.MWSaveDialog.prototype.initialize = function () {
);
}
} );
// Limit byte length, and display the remaining bytes
this.editSummaryInput.$input.byteLimit( this.editSummaryByteLimit );
this.editSummaryInput.on( 'change', function () {
dialog.changedEditSummary = true;
// TODO: This looks a bit weird, there is no unit in the UI, just numbers
// Users likely assume characters but then it seems to count down quicker
// than expected. Facing users with the word "byte" is bad? (bug 40035)
dialog.editSummaryCountLabel.setLabel(
String( dialog.editSummaryByteLimit - $.byteLength( dialog.editSummaryInput.getValue() ) )
);
} );
// Limit length, and display the remaining bytes/characters
if ( this.editSummaryCodePointLimit ) {
this.editSummaryInput.$input.codePointLimit( this.editSummaryCodePointLimit );
this.editSummaryInput.on( 'change', function () {
dialog.changedEditSummary = true;
dialog.editSummaryCountLabel.setLabel(
String( dialog.editSummaryCodePointLimit -
mwString.codePointLength( dialog.editSummaryInput.getValue() ) )
);
} );
} else {
this.editSummaryInput.$input.byteLimit( this.editSummaryByteLimit );
this.editSummaryInput.on( 'change', function () {
// TODO: This looks a bit weird, there is no unit in the UI, just numbers
// Users likely assume characters but then it seems to count down quicker
// than expected. Facing users with the word "byte" is bad? (bug 40035)
dialog.changedEditSummary = true;
dialog.editSummaryCountLabel.setLabel(
String( dialog.editSummaryByteLimit -
mwString.byteLength( dialog.editSummaryInput.getValue() ) )
);
} );
}
this.$saveCheckboxes = $( '<div>' ).addClass( 've-ui-mwSaveDialog-checkboxes' );
this.$saveOptions = $( '<div>' ).addClass( 've-ui-mwSaveDialog-options' ).append(