r50761 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50760‎ | r50761 | r50762 >
Date:23:42, 18 May 2009
Author:dale
Status:deferred
Tags:
Comment:
a bit better checking for odd json results
Modified paths:
  • /branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvUploader.js (modified) (history)

Diff [purge]

Index: branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvUploader.js
@@ -328,16 +328,18 @@
329329 if( tmpAryData[i]['name'] )
330330 _this.formData[ tmpAryData[i]['name'] ] = tmpAryData[i]['value'];
331331 }
332 -
333 - //get a clean loader:
334 - _this.dispProgressOverlay();
335 -
336 - //for some unknown reason we have to drop down the #p-search z-index:
337 - $j('#p-search').css('z-index', 1);
338 -
339 - //select upload mode:
340 - _this.detectUploadMode();
341 -
 332+ //put into a try catch so we are sure to return false:
 333+ try{
 334+ //get a clean loader:
 335+ _this.dispProgressOverlay();
 336+
 337+ //for some unknown reason we have to drop down the #p-search z-index:
 338+ $j('#p-search').css('z-index', 1);
 339+
 340+ //select upload mode:
 341+ _this.detectUploadMode();
 342+ }catch(e){}
 343+
342344 //don't submit the form we will do the post in ajax
343345 return false;
344346 };
@@ -422,11 +424,10 @@
423425 'action' : 'upload',
424426 'url' : $j('#wpUploadFileURL').val(),
425427 'filename' : $j('#wpDestFile').val(),
426 - 'comment' : $j('#wpUploadDescription').val(),
427 - 'asyncdownload': 'true'
 428+ 'comment' : $j('#wpUploadDescription').val()
428429 },
429430 'url' : _this.api_url
430 - }, function( data ){
 431+ }, function( data ){
431432 _this.processApiResult( data );
432433 });
433434 },
@@ -518,6 +519,7 @@
519520 },
520521 processApiResult: function( apiRes ){
521522 var _this = this;
 523+
522524 //check for upload api error:
523525 // {"upload":{"result":"Failure","error":"unknown-error","code":{"status":5,"filtered":"NGC2207%2BIC2163.jpg"}}}
524526 if( apiRes.error || ( apiRes.upload && apiRes.upload.result == "Failure" ) ){
@@ -545,28 +547,33 @@
546548 //error space is too large so we don't front load it
547549 //do a remote call to get the error msg:
548550 if(!error_code || error_code == 'unknown-error'){
549 - js_log('Error: apiRes: ' + JSON.stringify( apiRes) );
 551+ if(typeof JSON != 'undefined'){
 552+ js_log('Error: apiRes: ' + JSON.stringify( apiRes) );
 553+ }
550554 _this.updateUploadError( gM('unknown-error') + '<br>' + error_msg);
551555 }else{
552556 gMsgLoadRemote(error_code, function(){
553557 js_log('send msg: ' + gM( error_code ));
554558 _this.updateUploadError( gM( error_code ));
555559 });
556 - }
 560+ }
 561+ js_log("api.erorr");
557562 return ;
558563 }
559564 //check for upload_session key for async upload:
560565 if( apiRes.upload && apiRes.upload.upload_session_key ){
561566 //set the session key
562567 _this.upload_session_key = apiRes.upload.upload_session_key;
563 - js_log("set session key: " + _this.upload_session_key);
 568+
564569 //do ajax upload status:
565 - _this.doAjaxUploadStatus();
 570+ _this.doAjaxUploadStatus();
 571+ js_log("set upload_session_key: " + _this.upload_session_key);
566572 return ;
567573 }
568574
569575 if( apiRes.upload.imageinfo && apiRes.upload.imageinfo.descriptionurl ){
570576 _this.updateUploadDone( apiRes.upload.imageinfo.descriptionurl );
 577+ js_log('apiRes.upload.imageinfo:: updateUploadDone');
571578 return ;
572579 }
573580
@@ -576,7 +583,8 @@
577584 return ;
578585 }
579586 //check for known warnings:
580 - if( apiRes.upload.warnings ){
 587+ if( apiRes.upload.warnings ){
 588+ //debugger;
581589 var wmsg = '<ul>';
582590 for(var wtype in apiRes.upload.warnings){
583591 var winfo = apiRes.upload.warnings[wtype]
@@ -584,8 +592,13 @@
585593 switch(wtype){
586594 case 'duplicate':
587595 case 'exists':
588 - wmsg += gM('file-exists-duplicate') +' '+
589 - '<b>' + winfo[1].title.mTextform + '</b>';
 596+ if(winfo[1] && winfo[1].title && winfo[1].title.mTextform){
 597+ wmsg += gM('file-exists-duplicate') +' '+
 598+ '<b>' + winfo[1].title.mTextform + '</b>';
 599+ }else{
 600+ //misc error (weird that winfo[1] not present
 601+ wmsg += gM('upload-misc-error') + ' ' + wtype;
 602+ }
590603 break;
591604 case 'file-thumbnail-no':
592605 wmsg += gM('file-thumbnail-no', winfo);
@@ -664,5 +677,7 @@
665678 '<div id="dlbox-overlay" class="dlbox-overlay" style="background:#000;cursor:wait;height:100%;'+
666679 'left:0;top:0;position:fixed;width:100%;z-index:99;filter:alpha(opacity=60);'+
667680 '-moz-opacity: 0.6; opacity: 0.6;" ></div>');
 681+ //fade them in:
 682+ $j('#dlbox-centered,#dlbox-overlay').show();
668683 }
669684 }

Status & tagging log