r53083 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53082‎ | r53083 | r53084 >
Date:22:24, 10 July 2009
Author:dale
Status:deferred
Tags:
Comment:
fixed some regressions around http url copy uploads javascript interface that came up with the new firefogg js integration
Modified paths:
  • /branches/new-upload/phase3/includes/specials/SpecialUpload.php (modified) (history)
  • /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/mv_embed.js (modified) (history)
  • /branches/new-upload/phase3/js2/uploadPage.js (modified) (history)

Diff [purge]

Index: branches/new-upload/phase3/includes/specials/SpecialUpload.php
@@ -159,6 +159,8 @@
160160 * Checks are made in SpecialUpload::execute()
161161 *
162162 * 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)
163165 *
164166 * @access private
165167 */
@@ -624,6 +626,7 @@
625627 global $wgUseCopyrightUpload, $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview;
626628 global $wgRequest;
627629 global $wgStylePath, $wgStyleVersion;
 630+ global $wgEnableJS2system;
628631
629632 $useAjaxDestCheck = $wgUseAjax && $wgAjaxUploadDestCheck;
630633 $useAjaxLicensePreview = $wgUseAjax && $wgAjaxLicensePreview;
@@ -640,16 +643,16 @@
641644 wgEnableFirefogg = {$uef};
642645 wgUploadAutoFill = {$autofill};
643646 </script>" );
644 - //legacy upload code:
645 - //$wgOut->addScriptFile( 'upload.js' );
646 - //$wgOut->addScriptFile( 'edit.js' ); // For <charinsert> support
647647
648 - //add javascript phase 2 upload script (will completely replace upload.js shortly)
649 - if( $wgEnableJS2system )
 648+ if( $wgEnableJS2system ){
 649+ //js2version of upload page:
650650 $wgOut->addScriptClass( 'uploadPage' );
 651+ }else{
 652+ //legacy upload code:
 653+ $wgOut->addScriptFile( 'upload.js' );
 654+ $wgOut->addScriptFile( 'edit.js' ); // For <charinsert> support
 655+ }
651656
652 -
653 -
654657 if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) )
655658 {
656659 wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" );
@@ -778,13 +781,35 @@
779782 // Prepare form for upload or upload/copy
780783 //javascript moved from inline calls to setup:
781784 if( UploadFromUrl::isEnabled() && $wgUser->isAllowed( 'upload_by_url' ) ) {
782 - $filename_form =
 785+ if($wgEnableJS2system){
 786+ $filename_form =
783787 "<input type='radio' id=\"wpSourceTypeFile\" name='wpSourceType' value='upload' checked='checked' />" .
784788 "<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' size='60' />" .
785789 wfMsgHTML( 'upload_source_file' ) . "<br/>" .
786790 "<input type='radio' id='wpSourceTypeURL' name='wpSourceType' value='url' />" .
787791 "<input tabindex='1' type='text' name='wpUploadFileURL' id='wpUploadFileURL' size='60' />" .
788792 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+ }
789814 } else {
790815 $filename_form =
791816 "<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 @@
5252 'target_please_install' : false,
5353 'target_use_latest_fox': false,
5454 //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
5659 }
5760
5861
@@ -174,14 +177,14 @@
175178 $j(this.target_input_file_name).show();
176179
177180 //show select file:
178 - $j(this.target_btn_select_file).unbind(
 181+ $j( this.target_btn_select_file ).unbind(
179182 ).attr('disabled', false
180183 ).css({'display':'inline'}
181 - ).click(function(){
 184+ ).click(function(){
182185 _this.selectFogg();
183186 });
184187 //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(){
186189 _this.selectFogg();
187190 })
188191
Index: branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js
@@ -36,6 +36,7 @@
3737
3838 "cancel-button" : "Cancel",
3939 "ok-button" : "OK"
 40+
4041 });
4142
4243
@@ -83,7 +84,7 @@
8485 _this.org_onsubmit = _this.editForm.onsubmit;
8586
8687 //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(){
8889 //run the original onsubmit (if not run yet set flag to avoid excessive chaining )
8990 if( typeof( _this.org_onsubmit ) == 'function' ){
9091 if( ! _this.org_onsubmit() ){
@@ -112,7 +113,9 @@
113114
114115 //select upload mode:
115116 _this.detectUploadMode();
116 - }catch(e){}
 117+ }catch(e){
 118+
 119+ }
117120
118121 //don't submit the form we will do the post in ajax
119122 return false;
@@ -121,7 +124,7 @@
122125
123126 },
124127 detectUploadMode:function( callback ){
125 - var _this = this;
 128+ var _this = this;
126129 //check the upload mode:
127130 if( _this.upload_mode == 'autodetect' ){
128131 js_log('detectUploadMode::' + _this.upload_mode + ' api:' + _this.api_url);
@@ -331,8 +334,12 @@
332335 bObj[ gM('return-to-form') ] = function(){
333336 $j(this).dialog('close');
334337 };
 338+
 339+ //@@TODO should be refactored to more specialUpload page type error handling
 340+
335341 //check a few places for the error code:
336 - var error_code=0;
 342+ var error_code=0;
 343+ var errorReplaceArg='';
337344 if( apiRes.error && apiRes.error.code ){
338345 error_code = apiRes.error.code;
339346 }else if( apiRes.upload.code ){
@@ -342,6 +349,8 @@
343350 }
344351 if(apiRes.upload.code['status']){
345352 error_code = apiRes.upload.code['status'];
 353+ if(apiRes.upload.code['filtered'])
 354+ errorReplaceArg =apiRes.upload.code['filtered'];
346355 }
347356 }else{
348357 apiRes.upload.code;
@@ -352,40 +361,57 @@
353362 if(typeof apiRes.error == 'string')
354363 error_msg = apiRes.error;
355364 //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+ }
356386 //do a remote call to get the error msg:
357387 if(!error_code || error_code == 'unknown-error'){
358388 if(typeof JSON != 'undefined'){
359389 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;
364394 }else{
365395 if(apiRes.error && apiRes.error.info ){
366396 _this.updateProgressWin( gM('uploaderror'), apiRes.error.info ,bObj);
367397 return false;
368398 }else{
369 - if(typeof error_code == 'number'){
 399+ if(typeof error_code == 'number' && typeof error_msg_key[error_code] == 'undefined' ){
370400 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);
372402 }else{
373403 _this.updateProgressWin( gM('uploaderror'), gM('unknown-error') + ' : ' + error_code, bObj);
374404 }
375405 }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);
383409 });
384410 js_log("api.erorr");
385411 }
386412 return false;
387413 }
388 - }
389 - }
 414+ }
 415+ }
390416 //check for upload.error type erros.
391417 if( apiRes.upload && apiRes.upload.error){
392418 js_log(' apiRes.upload.error: ' + apiRes.upload.error );
Index: branches/new-upload/phase3/js2/mwEmbed/mv_embed.js
@@ -266,22 +266,24 @@
267267 * msgSet is either a string corresponding to a single msg to load
268268 * or msgSet is an array with set of msg to load
269269 */
270 -function gMsgLoadRemote(msgSet, callback){
 270+function gMsgLoadRemote(msgSet, callback){
271271 var ammessages = '';
272272 if(typeof msgSet == 'object' ){
273273 for(var i in msgSet){
274 - ammessages += msgSet[i];
 274+ ammessages += msgSet[i] + '|';
275275 }
276276 }else if(typeof msgSet == 'string'){
277277 ammessages += msgSet;
278278 }
279 - if(ammessages=''){
 279+ if(ammessages == ''){
280280 js_log('gMsgLoadRemote::no msg set requested');
281281 return false;
282 - }
283 -
 282+ }
284283 do_api_req({
285 - 'data':{'meta':'allmessages', 'ammessages':ammessages}
 284+ 'data':{
 285+ 'meta':'allmessages',
 286+ 'ammessages':ammessages
 287+ }
286288 },function(data){
287289 if(data.query.allmessages){
288290 var msgs = data.query.allmessages;
@@ -825,14 +827,37 @@
826828 });
827829 });
828830 }
 831+ /*
 832+ * the firefogg jquery function:
 833+ * @@note this firefogg envocation could be made to work more like real jquery plugins
 834+ */
829835 $.fn.firefogg = function( iObj, callback ) {
830836 if(!iObj)
831837 iObj={};
832838 //add base theme css:
833839 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+
837862 var loadSet = [
838863 [
839864 'mvBaseUploadInterface',
@@ -846,11 +871,11 @@
847872 ];
848873 if( iObj.encoder_interface ){
849874 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'
855880 ]);
856881 }
857882 //make sure we have everything loaded that we need:
@@ -862,8 +887,11 @@
863888 }else{
864889 var myFogg = new mvFirefogg( iObj );
865890 }
866 - if(myFogg)
 891+ if(myFogg){
867892 myFogg.doRewrite( callback );
 893+ var selectorElement = $j( iObj.selector ).get(0);
 894+ selectorElement['firefogg']=myFogg;
 895+ }
868896 });
869897 }
870898
Index: branches/new-upload/phase3/js2/uploadPage.js
@@ -67,6 +67,11 @@
6868
6969 $j('#wpSourceTypeURL').attr('checked', !set);
7070 $j('#wpUploadFileURL').attr('disabled', set);
 71+
 72+ //update firefogg mode:
 73+ $j('#wpUploadFile').firefogg({
 74+ 'fogg_enabled': $j('#wpSourceTypeFile').attr('checked')
 75+ });
7176 },
7277 /**
7378 * doDestCheck checks the destination

Status & tagging log