Index: branches/new-upload/phase3/includes/specials/SpecialUpload.php |
— | — | @@ -159,6 +159,8 @@ |
160 | 160 | * Checks are made in SpecialUpload::execute() |
161 | 161 | * |
162 | 162 | * FIXME this should really use the standard Status class (instead of associative array) |
| 163 | + * FIXME would be nice if we refactored this into the upload api. |
| 164 | + * (the special upload page is not the only response point that needs clean localized error msgs) |
163 | 165 | * |
164 | 166 | * @access private |
165 | 167 | */ |
— | — | @@ -624,6 +626,7 @@ |
625 | 627 | global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview; |
626 | 628 | global $wgRequest; |
627 | 629 | global $wgStylePath, $wgStyleVersion; |
| 630 | + global $wgEnableJS2system; |
628 | 631 | |
629 | 632 | $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck; |
630 | 633 | $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview; |
— | — | @@ -640,16 +643,16 @@ |
641 | 644 | wgEnableFirefogg = {$uef}; |
642 | 645 | wgUploadAutoFill = {$autofill}; |
643 | 646 | </script>" ); |
644 | | - //legacy upload code: |
645 | | - //$wgOut->addScriptFile( 'upload.js' ); |
646 | | - //$wgOut->addScriptFile( 'edit.js' ); // For <charinsert> support |
647 | 647 | |
648 | | - //add javascript phase 2 upload script (will completely replace upload.js shortly) |
649 | | - if( $wgEnableJS2system ) |
| 648 | + if( $wgEnableJS2system ){ |
| 649 | + //js2version of upload page: |
650 | 650 | $wgOut->addScriptClass( 'uploadPage' ); |
| 651 | + }else{ |
| 652 | + //legacy upload code: |
| 653 | + $wgOut->addScriptFile( 'upload.js' ); |
| 654 | + $wgOut->addScriptFile( 'edit.js' ); // For <charinsert> support |
| 655 | + } |
651 | 656 | |
652 | | - |
653 | | - |
654 | 657 | if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) ) |
655 | 658 | { |
656 | 659 | wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" ); |
— | — | @@ -778,13 +781,35 @@ |
779 | 782 | // Prepare form for upload or upload/copy |
780 | 783 | //javascript moved from inline calls to setup: |
781 | 784 | if( UploadFromUrl::isEnabled() && $wgUser->isAllowed( 'upload_by_url' ) ) { |
782 | | - $filename_form = |
| 785 | + if($wgEnableJS2system){ |
| 786 | + $filename_form = |
783 | 787 | "<input type='radio' id=\"wpSourceTypeFile\" name='wpSourceType' value='upload' checked='checked' />" . |
784 | 788 | "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' size='60' />" . |
785 | 789 | wfMsgHTML( 'upload_source_file' ) . "<br/>" . |
786 | 790 | "<input type='radio' id='wpSourceTypeURL' name='wpSourceType' value='url' />" . |
787 | 791 | "<input tabindex='1' type='text' name='wpUploadFileURL' id='wpUploadFileURL' size='60' />" . |
788 | 792 | wfMsgHtml( 'upload_source_url' ) ; |
| 793 | + }else{ |
| 794 | + //@@todo depreciate (only support JS2system) |
| 795 | + $filename_form = |
| 796 | + "<input type='radio' id='wpSourceTypeFile' name='wpSourceType' value='file' " . |
| 797 | + "onchange='toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\")' checked='checked' />" . |
| 798 | + "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " . |
| 799 | + "onfocus='" . |
| 800 | + "toggle_element_activation(\"wpUploadFileURL\",\"wpUploadFile\");" . |
| 801 | + "toggle_element_check(\"wpSourceTypeFile\",\"wpSourceTypeURL\")' " . |
| 802 | + "onchange='fillDestFilename(\"wpUploadFile\")' size='60' />" . |
| 803 | + wfMsgHTML( 'upload_source_file' ) . "<br/>" . |
| 804 | + "<input type='radio' id='wpSourceTypeURL' name='wpSourceType' value='web' " . |
| 805 | + "onchange='toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\")' />" . |
| 806 | + "<input tabindex='1' type='text' name='wpUploadFileURL' id='wpUploadFileURL' " . |
| 807 | + "onfocus='" . |
| 808 | + "toggle_element_activation(\"wpUploadFile\",\"wpUploadFileURL\");" . |
| 809 | + "toggle_element_check(\"wpSourceTypeURL\",\"wpSourceTypeFile\")' " . |
| 810 | + "onchange='fillDestFilename(\"wpUploadFileURL\")' size='60' disabled='disabled' />" . |
| 811 | + wfMsgHtml( 'upload_source_url' ) ; |
| 812 | + |
| 813 | + } |
789 | 814 | } else { |
790 | 815 | $filename_form = |
791 | 816 | "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' size='60' />" . |
Index: branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvFirefogg.js |
— | — | @@ -51,7 +51,10 @@ |
52 | 52 | 'target_please_install' : false, |
53 | 53 | 'target_use_latest_fox': false, |
54 | 54 | //status: |
55 | | - 'target_passthrough_mode':false |
| 55 | + 'target_passthrough_mode':false, |
| 56 | + |
| 57 | + //allows to switch to baseUpload interface (mostly mediaWiki specific) |
| 58 | + 'do_base_upload':false |
56 | 59 | } |
57 | 60 | |
58 | 61 | |
— | — | @@ -174,14 +177,14 @@ |
175 | 178 | $j(this.target_input_file_name).show(); |
176 | 179 | |
177 | 180 | //show select file: |
178 | | - $j(this.target_btn_select_file).unbind( |
| 181 | + $j( this.target_btn_select_file ).unbind( |
179 | 182 | ).attr('disabled', false |
180 | 183 | ).css({'display':'inline'} |
181 | | - ).click(function(){ |
| 184 | + ).click(function(){ |
182 | 185 | _this.selectFogg(); |
183 | 186 | }); |
184 | 187 | //also setup the text file display on Click to select file: |
185 | | - $j(this.target_input_file_name).unbind().attr('readonly', 'readonly').click(function(){ |
| 188 | + $j(this.target_input_file_name).unbind().attr('readonly', 'readonly').click(function(){ |
186 | 189 | _this.selectFogg(); |
187 | 190 | }) |
188 | 191 | |
Index: branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js |
— | — | @@ -36,6 +36,7 @@ |
37 | 37 | |
38 | 38 | "cancel-button" : "Cancel", |
39 | 39 | "ok-button" : "OK" |
| 40 | + |
40 | 41 | }); |
41 | 42 | |
42 | 43 | |
— | — | @@ -83,7 +84,7 @@ |
84 | 85 | _this.org_onsubmit = _this.editForm.onsubmit; |
85 | 86 | |
86 | 87 | //have to define the onsubmit function inline or its hard to pass the "_this" instance |
87 | | - _this.editForm.onsubmit = function(){ |
| 88 | + _this.editForm.onsubmit = function(){ |
88 | 89 | //run the original onsubmit (if not run yet set flag to avoid excessive chaining ) |
89 | 90 | if( typeof( _this.org_onsubmit ) == 'function' ){ |
90 | 91 | if( ! _this.org_onsubmit() ){ |
— | — | @@ -112,7 +113,9 @@ |
113 | 114 | |
114 | 115 | //select upload mode: |
115 | 116 | _this.detectUploadMode(); |
116 | | - }catch(e){} |
| 117 | + }catch(e){ |
| 118 | + |
| 119 | + } |
117 | 120 | |
118 | 121 | //don't submit the form we will do the post in ajax |
119 | 122 | return false; |
— | — | @@ -121,7 +124,7 @@ |
122 | 125 | |
123 | 126 | }, |
124 | 127 | detectUploadMode:function( callback ){ |
125 | | - var _this = this; |
| 128 | + var _this = this; |
126 | 129 | //check the upload mode: |
127 | 130 | if( _this.upload_mode == 'autodetect' ){ |
128 | 131 | js_log('detectUploadMode::' + _this.upload_mode + ' api:' + _this.api_url); |
— | — | @@ -331,8 +334,12 @@ |
332 | 335 | bObj[ gM('return-to-form') ] = function(){ |
333 | 336 | $j(this).dialog('close'); |
334 | 337 | }; |
| 338 | + |
| 339 | + //@@TODO should be refactored to more specialUpload page type error handling |
| 340 | + |
335 | 341 | //check a few places for the error code: |
336 | | - var error_code=0; |
| 342 | + var error_code=0; |
| 343 | + var errorReplaceArg=''; |
337 | 344 | if( apiRes.error && apiRes.error.code ){ |
338 | 345 | error_code = apiRes.error.code; |
339 | 346 | }else if( apiRes.upload.code ){ |
— | — | @@ -342,6 +349,8 @@ |
343 | 350 | } |
344 | 351 | if(apiRes.upload.code['status']){ |
345 | 352 | error_code = apiRes.upload.code['status']; |
| 353 | + if(apiRes.upload.code['filtered']) |
| 354 | + errorReplaceArg =apiRes.upload.code['filtered']; |
346 | 355 | } |
347 | 356 | }else{ |
348 | 357 | apiRes.upload.code; |
— | — | @@ -352,40 +361,57 @@ |
353 | 362 | if(typeof apiRes.error == 'string') |
354 | 363 | error_msg = apiRes.error; |
355 | 364 | //error space is too large so we don't front load it |
| 365 | + //this upload error space replicates code in: SpecialUpload.php::processUpload() |
| 366 | + //would be nice if we refactored that to the upload api.(problem is some need special actions) |
| 367 | + var error_msg_key = { |
| 368 | + '2' : 'largefileserver', |
| 369 | + '3' : 'emptyfile', |
| 370 | + '4' : 'minlength1', |
| 371 | + '5' : 'illegalfilename' |
| 372 | + }; |
| 373 | + //@@todo: need to write conditionals that mirror SpecialUpload for handling these error types: |
| 374 | + var error_onlykey = { |
| 375 | + '1': 'BEFORE_PROCESSING', |
| 376 | + '6': 'PROTECTED_PAGE', |
| 377 | + '7': 'OVERWRITE_EXISTING_FILE', |
| 378 | + '8': 'FILETYPE_MISSING', |
| 379 | + '9': 'FILETYPE_BADTYPE', |
| 380 | + '10': 'VERIFICATION_ERROR', |
| 381 | + '11': 'UPLOAD_VERIFICATION_ERROR', |
| 382 | + '12': 'UPLOAD_WARNING', |
| 383 | + '13': 'INTERNAL_ERROR', |
| 384 | + '14': 'MIN_LENGHT_PARTNAME' |
| 385 | + } |
356 | 386 | //do a remote call to get the error msg: |
357 | 387 | if(!error_code || error_code == 'unknown-error'){ |
358 | 388 | if(typeof JSON != 'undefined'){ |
359 | 389 | js_log('Error: apiRes: ' + JSON.stringify( apiRes) ); |
360 | | - } |
361 | | - js_log('should update win::'); |
362 | | - _this.updateProgressWin( gM('uploaderror'), gM('unknown-error') + '<br>' + error_msg, bObj); |
363 | | - return false; |
| 390 | + } |
| 391 | + js_log('should update win::'); |
| 392 | + _this.updateProgressWin( gM('uploaderror'), gM('unknown-error') + '<br>' + error_msg, bObj ); |
| 393 | + return false; |
364 | 394 | }else{ |
365 | 395 | if(apiRes.error && apiRes.error.info ){ |
366 | 396 | _this.updateProgressWin( gM('uploaderror'), apiRes.error.info ,bObj); |
367 | 397 | return false; |
368 | 398 | }else{ |
369 | | - if(typeof error_code == 'number'){ |
| 399 | + if(typeof error_code == 'number' && typeof error_msg_key[error_code] == 'undefined' ){ |
370 | 400 | if(apiRes.upload.code.finalExt){ |
371 | | - _this.updateProgressWin( gM('uploaderror'), gM('wgfogg_waring_bad_extension',apiRes.upload.code.finalExt) , bObj); |
| 401 | + _this.updateProgressWin( gM('uploaderror'), gM('wgfogg_waring_bad_extension', apiRes.upload.code.finalExt) , bObj); |
372 | 402 | }else{ |
373 | 403 | _this.updateProgressWin( gM('uploaderror'), gM('unknown-error') + ' : ' + error_code, bObj); |
374 | 404 | } |
375 | 405 | }else{ |
376 | | - gMsgLoadRemote(error_code, function(){ |
377 | | - js_log('send msg: ' + gM( error_code )); |
378 | | - var bObj = {}; |
379 | | - bObj[gM('return-to-form')] = function(){ |
380 | | - $(this).dialog('close'); |
381 | | - }; |
382 | | - _this.updateProgressWin( gM('uploaderror'), gM( error_code ),bObj); |
| 406 | + js_log('get key: ' + error_msg_key[ error_code ]) |
| 407 | + gMsgLoadRemote( error_msg_key[ error_code ], function(){ |
| 408 | + _this.updateProgressWin( gM('uploaderror'), gM( error_msg_key[ error_code ], errorReplaceArg ), bObj); |
383 | 409 | }); |
384 | 410 | js_log("api.erorr"); |
385 | 411 | } |
386 | 412 | return false; |
387 | 413 | } |
388 | | - } |
389 | | - } |
| 414 | + } |
| 415 | + } |
390 | 416 | //check for upload.error type erros. |
391 | 417 | if( apiRes.upload && apiRes.upload.error){ |
392 | 418 | js_log(' apiRes.upload.error: ' + apiRes.upload.error ); |
Index: branches/new-upload/phase3/js2/mwEmbed/mv_embed.js |
— | — | @@ -266,22 +266,24 @@ |
267 | 267 | * msgSet is either a string corresponding to a single msg to load |
268 | 268 | * or msgSet is an array with set of msg to load |
269 | 269 | */ |
270 | | -function gMsgLoadRemote(msgSet, callback){ |
| 270 | +function gMsgLoadRemote(msgSet, callback){ |
271 | 271 | var ammessages = ''; |
272 | 272 | if(typeof msgSet == 'object' ){ |
273 | 273 | for(var i in msgSet){ |
274 | | - ammessages += msgSet[i]; |
| 274 | + ammessages += msgSet[i] + '|'; |
275 | 275 | } |
276 | 276 | }else if(typeof msgSet == 'string'){ |
277 | 277 | ammessages += msgSet; |
278 | 278 | } |
279 | | - if(ammessages=''){ |
| 279 | + if(ammessages == ''){ |
280 | 280 | js_log('gMsgLoadRemote::no msg set requested'); |
281 | 281 | return false; |
282 | | - } |
283 | | - |
| 282 | + } |
284 | 283 | do_api_req({ |
285 | | - 'data':{'meta':'allmessages', 'ammessages':ammessages} |
| 284 | + 'data':{ |
| 285 | + 'meta':'allmessages', |
| 286 | + 'ammessages':ammessages |
| 287 | + } |
286 | 288 | },function(data){ |
287 | 289 | if(data.query.allmessages){ |
288 | 290 | var msgs = data.query.allmessages; |
— | — | @@ -825,14 +827,37 @@ |
826 | 828 | }); |
827 | 829 | }); |
828 | 830 | } |
| 831 | + /* |
| 832 | + * the firefogg jquery function: |
| 833 | + * @@note this firefogg envocation could be made to work more like real jquery plugins |
| 834 | + */ |
829 | 835 | $.fn.firefogg = function( iObj, callback ) { |
830 | 836 | if(!iObj) |
831 | 837 | iObj={}; |
832 | 838 | //add base theme css: |
833 | 839 | loadExternalCss( mv_jquery_skin_path + 'jquery-ui-1.7.1.custom.css'); |
834 | | - loadExternalCss( mv_embed_path + 'skins/'+mv_skin_name+'/styles.css' ); |
835 | | - // @@todo should refactor mvAdvFirefogg as jQuery plugin |
836 | | - iObj['selector'] = this.selector; |
| 840 | + loadExternalCss( mv_embed_path + 'skins/'+mv_skin_name+'/styles.css' ); |
| 841 | + |
| 842 | + //check if we already have firefogg loaded |
| 843 | + var sElm = $j(this.selector).get(0); |
| 844 | + if(sElm['firefogg']){ |
| 845 | + if(sElm['firefogg']=='loading'){ |
| 846 | + js_log("Error: called firefogg operations on Firefogg selector that is not done loading"); |
| 847 | + return false; |
| 848 | + } |
| 849 | + //update properties: |
| 850 | + for(var i in iObj){ |
| 851 | + js_log("updated: "+ i + ' to '+ iObj[i]); |
| 852 | + sElm['firefogg'][i] = iObj[i]; |
| 853 | + } |
| 854 | + return sElm['firefogg']; |
| 855 | + }else{ |
| 856 | + //avoid concurency |
| 857 | + sElm['firefogg'] = 'loading'; |
| 858 | + } |
| 859 | + //add the selector: |
| 860 | + iObj['selector'] = this.selector; |
| 861 | + |
837 | 862 | var loadSet = [ |
838 | 863 | [ |
839 | 864 | 'mvBaseUploadInterface', |
— | — | @@ -846,11 +871,11 @@ |
847 | 872 | ]; |
848 | 873 | if( iObj.encoder_interface ){ |
849 | 874 | loadSet.push([ |
850 | | - 'mvAdvFirefogg', |
851 | | - '$j.cookie', |
852 | | - '$j.ui.accordion', |
853 | | - '$j.ui.slider', |
854 | | - '$j.ui.datepicker' |
| 875 | + 'mvAdvFirefogg', |
| 876 | + '$j.cookie', |
| 877 | + '$j.ui.accordion', |
| 878 | + '$j.ui.slider', |
| 879 | + '$j.ui.datepicker' |
855 | 880 | ]); |
856 | 881 | } |
857 | 882 | //make sure we have everything loaded that we need: |
— | — | @@ -862,8 +887,11 @@ |
863 | 888 | }else{ |
864 | 889 | var myFogg = new mvFirefogg( iObj ); |
865 | 890 | } |
866 | | - if(myFogg) |
| 891 | + if(myFogg){ |
867 | 892 | myFogg.doRewrite( callback ); |
| 893 | + var selectorElement = $j( iObj.selector ).get(0); |
| 894 | + selectorElement['firefogg']=myFogg; |
| 895 | + } |
868 | 896 | }); |
869 | 897 | } |
870 | 898 | |
Index: branches/new-upload/phase3/js2/uploadPage.js |
— | — | @@ -67,6 +67,11 @@ |
68 | 68 | |
69 | 69 | $j('#wpSourceTypeURL').attr('checked', !set); |
70 | 70 | $j('#wpUploadFileURL').attr('disabled', set); |
| 71 | + |
| 72 | + //update firefogg mode: |
| 73 | + $j('#wpUploadFile').firefogg({ |
| 74 | + 'fogg_enabled': $j('#wpSourceTypeFile').attr('checked') |
| 75 | + }); |
71 | 76 | }, |
72 | 77 | /** |
73 | 78 | * doDestCheck checks the destination |