r80554 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80553‎ | r80554 | r80555 >
Date:03:59, 19 January 2011
Author:bawolff
Status:ok (Comments)
Tags:
Comment:
(follow-up r66913) Per CR, make the editsummary length checker use jQuery/RL fanciness.

The js was tested in firefox 3.0.6, IE6, some oldish version of Opera, Konqourer, and Chrome.
(Of course in IE6, the rest of mediawiki fell on its face, but the js added here worked).
Modified paths:
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/resources/Resources.php (modified) (history)
  • /trunk/phase3/resources/mediawiki.action/mediawiki.action.edit.js (added) (history)
  • /trunk/phase3/skins/common/edit.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/edit.js
@@ -229,41 +229,3 @@
230230 editForm
231231 } );
232232
233 -//make sure edit summary does not exceed byte limit
234 -addOnloadHook(function () {
235 - var summary = document.getElementById( 'wpSummary' );
236 - if ( !summary ) {
237 - return;
238 - }
239 - summary.maxLength = 250; //L must be capitalized in length.
240 -
241 - checkSummary = function (e) {
242 - if (!e) e = window.event; //IE
243 -
244 - //first check to see if this is actually a character key
245 - // being pressed.
246 - //Based on key-event info from http://unixpapa.com/js/key.html
247 - //note === sign, if undefined, still could be a real key
248 -
249 - if (e.which === 0 || e.charCode === 0 || e.ctrlKey || e.altKey || e.metaKey) {
250 - return true; //a special key (backspace, etc) so don't interefere.
251 - }
252 -
253 - //This basically figures out how many bytes a utf-16 string (which is what js sees) will take in utf-8
254 - //by replacing a 2 byte character with 2 *'s, etc, and counting that.
255 - //Note, surogate (\uD800-\uDFFF) characters are counted as 2 bytes, since theres two of them
256 - //and the actual character takes 4 bytes in utf-8 (2*2=4). might not work perfectly in edge cases such as
257 - //such as illegal sequences, but that should never happen.
258 -
259 - len = summary.value.replace(/[\u0080-\u07FF\uD800-\uDFFF]/g, '**').replace(/[\u0800-\uD7FF\uE000-\uFFFF]/g, '***').length;
260 - //247 as this doesn't count character about to be inserted.
261 - if (len > 247) {
262 - if (e.preventDefault) e.preventDefault();
263 - e.returnValue = false; //IE
264 - return false;
265 - }
266 - };
267 -
268 - addHandler(summary, 'keypress', checkSummary);
269 -});
270 -
Index: trunk/phase3/includes/EditPage.php
@@ -335,7 +335,7 @@
336336 $this->preview = true;
337337 }
338338
339 - $wgOut->addModules( 'mediawiki.legacy.edit' );
 339+ $wgOut->addModules( array( 'mediawiki.legacy.edit', 'mediawiki.action.edit' ) );
340340
341341 if ( $wgUser->getOption( 'uselivepreview', false ) ) {
342342 $wgOut->addModules( 'mediawiki.legacy.preview' );
Index: trunk/phase3/resources/mediawiki.action/mediawiki.action.edit.js
@@ -0,0 +1,30 @@
 2+/* Note, there is still stuff in skins/common/edit.js that
 3+ * has not been jQuery-ized.
 4+ */
 5+
 6+//make sure edit summary does not exceed byte limit
 7+$( '#wpSummary' ).attr( 'maxLength', 250 ).keypress( function (e) {
 8+
 9+ // first check to see if this is actually a character key
 10+ // being pressed.
 11+ // Based on key-event info from http://unixpapa.com/js/key.html
 12+ // JQuery should also normalize e.which to be consistent cross-browser,
 13+ // however the same check is still needed regardless of jQuery.
 14+
 15+ if (e.which === 0 || e.charCode === 0 || e.ctrlKey || e.altKey || e.metaKey) {
 16+ return true; //a special key (backspace, etc) so don't interfere.
 17+ }
 18+
 19+ // This basically figures out how many bytes a UTF-16 string (which is what js sees)
 20+ // will take in UTF-8 by replacing a 2 byte character with 2 *'s, etc, and counting that.
 21+ // Note, surrogate (\uD800-\uDFFF) characters are counted as 2 bytes, since there's two of them
 22+ // and the actual character takes 4 bytes in UTF-8 (2*2=4). Might not work perfectly in edge cases
 23+ // such as illegal sequences, but that should never happen.
 24+
 25+ len = this.value.replace(/[\u0080-\u07FF\uD800-\uDFFF]/g, '**').replace(/[\u0800-\uD7FF\uE000-\uFFFF]/g, '***').length;
 26+ //247 as this doesn't count character about to be inserted.
 27+ if (len > 247) {
 28+ e.preventDefault();
 29+ }
 30+});
 31+
Index: trunk/phase3/resources/Resources.php
@@ -353,6 +353,9 @@
354354 'scripts' => 'resources/mediawiki.action/mediawiki.action.history.js',
355355 'dependencies' => 'mediawiki.legacy.history',
356356 ),
 357+ 'mediawiki.action.edit' => array(
 358+ 'scripts' => 'resources/mediawiki.action/mediawiki.action.edit.js',
 359+ ),
357360 'mediawiki.action.view.rightClickEdit' => array(
358361 'scripts' => 'resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js',
359362 ),

Follow-up revisions

RevisionCommit summaryAuthorDate
r80575Followup r80554: coding style, add varcatrope17:49, 19 January 2011
r80576Followup r80554, r80575: wrap in (function( $ ) { ... })(jQuery);catrope17:50, 19 January 2011
r806771.17: MFT r80109, r80113, r80223, r80475, r80554, r80575, r80620, r80621, r80...catrope03:12, 21 January 2011
r83067(follow-up r80554) If person typed max amount in edit summary, backspace didn...bawolff03:57, 2 March 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r66913(bug 22967) Use javascript to make the maxlength of the edit summary field wo...bawolff09:10, 26 May 2010

Comments

#Comment by Bawolff (talk | contribs)   04:03, 19 January 2011

I'm tagging this 1.17 as its a follow-up to a fixme of a revision that is in 1.17, so I assume i should tag. (Of course the only real changes from the version in 1.17 is stylistic. It wasn't really broken before).

Status & tagging log