Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F6639
summaryChar.patch
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Authored By
•
bzimport
Nov 21 2014, 11:02 PM
2014-11-21 23:02:49 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
summaryChar.patch
View Options
Index: edit.js
===================================================================
--- edit.js (revision 65892)
+++ edit.js (working copy)
@@ -229,3 +229,36 @@
editForm
} );
+//make sure edit summary does not exceed byte limit
+addOnloadHook(function () {
+ var summary = document.getElementById('wpSummary');
+ summary.maxLength = 250; //L must be capitalized in length.
+
+ checkSummary = function (e) {
+ if (!e) e = window.event; //IE
+
+ //first check to see if this is actually a character key
+ // being pressed.
+ //Based on key-event info from http://unixpapa.com/js/key.html
+ //note === sign, if undefined, still could be a real key
+
+ if (e.which === 0 || e.charCode === 0 || e.ctrlKey || e.altKey || e.metaKey) {
+ return true; //a special key (backspace, etc) so don't interefere.
+ }
+
+ //This basically figures out how many bytes a utf-16 string (which is what js sees) will take in utf-8
+ //by replacing a 2 byte character with 2 *'s, etc, and counting that.
+ //Note, surogate (\uD800-\uDFFF) characters are counted as 2 bytes, since theres two of them
+ //and the actual character takes 4 bytes in utf-8 (2*2=4). might not work perfectly in edge cases such as
+ //such as illegal sequences, but that should never happen.
+
+ len = summary.value.replace(/[\u0080-\u07FF\uD800-\uDFFF]/g, '**').replace(/[\u0800-\uD7FF\uE000-\uFFFF]/g, '***').length;
+ if (len > 250) {
+ if (e.preventDefault) e.preventDefault();
+ e.returnValue = false; //IE
+ }
+ }
+
+ addHandler(summary, 'keypress', checkSummary);
+});
+
Index: ../../includes/EditPage.php
===================================================================
--- ../../includes/EditPage.php (revision 65892)
+++ ../../includes/EditPage.php (working copy)
@@ -1486,6 +1486,7 @@
*/
function getSummaryInput($summary = "", $labelText = null, $inputAttrs = null, $spanLabelAttrs = null) {
global $wgUser;
+ //Note: the maxlength is overriden in JS to 250 and to make it use UTF-8 bytes, not characters.
$inputAttrs = ( is_array($inputAttrs) ? $inputAttrs : array() ) + array(
'id' => 'wpSummary',
'maxlength' => '200',
File Metadata
Details
Attached
Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6179
Default Alt Text
summaryChar.patch (2 KB)
Attached To
Mode
T24967: Edit comment/summary accepts 200 chars but is truncated on save.
Attached
Detach File
Event Timeline
Log In to Comment