r50228 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50227‎ | r50228 | r50229 >
Date:17:21, 5 May 2009
Author:dale
Status:deferred
Tags:
Comment:
upload api updates
Modified paths:
  • /trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/mvUploader.js (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/mv_embed.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/mvUploader.js
@@ -15,8 +15,14 @@
1616 "wgfogg_waring_ogg_upload": "You have selected an ogg file for conversion to ogg (this is probably unnessesary). Maybe disable the video converter?",
1717 "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 help</a>",
1818 "upload-stats-fileprogres": "$1 of $2",
19 - "mv_upload_done" : "Your upload <i>should be<\/i> accessible <a href=\"$1\">here<\/a>",
20 - "mv_upload_completed" : "Upload Completed"
 19+ "mv_upload_done" : "Your upload <i>should be<\/i> accessible <a href=\"$1\">here<\/a>",
 20+
 21+ "successfulupload" : 'Successful upload',
 22+ "uploaderror" : "Upload error",
 23+ "uploadwarning": "Upload warning",
 24+ "unknown-error": "Unknown Error",
 25+ "return-to-form": "Return to form"
 26+
2127 });
2228
2329 var default_upload_options = {
@@ -106,11 +112,12 @@
107113 var intFirefoggObj = ( this.on_upload_page )?
108114 {'upload_done_action':'redirect'}:
109115 {'upload_done_action':function( rTitle ){
110 - js_log('add_done_action callback for uploader');
 116+ js_log( 'add_done_action callback for uploader' );
111117 //call the parent insert resource preview
112118 _this.upload_done_action( rTitle );
113119 }
114120 };
 121+
115122 if( _this.api_url )
116123 intFirefoggObj['api_url'] = _this.api_url;
117124
@@ -192,15 +199,12 @@
193200 //error in org submit return false;
194201 return false;
195202 }
196 - }
197 -
 203+ }
198204 //check for post action override:
199205 if( _this.form_post_override ){
200206 //alert('woudld submit here');
201207 return true;
202 - }
203 -
204 -
 208+ }
205209 //get the input form data in flat json:
206210 var tmpAryData = $j( _this.editForm ).serializeArray();
207211 for(var i=0; i < tmpAryData.length; i++){
@@ -214,8 +218,7 @@
215219 //for some unknown reason we have to drop down the #p-search z-index:
216220 $j('#p-search').css('z-index', 1);
217221
218 - //select upload mode:
219 -
 222+ //select upload mode:
220223 _this.detectUploadMode();
221224
222225 //don't submit the form we will do the post in ajax
@@ -334,7 +337,8 @@
335338 }else{
336339 var apiResult = JSON.parse ( data.upload['apiUploadResult'] ) ;
337340 _this.processApiResult( apiResult );
338 - }
 341+ }
 342+ return ;
339343 }
340344
341345 //@@ else update status:
@@ -358,12 +362,39 @@
359363 }
360364 uploadStatus();
361365 },
362 - processApiResult: function( apiResult ){
363 - if(apiResult['descriptionurl'])
364 - _this.updateUploadDone( apiResult['descriptionurl'] );
 366+ processApiResult: function( apiRes ){
 367+ var _this = this;
 368+ //check for error
 369+ if( apiRes.upload.result == "Failure" ){
 370+ //error space is too large so we don't front load it
 371+ //do a remote call to get the error msg:
 372+ if(apiRes.upload.error != "unknown-error"){
 373+ gMsgLoadRemote(apiRes.upload.error, function(msg){
 374+ _this.updateUploadError( gM( apiRes.upload.error ));
 375+ });
 376+ }else{
 377+ _this.updateUploadError( gM('unknown-error'));
 378+ }
 379+ }else if( apiRes.upload.imageinfo && apiRes.upload.imageinfo.descriptionurl ){
 380+ _this.updateUploadDone( apiRes.upload.imageinfo.descriptionurl );
 381+ }else{
 382+ //nothing fits assume unkown error:
 383+ _this.updateUploadError( gM('unknown-error'));
 384+ }
 385+
365386 },
 387+ updateUploadError:function( msg ){
 388+ $j( '#dlbox-centered' ).html( '<h3>' + gM('uploaderror') + '</h3>' +
 389+ msg + '<p>' +
 390+ '<a id="mv-return-to-form" href="#" >' + gM('return-to-form') + '</a>');
 391+ $j('#mv-return-to-form').click(function(){
 392+ //hide / close up shop
 393+ $j('#dlbox-overlay,#dlbox-centered').hide();
 394+ return false;
 395+ });
 396+ },
366397 updateUploadDone:function(url){
367 - $j( '#dlbox-centered' ).html( '<h3>' + gM('mv_upload_completed') + '</h3>' +
 398+ $j( '#dlbox-centered' ).html( '<h3>' + gM('successfulupload') + '</h3>' +
368399 gM( 'mv_upload_done', url) );
369400 },
370401 getProgressTitle:function(){
@@ -378,24 +409,23 @@
379410 },
380411 dispProgressOverlay:function(){
381412 var _this = this;
382 - //add in loader dl box if not present:
383 - if( $j('#dlbox-centered').length ==0 ){
384 - //hard code style (since not always easy to import style sheets)
385 - $j('body').append('<div id="dlbox-centered" class="dlbox-centered" style="'+
386 - 'position:fixed;background:#DDD;border:3px solid #AAA;font-size:115%;width:40%;'+
387 - 'height:300px;padding: 10px;z-index:100;top:100px;bottom:40%;left:20%;" >'+
388 - '<h5>' + _this.getProgressTitle() + '</h5>' +
389 - '<div id="up-pbar-container" style="border:solid thin gray;width:90%;height:15px;" >' +
390 - '<div id="up-progressbar" style="background:#AAC;width:0%;height:15px;"></div>' +
391 - '</div>' +
392 - '<span id="up-pstatus">0% - </span> ' +
393 - '<span id="up-status-state">' + gM('uploaded-status') + '</span> ' +
394 - '<span id="upload-stats-fileprogres"></span>'+
395 - '</div>' +
396 - '<div id="dlbox-overlay" class="dlbox-overlay" style="background:#000;cursor:wait;height:100%;'+
397 - 'left:0;top:0;position:fixed;width:100%;z-index:99;filter:alpha(opacity=60);'+
398 - '-moz-opacity: 0.6; opacity: 0.6;" ></div>');
399 - }
 413+ //remove old instance:
 414+ $j('#dlbox-centered,#dlbox-overlay').remove();
 415+ //hard code style (since not always easy to import style sheets)
 416+ $j('body').append('<div id="dlbox-centered" class="dlbox-centered" style="'+
 417+ 'position:fixed;background:#DDD;border:3px solid #AAA;font-size:115%;width:40%;'+
 418+ 'height:300px;padding: 10px;z-index:100;top:100px;bottom:40%;left:20%;" >'+
 419+ '<h5>' + _this.getProgressTitle() + '</h5>' +
 420+ '<div id="up-pbar-container" style="border:solid thin gray;width:90%;height:15px;" >' +
 421+ '<div id="up-progressbar" style="background:#AAC;width:0%;height:15px;"></div>' +
 422+ '</div>' +
 423+ '<span id="up-pstatus">0% - </span> ' +
 424+ '<span id="up-status-state">' + gM('uploaded-status') + '</span> ' +
 425+ '<span id="upload-stats-fileprogres"></span>'+
 426+ '</div>' +
 427+ '<div id="dlbox-overlay" class="dlbox-overlay" style="background:#000;cursor:wait;height:100%;'+
 428+ 'left:0;top:0;position:fixed;width:100%;z-index:99;filter:alpha(opacity=60);'+
 429+ '-moz-opacity: 0.6; opacity: 0.6;" ></div>');
400430 }
401431
402432 }
\ No newline at end of file
Index: trunk/extensions/MetavidWiki/skins/mv_embed/mv_embed.js
@@ -138,6 +138,37 @@
139139 return '[' + key + ']';
140140 }
141141 }
 142+/*
 143+ * msgSet is either a string corresponding to a single msg to load
 144+ * or msgSet is an array with set of msg to load
 145+ */
 146+function gMsgLoadRemote(msgSet, callback){
 147+ var ammessages = '';
 148+ if(typeof msgSet == 'object' ){
 149+ for(var i in msgSet){
 150+ ammessages += msgSet[i];
 151+ }
 152+ }else if(typeof msgSet == 'string'){
 153+ ammessages += msgSet;
 154+ }
 155+ if(ammessages=='')
 156+ return js_log('gMsgLoadRemote::no msg set requested');
 157+
 158+ do_api_req({
 159+ 'data':{'meta':'allmessages', 'ammessages':ammessages}
 160+ },function(data){
 161+ if(data.query.allmessages){
 162+ var msgs = data.query.allmessages;
 163+ for(var i in msgs){
 164+ var ld = {};
 165+ ld[ msgs[i]['name'] ] = msgs[i]['*'];
 166+ loadGM( ld );
 167+ }
 168+ }
 169+ //load the result into local msg var
 170+ callback();
 171+ });
 172+}
142173
143174 /**
144175 * Format a size in bytes for output, using an appropriate
@@ -784,6 +815,10 @@
785816 //force format to json (if not already set)
786817 options.data['format'] = 'json';
787818
 819+ //if action not set assume query
 820+ if(!options.data['action'])
 821+ options.data['action']='query';
 822+
788823 js_log('do api req: ' + options.url +'?' + jQuery.param(options.data) );
789824 //build request string:
790825 if( parseUri( document.URL ).host == parseUri( options.url ).host ){

Status & tagging log