r91046 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91045‎ | r91046 | r91047 >
Date:02:15, 29 June 2011
Author:kaldari
Status:ok (Comments)
Tags:
Comment:
adding a couple more validators to submitSend since we are doing just-in-time now - extra safe
Modified paths:
  • /trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js (modified) (history)

Diff [purge]

Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js
@@ -489,17 +489,34 @@
490490 },
491491
492492 /*
493 - * Handler for the send (final submit) button.
 493+ * Handler for the send (final submit) button. Builds the data for the AJAX request.
494494 * The type sent for statistics is 'typeId-subtypeId' when using subtypes,
495495 * or simply 'typeId' otherwise.
496496 */
497497 submitSend: function( e ) {
498498 e.preventDefault();
499499 $( '#mw-wikilove-dialog' ).find( '.mw-wikilove-error' ).remove();
 500+
500501 // Check for a header if it is required
501502 if( $.inArray( 'header', currentTypeOrSubtype.fields ) >= 0 && $( '#mw-wikilove-header' ).val().length <= 0 ) {
502503 $.wikiLove.showAddDetailsError( 'wikilove-err-header' ); return false;
503504 }
 505+
 506+ // Check for a title if it is required, and otherwise use the header text
 507+ if( $.inArray( 'title', currentTypeOrSubtype.fields ) >= 0 && $( '#mw-wikilove-title' ).val().length <= 0 ) {
 508+ $( '#mw-wikilove-title' ).val( $( '#mw-wikilove-header' ).val() );
 509+ }
 510+
 511+ if( $.inArray( 'message', currentTypeOrSubtype.fields ) >= 0 ) {
 512+ // If there's a signature already in the message, throw an error
 513+ if ( $( '#mw-wikilove-message' ).val().indexOf( '~~~' ) >= 0 ) {
 514+ $.wikiLove.showAddDetailsError( 'wikilove-err-sig' ); return false;
 515+ }
 516+ }
 517+
 518+ // We don't need to do any image validation here since its not actually possible to click
 519+ // Send WikiLove without having a valid image entered.
 520+
504521 var submitData = {
505522 'header': $( '#mw-wikilove-header' ).val(),
506523 'text': $.wikiLove.prepareMsg( currentTypeOrSubtype.text || options.defaultText ),

Follow-up revisions

RevisionCommit summaryAuthorDate
r91083WikiLove minor fixes:...krinkle17:29, 29 June 2011

Comments

#Comment by Krinkle (talk | contribs)   17:55, 29 June 2011
+ ... $( '#mw-wikilove-title' ).val().length <= 0  )

val() always returns a string so the length property is always available and returns atleast 0 (or higher). I removed the "less than" in r91083 as it can't be less than 0 afaik (unlike indexOf).

#Comment by Kaldari (talk | contribs)   19:04, 29 June 2011

Looks like you're right. If the input isn't found, the val is actually undefined.

#Comment by Krinkle (talk | contribs)   19:34, 29 June 2011

yeah, from jQuery source (simplified)

if ( elems[0] ) {
	return elem.value || ""
}
return undefined;

Status & tagging log