r52861 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52860‎ | r52861 | r52862 >
Date:21:31, 7 July 2009
Author:dale
Status:deferred
Tags:
Comment:
updated firefogg /uploader error handling
Modified paths:
  • /branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js (modified) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvFirefogg.js (modified) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/libEmbedVideo/embedVideo.js (modified) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/libSequencer/mvPlayList.js (modified) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/mv_embed.js (modified) (history)

Diff [purge]

Index: branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvFirefogg.js
@@ -10,7 +10,7 @@
1111 "fogg-installed" : "Firefogg is Installed",
1212 "fogg-for_improved_uplods" : "For Improved uploads: ",
1313 "fogg-please_install" : "<a href=\"$1\">Install Firefogg</a>. More <a href=\"http://commons.wikimedia.org/wiki/Commons:Firefogg\">about firefogg</a>",
14 - "fogg-use_latest_fox" : "Please first install <a href=\"http://www.mozilla.com/en-US/firefox/upgrade.html?from=mv_embed\">Firefox 3.5</a>. <i>then revisit this page to install the <b>firefogg</b> extention</i>",
 14+ "fogg-use_latest_fox" : "Please first install <a href=\"http://www.mozilla.com/en-US/firefox/upgrade.html?from=firefogg\">Firefox 3.5</a>. <i>then revisit this page to install the <b>firefogg</b> extention</i>",
1515 "fogg-passthrough_mode" : "Your selected file is already ogg or not a video file",
1616 "fogg-transcoding" : "Encoding Video to Ogg",
1717 "fogg-encoding-done" : "Encoding Done"
@@ -495,8 +495,7 @@
496496 _this.formData[ 'wpSourceType' ] = 'upload';
497497 _this.formData[ 'action' ] = 'submit';
498498 //wpUploadFile is set by firefogg
499 - delete _this.formData[ 'wpUploadFile' ];
500 -
 499+ delete _this.formData[ 'wpUploadFile' ];
501500
502501 _this.fogg.post( _this.editForm.action, 'wpUploadFile', JSON.stringify( _this.formData ) );
503502 //update upload status:
@@ -515,7 +514,7 @@
516515 var uploadStatus = function(){
517516 //get the response text:
518517 var response_text = _this.fogg.responseText;
519 - if( !response_text){
 518+ if(!response_text){
520519 try{
521520 var pstatus = JSON.parse( _this.fogg.uploadstatus() );
522521 response_text = pstatus["responseText"];
@@ -527,16 +526,31 @@
528527 if( _this.oldResponseText != response_text){
529528 js_log('new result text:' + response_text + ' state:' + _this.fogg.state);
530529 _this.oldResponseText = response_text;
531 - //try and pare the response see if we need to take action:
532 - }
 530+ //try and parse the response text and check for errors
 531+ try{
 532+ var apiResult = JSON.parse( response_text );
 533+ }catch(e){
 534+ js_log("could not parse response_text::" + response_text + ' ...for now try with eval...');
 535+ try{
 536+ var apiResult = eval( response_text );
 537+ }catch(e){
 538+ var apiResult = null;
 539+ }
 540+ }
 541+ if(apiResult && _this.apiUpdateErrorCheck( apiResult ) === false){
 542+ //stop status update we have an error
 543+ _this.fogg.cancel();
 544+ return false;
 545+ }
 546+ }
533547 //update progress bar
534548 _this.updateProgress( _this.fogg.progress() );
535549
536550 //loop to get new status if still uploading (could also be encoding if we are in chunk upload mode)
537551 if( _this.fogg.state == 'encoding' || _this.fogg.state == 'uploading') {
538552 setTimeout(uploadStatus, 100);
539 - }
540 - //check upload state
 553+
 554+ }//check upload state
541555 else if( _this.fogg.state == 'upload done' ||
542556 _this.fogg.state == 'done' ||
543557 _this.fogg.state == 'encoding done' ) {
Index: branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js
@@ -31,6 +31,8 @@
3232 "ignorewarning" : "Ignore warning and save file anyway",
3333 "file-thumbnail-no" : "The filename begins with <b><tt>$1</tt></b>",
3434 "go-to-resource" : "Go to Resource Page",
 35+
 36+ "wgfogg_waring_bad_extension" : "You have selected a file with an unsuported extension (<a href=\"http://commons.wikimedia.org/wiki/Commons:Firefogg#Supported_File_Types\">more information</a>).",
3537
3638 "cancel-button" : "Cancel",
3739 "ok-button" : "OK"
@@ -320,15 +322,16 @@
321323 }
322324 uploadStatus();
323325 },
324 - processApiResult: function( apiRes ){
325 - var _this = this;
326 - js_log('processApiResult::');
327 - //check for upload api error:
328 - // {"upload":{"result":"Failure","error":"unknown-error","code":{"status":5,"filtered":"NGC2207%2BIC2163.jpg"}}}
 326+ apiUpdateErrorCheck:function( apiRes ){
 327+ var _this = this;
329328 if( apiRes.error || ( apiRes.upload && apiRes.upload.result == "Failure" ) ){
330 -
 329+ //gennerate the error button:
 330+ var bObj = {};
 331+ bObj[ gM('return-to-form') ] = function(){
 332+ $j(this).dialog('close');
 333+ };
331334 //check a few places for the error code:
332 - var error_code=0;
 335+ var error_code=0;
333336 if( apiRes.error && apiRes.error.code ){
334337 error_code = apiRes.error.code;
335338 }else if( apiRes.upload.code ){
@@ -337,7 +340,7 @@
338341 error_code = apiRes.upload.code[0];
339342 }
340343 if(apiRes.upload.code['status']){
341 - error_code = apiRes.upload['status'];
 344+ error_code = apiRes.upload.code['status'];
342345 }
343346 }else{
344347 apiRes.upload.code;
@@ -352,68 +355,44 @@
353356 if(!error_code || error_code == 'unknown-error'){
354357 if(typeof JSON != 'undefined'){
355358 js_log('Error: apiRes: ' + JSON.stringify( apiRes) );
356 - }
357 - var bObj = {};
358 - bObj[ gM('return-to-form') ] = function(){
359 - $j(this).dialog('close');
360 - };
 359+ }
 360+ js_log('should update win::');
361361 _this.updateProgressWin( gM('uploaderror'), gM('unknown-error') + '<br>' + error_msg, bObj);
362 - return ;
 362+ return false;
363363 }else{
364 - if( apiRes.error.info ){
 364+ if(apiRes.error && apiRes.error.info ){
365365 _this.updateProgressWin( gM('uploaderror'), apiRes.error.info ,bObj);
366 - return ;
 366+ return false;
367367 }else{
368 - gMsgLoadRemote(error_code, function(){
369 - js_log('send msg: ' + gM( error_code ));
370 - var bObj = {};
371 - bObj[gM('return-to-form')] = function(){
372 - $(this).dialog('close');
373 - };
374 - _this.updateProgressWin( gM('uploaderror'), gM( error_code ),bObj);
375 - });
376 - js_log("api.erorr");
377 - return ;
 368+ if(typeof error_code == 'number'){
 369+ if(apiRes.upload.code.finalExt){
 370+ _this.updateProgressWin( gM('uploaderror'), gM('wgfogg_waring_bad_extension',apiRes.upload.code.finalExt) , bObj);
 371+ }else{
 372+ _this.updateProgressWin( gM('uploaderror'), gM('unknown-error') + ' : ' + error_code, bObj);
 373+ }
 374+ }else{
 375+ gMsgLoadRemote(error_code, function(){
 376+ js_log('send msg: ' + gM( error_code ));
 377+ var bObj = {};
 378+ bObj[gM('return-to-form')] = function(){
 379+ $(this).dialog('close');
 380+ };
 381+ _this.updateProgressWin( gM('uploaderror'), gM( error_code ),bObj);
 382+ });
 383+ js_log("api.erorr");
 384+ }
 385+ return false;
378386 }
379387 }
380 - }
381 - //check for upload_session key for async upload:
382 - if( apiRes.upload && apiRes.upload.upload_session_key ){
383 - //set the session key
384 - _this.upload_session_key = apiRes.upload.upload_session_key;
385 -
386 - //do ajax upload status:
387 - _this.doAjaxUploadStatus();
388 - js_log("set upload_session_key: " + _this.upload_session_key);
389 - return ;
390 - }
391 -
392 - if( apiRes.upload.imageinfo && apiRes.upload.imageinfo.descriptionurl ){
393 - var url = apiRes.upload.imageinfo.descriptionurl;
394 - //check done action:
395 - if(_this.done_upload_cb){
396 - //close up shop:
397 - $j('#upProgressDialog').dialog('close');
398 - //call the callback:
399 - _this.done_upload_cb( url );
400 - }else{
401 - var bObj = {};
402 - bObj[ gM('go-to-resource') ] = function(){
403 - window.location = url;
404 - };
405 - _this.updateProgressWin( gM('successfulupload'), gM( 'mv_upload_done', url), bObj);
406 - js_log('apiRes.upload.imageinfo::'+url);
407 - }
408 - return ;
409 - }
410 -
411 - //check for upload error:
 388+ }
 389+ //check for upload.error type erros.
412390 if( apiRes.upload && apiRes.upload.error){
413391 js_log(' apiRes.upload.error: ' + apiRes.upload.error );
414 - return ;
 392+ _this.updateProgressWin( gM('uploaderror'), gM('unknown-error') + '<br>', bObj);
 393+ return false;
415394 }
416395 //check for known warnings:
417 - if( apiRes.upload.warnings ){
 396+ if(apiRes.upload && apiRes.upload.warnings ){
418397 //debugger;
419398 var wmsg = '<ul>';
420399 for(var wtype in apiRes.upload.warnings){
@@ -449,17 +428,49 @@
450429 _this.updateProgressWin( gM('uploadwarning'), '<h3>' + gM('uploadwarning') + '</h3>' +msg + '<p>',bObj);
451430 return false;
452431 }
453 -
454 - //nothing fits assume unkown error:
455 - js_log('could not parse upload api request result');
456 - var return_to_form_msg = gM('return-to-form');
457 - var bObj = {};
458 - bObj[ gM('return-to-form')] = function(){
459 - $(this).dialog('close');
460 - };
461 - _this.updateProgressWin( gM('uploaderror'), gM('unknown-error'),bObj);
462 - return false;
 432+ //should be "OK"
 433+ return true;
463434 },
 435+ processApiResult: function( apiRes ){
 436+ var _this = this;
 437+ js_log('processApiResult::');
 438+ //check for upload api error:
 439+ // {"upload":{"result":"Failure","error":"unknown-error","code":{"status":5,"filtered":"NGC2207%2BIC2163.jpg"}}}
 440+ if( _this.apiUpdateErrorCheck(apiRes) === false){
 441+ //error returned false (updated and
 442+ return false;
 443+ }else{
 444+ //check for upload_session key for async upload:
 445+ if( apiRes.upload && apiRes.upload.upload_session_key ){
 446+ //set the session key
 447+ _this.upload_session_key = apiRes.upload.upload_session_key;
 448+
 449+ //do ajax upload status:
 450+ _this.doAjaxUploadStatus();
 451+ js_log("set upload_session_key: " + _this.upload_session_key);
 452+ return ;
 453+ }
 454+
 455+ if( apiRes.upload.imageinfo && apiRes.upload.imageinfo.descriptionurl ){
 456+ var url = apiRes.upload.imageinfo.descriptionurl;
 457+ //check done action:
 458+ if(_this.done_upload_cb){
 459+ //close up shop:
 460+ $j('#upProgressDialog').dialog('close');
 461+ //call the callback:
 462+ _this.done_upload_cb( url );
 463+ }else{
 464+ var bObj = {};
 465+ bObj[ gM('go-to-resource') ] = function(){
 466+ window.location = url;
 467+ };
 468+ _this.updateProgressWin( gM('successfulupload'), gM( 'mv_upload_done', url), bObj);
 469+ js_log('apiRes.upload.imageinfo::'+url);
 470+ }
 471+ return ;
 472+ }
 473+ }
 474+ },
464475 updateProgressWin:function(title_txt, msg, buttons){
465476 var _this = this;
466477 if(!title_txt)
@@ -473,10 +484,10 @@
474485 }else{
475486 //@@todo should convice the jquery ui people to not use object keys as user msg's
476487 var bObj = {};
477 - bObj[ gM('ok-button') ] = function(){
 488+ bObj[ gM('ok-button') ] = function(){
478489 $j(this).dialog('close');
479 - };
480 - $j('#upProgressDialog').dialog('option','buttons', bObj);
 490+ };
 491+ $j('#upProgressDialog').dialog('option','buttons', bObj);
481492 }
482493 },
483494 getProgressTitle:function(){
Index: branches/new-upload/phase3/js2/mwEmbed/libSequencer/mvPlayList.js
@@ -1208,11 +1208,12 @@
12091209 }else{
12101210 this[method]=videoInterface[method];
12111211 }
1212 - }
 1212+ }
12131213 //string -> boolean:
12141214 if(this[method]=="false")this[method]=false;
12151215 if(this[method]=="true")this[method]=true;
1216 - }
 1216+ }
 1217+ debugger;
12171218 },
12181219 onClipDone:function(){
12191220 js_log('pl onClipDone (should go to next)');
Index: branches/new-upload/phase3/js2/mwEmbed/mv_embed.js
@@ -275,8 +275,10 @@
276276 }else if(typeof msgSet == 'string'){
277277 ammessages += msgSet;
278278 }
279 - if(ammessages=='')
280 - return js_log('gMsgLoadRemote::no msg set requested');
 279+ if(ammessages=''){
 280+ js_log('gMsgLoadRemote::no msg set requested');
 281+ return false;
 282+ }
281283
282284 do_api_req({
283285 'data':{'meta':'allmessages', 'ammessages':ammessages}
@@ -762,10 +764,10 @@
763765 loadExternalCss( mv_jquery_skin_path + 'jquery-ui-1.7.1.custom.css' );
764766 loadExternalCss( mv_embed_path + 'skins/'+mv_skin_name+'/styles.css' );
765767 //load all the req libs:
766 - mvJsLoader.jQueryCheck(function(){
 768+ mvJsLoader.jQueryCheck(function(){
767769 //load with staged dependeinces (for ie and safari that don't execute in order)
768770 mvJsLoader.doLoadDepMode([
769 - ['remoteSearchDriver',
 771+ [ 'remoteSearchDriver',
770772 '$j.cookie',
771773 '$j.ui'
772774 ],[
Index: branches/new-upload/phase3/js2/mwEmbed/libEmbedVideo/embedVideo.js
@@ -325,11 +325,11 @@
326326 $j('#' + embedObj.id).get(0).play();
327327 });
328328
329 - //add recomend firefox if non-native playback:
 329+ //add recomend firefox if non-native playback:
330330 if( embedObj.doNativeWarningCheck() ){
331331 $j('#dc_'+ embedObj.id).hover(
332332 function(){
333 - if($j('gnp_' + embedObj.id).length==0){
 333+ if($j('#gnp_' + embedObj.id).length==0){
334334 $j(this).append('<div id="gnp_' + embedObj.id + '" class="ui-state-highlight ui-corner-all" ' +
335335 'style="position:absolute;display:none;background:#FFF;top:10px;left:10px;right:10px;height:60px;">' +
336336 gM('mv_for_best_experience') +

Status & tagging log