Index: trunk/extensions/WikiLove/WikiLove.php |
— | — | @@ -118,6 +118,8 @@ |
119 | 119 | 'wikilove-err-title', |
120 | 120 | 'wikilove-err-msg', |
121 | 121 | 'wikilove-err-image', |
| 122 | + 'wikilove-err-image-bad', |
| 123 | + 'wikilove-err-image-api', |
122 | 124 | 'wikilove-err-sig', |
123 | 125 | 'wikilove-err-gallery', |
124 | 126 | 'wikilove-err-gallery-again', |
Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js |
— | — | @@ -126,7 +126,7 @@ |
127 | 127 | $( '#mw-wikilove-gallery-error-again' ).click( $.wikiLove.showGallery ); |
128 | 128 | $( '#mw-wikilove-types a' ).click( $.wikiLove.clickType ); |
129 | 129 | $( '#mw-wikilove-subtype' ).change( $.wikiLove.changeSubtype ); |
130 | | - $( '#mw-wikilove-preview-form' ).submit( $.wikiLove.submitPreview ); |
| 130 | + $( '#mw-wikilove-preview-form' ).submit( $.wikiLove.validatePreviewForm ); |
131 | 131 | $( '#mw-wikilove-send-form' ).click( $.wikiLove.submitSend ); |
132 | 132 | $( '#mw-wikilove-message' ).elastic(); // have the message textarea grow automatically |
133 | 133 | } |
— | — | @@ -262,21 +262,13 @@ |
263 | 263 | }, |
264 | 264 | |
265 | 265 | /* |
266 | | - * Handler for clicking the preview button. Builds data for AJAX request. |
| 266 | + * Handler for clicking the preview button. |
267 | 267 | */ |
268 | | - submitPreview: function( e ) { |
| 268 | + validatePreviewForm: function( e ) { |
269 | 269 | e.preventDefault(); |
270 | 270 | $( '#mw-wikilove-preview' ).hide(); |
271 | 271 | $( '#mw-wikilove-dialog' ).find( '.mw-wikilove-error' ).remove(); |
272 | 272 | |
273 | | - |
274 | | - if ( $( '#mw-wikilove-image' ).val().length <= 0 ) { |
275 | | - if( typeof currentTypeOrSubtype.gallery == 'object' ) { |
276 | | - $.wikiLove.showError( 'wikilove-err-image' ); return false; |
277 | | - } else { |
278 | | - $( '#mw-wikilove-image' ).val( options.defaultImage ); |
279 | | - } |
280 | | - } |
281 | 273 | if( $( '#mw-wikilove-header' ).val().length <= 0 ) { |
282 | 274 | $.wikiLove.showError( 'wikilove-err-header' ); return false; |
283 | 275 | } |
— | — | @@ -290,6 +282,53 @@ |
291 | 283 | $.wikiLove.showError( 'wikilove-err-sig' ); return false; |
292 | 284 | } |
293 | 285 | |
| 286 | + // Split image validation depending on whether or not it is a gallery |
| 287 | + if ( typeof currentTypeOrSubtype.gallery == 'undefined' ) { // not a gallery |
| 288 | + if ( $( '#mw-wikilove-image' ).val().length <= 0 ) { |
| 289 | + // Give them the default image and continue with preview. |
| 290 | + $( '#mw-wikilove-image' ).val( options.defaultImage ); |
| 291 | + $.wikiLove.submitPreview(); |
| 292 | + } else { |
| 293 | + // Make sure the image exists |
| 294 | + var imageTitle = $.wikiLove.addFilePrefix( $( '#mw-wikilove-image' ).val() ); |
| 295 | + $.ajax( { |
| 296 | + url: mw.util.wikiScript( 'api' ), |
| 297 | + data: { |
| 298 | + 'action': 'query', |
| 299 | + 'format': 'json', |
| 300 | + 'titles': imageTitle, |
| 301 | + 'prop': 'imageinfo' |
| 302 | + }, |
| 303 | + dataType: 'json', |
| 304 | + success: function( data ) { |
| 305 | + if ( !data.query.pages[-1].imageinfo ) { |
| 306 | + // Image does not exist |
| 307 | + $.wikiLove.showError( 'wikilove-err-image-bad' ); |
| 308 | + } else { |
| 309 | + // Image exists. Proceed with preview. |
| 310 | + $.wikiLove.submitPreview(); |
| 311 | + } |
| 312 | + }, |
| 313 | + error: function( xhr ) { |
| 314 | + $.wikiLove.showError( 'wikilove-err-image-api' ); |
| 315 | + } |
| 316 | + } ); |
| 317 | + } |
| 318 | + } else { // a gallery |
| 319 | + if ( $( '#mw-wikilove-image' ).val().length <= 0 ) { |
| 320 | + // Display an error telling them to select an image. |
| 321 | + $.wikiLove.showError( 'wikilove-err-image' ); return false; |
| 322 | + } else { |
| 323 | + // Proceed with preview. |
| 324 | + $.wikiLove.submitPreview(); |
| 325 | + } |
| 326 | + } |
| 327 | + }, |
| 328 | + |
| 329 | + /* |
| 330 | + * After the form is validated, perform preview, and build data for the final AJAX request. |
| 331 | + */ |
| 332 | + submitPreview: function() { |
294 | 333 | var text = $.wikiLove.prepareMsg( currentTypeOrSubtype.text || options.defaultText ); |
295 | 334 | |
296 | 335 | $.wikiLove.doPreview( '==' + $( '#mw-wikilove-header' ).val() + "==\n" + text ); |
— | — | @@ -376,7 +415,7 @@ |
377 | 416 | }, |
378 | 417 | |
379 | 418 | /* |
380 | | - * Handler for the send (final submit) button. Builds data for AJAX request. |
| 419 | + * Handler for the send (final submit) button. |
381 | 420 | * The type sent for statistics is 'typeId-subtypeId' when using subtypes, |
382 | 421 | * or simply 'typeId' otherwise. |
383 | 422 | */ |
Index: trunk/extensions/WikiLove/WikiLove.i18n.php |
— | — | @@ -39,6 +39,8 @@ |
40 | 40 | 'wikilove-err-title' => 'Please enter a title.', |
41 | 41 | 'wikilove-err-msg' => 'Please enter a message.', |
42 | 42 | 'wikilove-err-image' => 'Please select an image.', |
| 43 | + 'wikilove-err-image-bad' => 'Image does not exist.', |
| 44 | + 'wikilove-err-image-api' => 'Image check failed.', |
43 | 45 | 'wikilove-err-sig' => 'Please do not include a signature in the message.', |
44 | 46 | 'wikilove-err-gallery' => 'Something went wrong when loading the images!', |
45 | 47 | 'wikilove-err-gallery-again' => 'Try again', |