r88180 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88179‎ | r88180 | r88181 >
Date:14:11, 15 May 2011
Author:janpaul123
Status:ok
Tags:
Comment:
Some more refactoring
Modified paths:
  • /trunk/extensions/WikiLove/wikiLove.css (modified) (history)
  • /trunk/extensions/WikiLove/wikiLove.js (modified) (history)

Diff [purge]

Index: trunk/extensions/WikiLove/wikiLove.css
@@ -231,6 +231,7 @@
232232 #wikiLoveDialog #wlAddDetails {
233233 float: right;
234234 width: 480px;
 235+ margin-bottom: 5px;
235236 }
236237
237238 #wikiLoveDialog #wlAddDetails label {
@@ -346,5 +347,13 @@
347348 }
348349
349350 #wikiLoveDialog .wlError {
 351+ /* @embed */
 352+ background-image: url(images/alert.png);
 353+ background-position: center left;
 354+ background-repeat: no-repeat;
350355 color: red;
 356+ font-weight: bold;
 357+ line-height: 32px;
 358+ padding-left: 34px;
 359+ padding-bottom: 3px;
351360 }
Index: trunk/extensions/WikiLove/wikiLove.js
@@ -29,11 +29,11 @@
3030 'cat': {
3131 descr: 'Cat',
3232 title: null,
33 - text: "[[$3|left|150px]]\n$1\n\n~~~~", // $3 is the image filename
 33+ text: '[[$3|left|150px]]\n$1\n\n~~~~\n<br style="clear: both"/>', // $3 is the image filename
3434 template: '',
3535 gallery: {
3636 // right now we can only query the local wiki (not e.g. commons)
37 - category: 'Category:Tropical',
 37+ category: 'Category:Cat',
3838 total: 100, // total number of pictures to retrieve, and to randomise
3939 num: 3, // number of pictures to show from the randomised set
4040 width: 150 // width of each picture in pixels in the interface (not in the template)
@@ -144,7 +144,7 @@
145145 .append( '<label for="wlMessage" id="wlMessageLabel">' + mw.msg( 'wikilove-enter-message' ) + '</label>' )
146146 .append( '<span class="wlOmitSig">' + mw.msg( 'wikilove-omit-sig' ) + '</span>' )
147147 .append( '<textarea id="wlMessage"></textarea>' )
148 - .append( $('<div id="wlNotify"></div>').html('<input type="checkbox" id="wlNotifyCheckbox" name="notify"/> Notify user by email') )
 148+ .append( $('<div id="wlNotify"></div>').html('<input type="checkbox" id="wlNotifyCheckbox" name="notify"/> <label for="wlNotifyCheckbox">Notify user by email</label>') )
149149 .append( '<input id="wlButtonPreview" class="submit" type="submit" value="'
150150 + mw.msg( 'wikilove-button-preview' ) + '"/>' )
151151 .append( '<img class="wlSpinner" src="' + mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' )
@@ -292,6 +292,8 @@
293293 * Called when type or subtype changes, updates controls. Currently only updates title label and textbox.
294294 */
295295 updateAllDetails: function() {
 296+ $( '#wikiLoveDialog' ).find( '.wlError' ).remove();
 297+
296298 // show or hide title label and textbox depending on whether a predefined title exists
297299 if( typeof $.wikiLove.currentTypeOrSubtype.title == 'string' ) {
298300 $( '#wlTitleLabel').hide();
@@ -326,26 +328,27 @@
327329 */
328330 submitPreview: function( e ) {
329331 e.preventDefault();
 332+ $( '#wlPreview' ).hide();
 333+ $( '#wikiLoveDialog' ).find( '.wlError' ).remove();
 334+
 335+ if( typeof $.wikiLove.currentTypeOrSubtype.gallery == 'object' ) {
 336+ if ( !$.wikiLove.imageTitle ) {
 337+ $.wikiLove.showError( 'wikilove-err-image' ); return false;
 338+ }
 339+ }
330340 if( $( '#wlTitle' ).val().length <= 0 ) {
331341 $.wikiLove.showError( 'wikilove-err-title' ); return false;
332342 }
333343 if( $( '#wlMessage' ).val().length <= 0 ) {
334344 $.wikiLove.showError( 'wikilove-err-msg' ); return false;
335345 }
336 - if( typeof $.wikiLove.currentTypeOrSubtype.gallery == 'object' ) {
337 - if ( !$.wikiLove.imageTitle ) {
338 - $.wikiLove.showError( 'wikilove-err-img' ); return false;
339 - }
340 - }
341346
342 - var rawMessage = $( '#wlMessage' ).val();
343 -
344347 // If there isn't a signature already in the message, throw an error
345 - if ( rawMessage.indexOf( '~~~' ) >= 0 ) {
 348+ if ( $( '#wlMessage' ).val().indexOf( '~~~' ) >= 0 ) {
346349 $.wikiLove.showError( 'wikilove-err-sig' ); return false;
347350 }
348351
349 - var msg = $.wikiLove.prepareMsg( rawMessage );
 352+ var msg = $.wikiLove.prepareMsg( $.wikiLove.currentTypeOrSubtype.text );
350353
351354 $.wikiLove.doPreview( '==' + $( '#wlTitle' ).val() + "==\n" + msg );
352355 $.wikiLove.previewData = {
@@ -360,7 +363,7 @@
361364 },
362365
363366 showError: function( errmsg ) {
364 - $.wikiLove.showPreview( mw.msg( errmsg ) );
 367+ $( '#wlAddDetails' ).append( $( '<div class="wlError"></div>' ).html( mw.msg( errmsg ) ) );
365368 },
366369
367370 /*
@@ -447,9 +450,6 @@
448451 dataType: 'json',
449452 type: 'POST',
450453 success: function( data ) {
451 - mw.log( data );
452 - mw.log( 'wgPageName: ' + mw.config.get( 'wgPageName' ) );
453 -
454454 if ( notify && $.wikiLove.emailable ) {
455455 $.wikiLove.sendEmail(
456456 $.wikiLove.currentTypeOrSubtype.title,
@@ -459,6 +459,11 @@
460460
461461 $( '#wlPreview .wlSpinner' ).fadeOut( 200 );
462462
 463+ if ( typeof data.error !== 'undefined' ) {
 464+ $( '#wlPreview' ).append( '<div class="wlError">' + data.error.info + '<div>' );
 465+ return;
 466+ }
 467+
463468 if ( typeof data.redirect !== 'undefined'
464469 && data.redirect.pageName == mw.config.get( 'wgPageName' ) ) {
465470 // unfortunately, when on the talk page we cannot reload and then
@@ -466,10 +471,6 @@
467472 // the page won't reload...
468473 window.location.reload();
469474 }
470 - else if ( typeof data.error !== 'undefined' ) {
471 - $( '<div class="wlError">' + data.error.info + '<div>' ).insertBefore( '#wlSendForm' );
472 - window.location.reload();
473 - }
474475 else {
475476 window.location = mw.config.get( 'wgArticlePath' ).replace('$1', data.redirect.pageName)
476477 + data.redirect.fragment;

Status & tagging log