r90969 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90968‎ | r90969 | r90970 >
Date:15:32, 28 June 2011
Author:janpaul123
Status:ok
Tags:
Comment:
Added error messages when API calls fail.
Modified paths:
  • /trunk/extensions/WikiLove/WikiLove.api.php (modified) (history)
  • /trunk/extensions/WikiLove/WikiLove.i18n.php (modified) (history)
  • /trunk/extensions/WikiLove/WikiLove.php (modified) (history)
  • /trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js (modified) (history)

Diff [purge]

Index: trunk/extensions/WikiLove/WikiLove.php
@@ -129,6 +129,8 @@
130130 'wikilove-commons-text',
131131 'wikilove-commons-link',
132132 'wikilove-commons-url',
 133+ 'wikilove-err-preview-api',
 134+ 'wikilove-err-send-api',
133135 ),
134136 'dependencies' => array(
135137 'jquery.ui.dialog',
Index: trunk/extensions/WikiLove/WikiLove.api.php
@@ -31,14 +31,12 @@
3232 'notminor' => true,
3333 ), false, array( 'wsEditToken' => $wgRequest->getSessionData( 'wsEditToken' ) ) ), true );
3434
 35+ $api->execute();
 36+
3537 if ( isset( $params['email'] ) ) {
3638 $this->emailUser( $talk, $params['subject'], $params['email'], $params['token'] );
3739 }
3840
39 - $api->execute();
40 -
41 - $result = $api->getResult();
42 -
4341 $this->getResult()->addValue( 'redirect', 'pageName', $talk->getPrefixedDBkey() );
4442 $this->getResult()->addValue( 'redirect', 'fragment', Title::escapeFragmentForURL( $params['subject'] ) );
4543 // note that we cannot use Title::makeTitle here as it doesn't sanitize the fragment
Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js
@@ -328,7 +328,7 @@
329329
330330 // Check for a header if it is required
331331 if( $.inArray( 'header', currentTypeOrSubtype.fields ) >= 0 && $( '#mw-wikilove-header' ).val().length <= 0 ) {
332 - $.wikiLove.showError( 'wikilove-err-header' ); return false;
 332+ $.wikiLove.showAddDetailsError( 'wikilove-err-header' ); return false;
333333 }
334334
335335 // Check for a title if it is required, and otherwise use the header text
@@ -339,12 +339,12 @@
340340 if( $.inArray( 'message', currentTypeOrSubtype.fields ) >= 0 ) {
341341 // Check for a message if it is required
342342 if ( $( '#mw-wikilove-message' ).val().length <= 0 ) {
343 - $.wikiLove.showError( 'wikilove-err-msg' ); return false;
 343+ $.wikiLove.showAddDetailsError( 'wikilove-err-msg' ); return false;
344344 }
345345
346346 // If there isn't a signature already in the message, throw an error
347347 if ( $( '#mw-wikilove-message' ).val().indexOf( '~~~' ) >= 0 ) {
348 - $.wikiLove.showError( 'wikilove-err-sig' ); return false;
 348+ $.wikiLove.showAddDetailsError( 'wikilove-err-sig' ); return false;
349349 }
350350 }
351351
@@ -371,7 +371,7 @@
372372 success: function( data ) {
373373 if ( !data.query.pages[-1].imageinfo ) {
374374 // Image does not exist
375 - $.wikiLove.showError( 'wikilove-err-image-bad' );
 375+ $.wikiLove.showAddDetailsError( 'wikilove-err-image-bad' );
376376 $( '#mw-wikilove-preview-spinner' ).fadeOut( 200 );
377377 } else {
378378 // Image exists. Proceed with preview.
@@ -379,7 +379,7 @@
380380 }
381381 },
382382 error: function() {
383 - $.wikiLove.showError( 'wikilove-err-image-api' );
 383+ $.wikiLove.showAddDetailsError( 'wikilove-err-image-api' );
384384 $( '#mw-wikilove-preview-spinner' ).fadeOut( 200 );
385385 }
386386 } );
@@ -387,7 +387,7 @@
388388 } else { // a gallery
389389 if ( $( '#mw-wikilove-image' ).val().length <= 0 ) {
390390 // Display an error telling them to select an image.
391 - $.wikiLove.showError( 'wikilove-err-image' ); return false;
 391+ $.wikiLove.showAddDetailsError( 'wikilove-err-image' ); return false;
392392 } else {
393393 // Proceed with preview.
394394 $.wikiLove.submitPreview();
@@ -417,10 +417,14 @@
418418 }
419419 },
420420
421 - showError: function( errmsg ) {
 421+ showAddDetailsError: function( errmsg ) {
422422 $( '#mw-wikilove-add-details' ).append( $( '<div class="mw-wikilove-error"></div>' ).text( mw.msg( errmsg ) ) );
423423 },
424424
 425+ showPreviewError: function( errmsg ) {
 426+ $( '#mw-wikilove-preview' ).append( $( '<div class="mw-wikilove-error"></div>' ).text( mw.msg( errmsg ) ) );
 427+ },
 428+
425429 /*
426430 * Prepares a message or e-mail body by replacing placeholders.
427431 * $1: message entered by the user
@@ -475,6 +479,10 @@
476480 success: function( data ) {
477481 $.wikiLove.showPreview( data.parse.text['*'] );
478482 $( '#mw-wikilove-preview-spinner' ).fadeOut( 200 );
 483+ },
 484+ error: function() {
 485+ $.wikiLove.showAddDetailsError( 'wikilove-err-preview-api' );
 486+ $( '#mw-wikilove-preview-spinner' ).fadeOut( 200 );
479487 }
480488 });
481489 },
@@ -548,7 +556,7 @@
549557 $( '#mw-wikilove-send-spinner' ).fadeOut( 200 );
550558
551559 if ( typeof data.error !== 'undefined' ) {
552 - $( '#mw-wikilove-preview' ).append( '<div class="mw-wikilove-error">' + mw.html.escape( data.error.info ) + '<div>' );
 560+ $.wikiLove.showPreviewError( data.error.info );
553561 return;
554562 }
555563
@@ -563,6 +571,10 @@
564572 mw.config.get( 'wgArticlePath' ).replace( '$1', mw.util.wikiUrlencode( data.redirect.pageName ) )
565573 + '#' + data.redirect.fragment );
566574 }
 575+ },
 576+ error: function() {
 577+ $.wikiLove.showPreviewError( 'wikilove-err-send-api' );
 578+ $( '#mw-wikilove-send-spinner' ).fadeOut( 200 );
567579 }
568580 });
569581 },
Index: trunk/extensions/WikiLove/WikiLove.i18n.php
@@ -41,10 +41,12 @@
4242 'wikilove-err-msg' => 'Please enter a message.',
4343 'wikilove-err-image' => 'Please select an image.',
4444 'wikilove-err-image-bad' => 'Image does not exist.',
45 - 'wikilove-err-image-api' => 'Image check failed.',
 45+ 'wikilove-err-image-api' => 'Something went wrong when retrieving the image. Please try again.',
4646 'wikilove-err-sig' => 'Please do not include a signature in the message.',
47 - 'wikilove-err-gallery' => 'Something went wrong when loading the images!',
 47+ 'wikilove-err-gallery' => 'Something went wrong when loading the images.',
4848 'wikilove-err-gallery-again' => 'Try again',
 49+ 'wikilove-err-preview-api' => 'Something went wrong during previewing. Please try again.',
 50+ 'wikilove-err-send-api' => 'Something went wrong when sending the message. Please try again.',
4951 'wikilove-summary' => '/* $1 */ new WikiLove message',
5052 'wikilove-what-is-this' => "What is this?",
5153 'wikilove-anon-warning' => 'Note: This user is not registered, he or she many not notice this message.',

Status & tagging log