1 /* adds firefogg support.
2 * autodetects: new upload api or old http POST.
6 "fogg-select_file" : "Select file",
7 "fogg-select_new_file" : "Select new file",
8 "fogg-select_url" : "Select URL",
9 "fogg-save_local_file" : "Save Ogg",
10 "fogg-check_for_fogg" : "Checking for Firefogg <blink>...<\/blink>",
11 "fogg-installed" : "Firefogg is installed",
12 "fogg-for_improved_uplods" : "For improved uploads:",
13 "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=firefogg\">Firefox 3.5<\/a> (or later). <i>Then revisit this page to install the <b>Firefogg<\/b> extension.<\/i>",
15 "fogg-passthrough_mode" : "Your selected file is already Ogg or not a video file",
16 "fogg-transcoding" : "Encoding video to Ogg",
17 "fogg-encoding-done" : "Encoding complete",
18 "fogg-badtoken" : "Token is not valid",
19 "fogg-preview" : "Preview video",
20 "fogg-hidepreview" : "Hide preview"
23 var firefogg_install_links
= {
24 'macosx': 'http://firefogg.org/macosx/Firefogg.xpi',
25 'win32': 'http://firefogg.org/win32/Firefogg.xpi',
26 'linux' : 'http://firefogg.org/linux/Firefogg.xpi'
29 var default_firefogg_options
= {
30 //what to do when finished uploading
31 'done_upload_cb':false,
32 //if firefoog is enabled
34 //the api url to upload to
36 //the passthrough flag (enables un-modified uploads)
38 //if we will be showing the encoder interface
39 'encoder_interface': false,
40 //if we want to limit the library functionality to "only firefoog" (no upload or progress bars)
45 'new_source_cb': false, //called on source name update passes along source name
47 //target control container or form (can't be left null)
50 //if not rewriting a form we are encoding local.
51 'form_rewrite': false,
54 'target_btn_select_file': false,
55 'target_btn_select_new_file': false,
57 //'target_btn_select_url': false,
59 'target_btn_save_local_file': false,
60 'target_input_file_name': false,
63 //target install descriptions
64 'target_check_for_fogg': false,
65 'target_installed': false,
66 'target_please_install': false,
67 'target_use_latest_fox': false,
69 'target_passthrough_mode':false,
71 //if firefogg should take over the form submit action
72 'firefogg_form_action':true,
74 //if we should show a preview of encoding progress
79 var mvFirefogg = function(iObj
){
80 return this.init( iObj
);
82 mvFirefogg
.prototype = { //extends mvBaseUploadInterface
84 min_firefogg_version
: '0.9.9.5',
85 fogg_enabled
: false, //if firefogg is enabled or not.
86 encoder_settings
:{ //@@todo allow server to set this
88 'videoBitrate' : '544',
89 'audioBitrate' : '96',
93 ogg_extensions
: ['ogg', 'ogv', 'oga'],
94 video_extensions
: ['avi', 'mov', 'mp4', 'mp2', 'mpeg', 'mpeg2', 'mpeg4', 'dv', 'wmv'],
99 init: function( iObj
){
103 //if we have no api_url set upload to "post"
105 iObj
.upload_mode
= 'post';
107 //inherit iObj properties:
108 for(var i
in default_firefogg_options
){
112 this[i
] = default_firefogg_options
[i
];
115 //check if we want to limit the usage:
117 var myBUI
= new mvBaseUploadInterface( iObj
);
119 //standard extends code:
122 this['pe_'+ i
] = myBUI
[i
];
130 js_log('firefogg: missing selector ');
133 doRewrite:function( callback
){
135 js_log('sel len: ' + this.selector
+ '::' + $j(this.selector
).length
+ ' tag:'+ $j(this.selector
).get(0).tagName
);
136 if( $j(this.selector
).length
>=0 ){
138 if( $j(this.selector
).get(0).tagName
.toLowerCase() == 'input' ){
139 _this
.form_rewrite
= true;
142 //check if we are rewriting an input or a form:
143 if( this.form_rewrite
){
146 this.doControlHTML();
147 this.doControlBindings();
154 doControlHTML: function( ){
157 $j
.each(default_firefogg_options
, function(target
, na
){
158 if(target
.substring(0, 6)=='target'){
159 //js_log('check for target html: ' + target);
160 //check for the target if missing add to the output:
161 if( _this
[target
] === false){
162 out
+= _this
.getTargetHtml(target
) + ' ';
163 //update the target selector
164 _this
[target
] = _this
.selector
+ ' .' + target
;
168 $j( this.selector
).append( out
).hide();
170 getTargetHtml:function(target
){
171 if( target
.substr(7,3)=='btn'){
172 return '<input style="" class="' + target
+ '" type="button" value="' + gM( 'fogg-' + target
.substring(11)) + '"/> ';
173 }else if(target
.substr(7,5)=='input'){
174 return '<input style="" class="' + target
+ '" type="text" value="' + gM( 'fogg-' + target
.substring(11)) + '"/> ';
176 return '<div style="" class="' + target
+ '" >'+ gM('fogg-'+ target
.substring(7)) + '</div> ';
179 doControlBindings: function(){
183 var hide_target_list
='';
185 $j
.each(default_firefogg_options
, function(target
, na
){
186 if(target
.substring(0, 6)=='target'){
187 hide_target_list
+=coma
+ _this
[target
];
191 $j( hide_target_list
).hide();
192 //now that the proper set of items has been hiiden show:
193 $j( this.selector
).show();
196 //hide all but check-for-fogg
198 if( _this
.firefoggCheck() ){
200 //if rewriting the form lets keep the text input around:
201 if( _this
.form_rewrite
)
202 $j(this.target_input_file_name
).show();
205 $j( this.target_btn_select_file
).unbind(
206 ).attr('disabled', false
207 ).css({'display':'inline'}
212 //also setup the text file display on Click to select file:
213 $j(this.target_input_file_name
).unbind().attr('readonly', 'readonly').click(function(){
218 //first check firefox version:
219 if(!( $j
.browser
.mozilla
&& $j
.browser
.version
>= '1.9.1' )) {
220 js_log( 'show use latest::' + _this
.target_use_latest_fox
);
221 if( _this
.target_use_latest_fox
){
222 if( _this
.form_rewrite
)
223 $j( _this
.target_use_latest_fox
).prepend( gM('fogg-for_improved_uplods') );
225 $j( _this
.target_use_latest_fox
).show();
230 //if rewriting form use upload msg text
231 var upMsg
= (_this
.form_rewrite
) ? gM('fogg-for_improved_uplods') : '';
232 $j( _this
.target_please_install
).html( upMsg
+ gM('fogg-please_install', _this
.getOSlink() )).css('padding', '10px').show();
234 //setup the target save local file bindins:
235 $j( _this
.target_btn_save_local_file
).unbind().click(function(){
236 _this
.saveLocalFogg();
240 * returns the firefogg link for your os:
242 getOSlink:function(){
245 if(navigator
.oscpu
.search('Linux') >= 0)
246 os_link
= firefogg_install_links
['linux'];
247 else if(navigator
.oscpu
.search('Mac') >= 0)
248 os_link
= firefogg_install_links
['macosx'];
249 else if(navigator
.oscpu
.search('Win') >= 0)
250 os_link
= firefogg_install_links
['win32'];
254 firefoggCheck:function(){
255 if(typeof(Firefogg
) != 'undefined' && Firefogg().version
>= this.min_firefogg_version
){
256 this.fogg
= new Firefogg();
257 this.fogg_enabled
= true;
263 //assume input target
264 setupForm: function(){
265 js_log('firefogg::setupForm::');
266 //to parent form setup if we want http updates
267 if( this.form_rewrite
){
268 //do parent form setup:
272 //check if we have firefogg (if not just add a link and stop proccessing)
273 if( !this.firefoggCheck() ){
274 //add some status indicators if not provided:
275 if(!this.target_please_install
){
276 $j(this.selector
).after ( this.getTargetHtml('target_please_install') );
277 this.target_please_install
= this.selector
+ ' ~ .target_please_install';
279 if(!this.target_use_latest_fox
){
280 $j(this.selector
).after ( this.getTargetHtml('target_use_latest_fox') );
281 this.target_use_latest_fox
= this.selector
+ ' ~ .target_use_latest_fox';
283 //update download link:
284 this.doControlBindings();
288 //change the file browser to type text: (can't directly change input from "file" to "text" so longer way:
289 var inTag
= '<input ';
290 $j
.each($j(this.selector
).get(0).attributes
, function(i
, attr
){
291 var val
= attr
.value
;
292 if( attr
.name
== 'type')
294 inTag
+= attr
.name
+ '="' + val
+ '" ';
296 if(!$j(this.selector
).attr('style'))
297 inTag
+= 'style="display:inline" ';
299 inTag
+= '/><span id="' + $j(this.selector
).attr('name') + '_fogg-control"></span>';
301 js_log('set input: ' + inTag
);
302 $j(this.selector
).replaceWith(inTag
);
304 this.target_input_file_name
= 'input[name=' + $j(this.selector
).attr('name') + ']';
305 //update the selector to the control target:
306 this.selector
= '#' + $j(this.selector
).attr('name') + "_fogg-control";
308 this.doControlHTML();
309 //check for the other inline status indicator targets:
311 //update the bindings:
312 this.doControlBindings();
314 //do firefogg specific additions:
315 dispProgressOverlay:function(){
316 this.pe_dispProgressOverlay();
317 //if we are uploading video (not in passthrough mode show preview button)
318 if( ! this.encoder_settings
['passthrough'] ){
319 this.doPreviewControl();
322 doPreviewControl:function(){
324 //prepend preview collapable
325 $j('#upProgressDialog').append(
326 '<div style="clear:both;height:3em"/>'+
327 $j
.btnHtml(gM('fogg-preview'), 'fogg_preview', 'triangle-1-e') +
328 '<div style="padding:10px;">' +
329 '<canvas style="margin:auto;" id="fogg_preview_canvas" />' +
333 if( _this
.show_preview
== true){
334 $j('#fogg_preview_canvas').show();
336 $j('#fogg_preview_canvas').hide();
338 //apply preview binding:
339 $j('#upProgressDialog .fogg_preview').btnBind().click( function(){
340 js_log("click .foog_preview" + $j(this).children('.ui-icon').attr('class') );
342 if( $j(this).children('.ui-icon').hasClass('ui-icon-triangle-1-e') ){
343 _this
.show_preview
= true;
345 $j(this).children('.ui-icon')
346 .removeClass('ui-icon-triangle-1-e')
347 .addClass('ui-icon-triangle-1-s');
349 $j(this).children('.btnText').text( gM('fogg-hidepreview') );
351 //show preview window
352 $j('#fogg_preview_canvas').show('fast');
354 _this
.show_preview
= false;
356 $j(this).children('.ui-icon')
357 .removeClass('ui-icon-triangle-1-s')
358 .addClass('ui-icon-triangle-1-e');
360 $j(this).children('.btnText').text( gM('fogg-preview') );
362 $j('#fogg_preview_canvas').hide('slow');
368 doRenderPreview:function(){
370 //set up the hidden video to pull frames from:
371 if( $j('#fogg_preview_vid').length
== 0 )
372 $j('body').append('<video id="fogg_preview_vid" style="display:none"></video>');
373 var v
= $j('#fogg_preview_vid').get(0);
375 function seekToEnd(){
376 var v
= $j('#fogg_preview_vid').get(0);
377 v
.currentTime
= v
.duration
-0.4;
379 function getFrame() {
380 var v
= $j('#fogg_preview_vid').get(0);
381 var canvas
= $j('#fogg_preview_canvas').get(0);
384 canvas
.height
= canvas
.width
* v
.videoHeight
/v
.videoWidth
;
385 var ctx
= canvas
.getContext("2d");
386 ctx
.drawImage(v
, 0, 0, canvas
.width
, canvas
.height
);
391 //initialize the video if not setup already:
392 var v
= $j('#fogg_preview_vid').get(0);
393 if( v
.src
!= _this
.fogg
.previewUrl
){
394 js_log('init preview with url:' + _this
.fogg
.previewUrl
);
395 v
.src
= _this
.fogg
.previewUrl
;
397 //set the video to seek to the end of the video
398 v
.removeEventListener("loadedmetadata", seekToEnd
, true);
399 v
.addEventListener("loadedmetadata", seekToEnd
, true);
401 //render a frame once seek is complete:
402 v
.removeEventListener("seeked", getFrame
, true);
403 v
.addEventListener("seeked", getFrame
, true);
405 //refresh the video duration/meta:
406 clearInterval(previewI
);
407 var previewI
= setInterval(function(){
408 if (_this
.fogg
.status() != "encoding"){
409 clearInterval(previewI
);
417 getEditForm:function(){
418 if( this.target_edit_from
)
419 return this.pe_getEditForm();
420 //else try to get the parent "from" of the file selector:
421 return $j(this.selector
).parents('form:first').get(0);
423 selectFogg:function(){
425 if(_this
.fogg
.selectVideo() ){
426 this.selectFoggActions();
429 selectFoggActions:function(){
431 js_log('videoSelectReady');
432 //if not already hidden hide select file and show "select new":
433 $j(_this
.target_btn_select_file
).hide();
435 //show and setup binding for select new file:
436 $j(_this
.target_btn_select_new_file
).show().unbind().click(function(){
437 //create new fogg instance:
438 _this
.fogg
= new Firefogg();
442 //update if we are in passthrough mode or going to encode
443 if( _this
.fogg
.sourceInfo
&& _this
.fogg
.sourceFilename
){
444 //update the source status
446 _this
.sourceFileInfo
= JSON
.parse( _this
.fogg
.sourceInfo
) ;
448 js_error('error could not parse fogg sourceInfo');
451 //now setup encoder settings based source type:
452 _this
.autoEncoderSettings();
454 //if set to passthough update the interface:
455 if(_this
.encoder_settings
['passthrough'] == true){
456 $j(_this
.target_passthrough_mode
).show();
458 $j(_this
.target_passthrough_mode
).hide();
459 //if set to encoder expose the encode button:
460 if( !_this
.form_rewrite
){
461 $j(_this
.target_btn_save_local_file
).show();
464 //~otherwise the encoding will be triggered by the form~
466 //do source name update callback:
467 js_log(" should update: " + _this
.target_input_file_name
+ ' to: ' + _this
.fogg
.sourceFilename
);
468 $j(_this
.target_input_file_name
).val(_this
.fogg
.sourceFilename
).show();
470 if(_this
.new_source_cb
){
471 if(_this
.encoder_settings
['passthrough']){
472 var fName
= _this
.fogg
.sourceFilename
474 var oggExt
= (_this
.isSourceAudio())?'oga':'ogg';
475 oggExt
= (_this
.isSourceVideo())?'ogv':oggExt
;
476 oggExt
= (_this
.isUnknown())?'ogg':oggExt
;
477 oggName
= _this
.fogg
.sourceFilename
.substr(0,
478 _this
.fogg
.sourceFilename
.lastIndexOf('.'));
479 var fName
= oggName
+'.'+ oggExt
481 _this
.new_source_cb( _this
.fogg
.sourceFilename
, fName
);
485 saveLocalFogg:function(){
486 //request target location:
488 if(!this.fogg
.saveVideoAs() )
491 //we have set a target now call the encode:
495 //simple auto encoder settings just enable passthough if file is not video or > 480 pixles tall
496 autoEncoderSettings:function(){
498 //grab the extension:
499 var sf
= _this
.fogg
.sourceFilename
;
501 if( sf
.lastIndexOf('.') != -1){
502 ext
= sf
.substring( sf
.lastIndexOf('.')+1 ).toLowerCase();
505 //set to passthrough to true by default (images, arbitrary files that we want to send with http chunks)
506 this.encoder_settings
['passthrough'] = true;
508 //see if we have video or audio:
509 if( _this
.isSourceAudio() || _this
.isSourceVideo() ){
510 _this
.encoder_settings
['passthrough'] = false;
513 //special case see if we already have ogg video:
514 if( _this
.isOggFormat() ){
515 _this
.encoder_settings
['passthrough'] = true;
518 js_log('base autoEncoderSettings::' + _this
.sourceFileInfo
.contentType
+ ' passthrough:' + _this
.encoder_settings
['passthrough']);
520 isUnknown:function(){
521 return (this.sourceFileInfo
.contentType
.indexOf("unknown") != -1);
523 isSourceAudio:function(){
524 return (this.sourceFileInfo
.contentType
.indexOf("audio/") != -1);
526 isSourceVideo:function(){
527 return (this.sourceFileInfo
.contentType
.indexOf("video/") != -1);
529 isOggFormat:function(){
530 return ( this.sourceFileInfo
.contentType
.indexOf("video/ogg") != -1 ||
531 this.sourceFileInfo
.contentType
.indexOf("application/ogg") != -1 );
533 getProgressTitle:function(){
534 js_log("fogg:getProgressTitle f:" + this.fogg_enabled
+ ' rw:' + this.form_rewrite
);
535 //return the parent if we don't have fogg turned on:
536 if(! this.fogg_enabled
|| !this.firefogg_form_action
)
537 return this.pe_getProgressTitle();
538 if( !this.form_rewrite
)
539 return gM('fogg-transcoding');
540 //else return our upload+transcode msg:
541 return gM('mwe-upload-transcode-in-progress');
543 doUploadSwitch:function(){
545 js_log("firefogg: doUploadSwitch:: " + this.fogg_enabled
+ ' up mode:' + _this
.upload_mode
);
546 //make sure firefogg is enabled otherwise do parent UploadSwich:
547 if( !this.fogg_enabled
|| !this.firefogg_form_action
)
548 return _this
.pe_doUploadSwitch();
550 //check what mode to use firefogg in:
551 if( _this
.upload_mode
== 'post' ){
553 }else if( _this
.upload_mode
== 'api' ){ //if api mode and chunks supported do chunkUpload
554 _this
.doChunkUpload();
556 js_error( 'Error: unrecongized upload mode: ' + _this
.upload_mode
);
559 //doChunkUpload does both uploading and encoding at the same time and uploads one meg chunks as they are ready
560 doChunkUpload : function(){
561 js_log('firefogg::doChunkUpload');
563 _this
.action_done
= false;
565 //extension should already be ogg but since its user editable,
567 //we are transcoding so we know it will be an ogg
568 //(should not be done for passthrough mode)
569 var sf
= _this
.formData
['filename'];
571 if( sf
.lastIndexOf('.') != -1){
572 ext
= sf
.substring( sf
.lastIndexOf('.') ).toLowerCase();
574 if( !_this
.encoder_settings
['passthrough'] && $j
.inArray(ext
.substr(1), _this
.ogg_extensions
) == -1 ){
575 var extreg
= new RegExp(ext
+ '$', 'i');
576 _this
.formData
['filename'] = sf
.replace(extreg
, '.ogg');
578 //add chunk response hook to build the resultURL when uploading chunks
580 //check for editToken:
582 js_log('missing token try ' + _this
.formData
['token']);
583 if( _this
.formData
['token']){
584 _this
.etoken
= _this
.formData
['token'];
585 _this
.doChunkWithFormData();
588 'File:'+ _this
.formData
['filename'],
591 if( !eToken
|| eToken
== '+\\' ){
592 _this
.updateProgressWin( gM('fogg-badtoken'), gM('fogg-badtoken') );
595 _this
.etoken
= eToken
;
596 _this
.doChunkWithFormData();
601 js_log('we already have token: ' + this.etoken
);
602 _this
.doChunkWithFormData();
605 doChunkWithFormData:function(){
607 js_log("firefogg::doChunkWithFormData" + _this
.etoken
);
612 'filename': _this
.formData
['filename'],
613 'comment': _this
.formData
['comment'],
614 'enablechunks': 'true'
618 aReq
['token'] = this.etoken
;
620 if( _this
.formData
['watch'] )
621 aReq
['watch'] = _this
.formData
['watch'];
623 if( _this
.formData
['ignorewarnings'] )
624 aReq
['ignorewarnings'] = _this
.formData
['ignorewarnings'];
626 js_log('do fogg upload/encode call: '+ _this
.api_url
+ ' :: ' + JSON
.stringify( aReq
) );
627 js_log('foggEncode: '+ JSON
.stringify( _this
.encoder_settings
) );
628 _this
.fogg
.upload( JSON
.stringify( _this
.encoder_settings
), _this
.api_url
, JSON
.stringify( aReq
) );
630 //update upload status:
631 _this
.doUploadStatus();
633 //doEncode and monitor progress:
634 doEncode : function(){
636 _this
.action_done
= false;
637 _this
.dispProgressOverlay();
638 js_log('doEncode: with: ' + JSON
.stringify( _this
.encoder_settings
) );
639 _this
.fogg
.encode( JSON
.stringify( _this
.encoder_settings
) );
641 //show transcode status:
642 $j('#up-status-state').html( gM('mwe-upload-transcoded-status') );
644 //setup a local function for timed callback:
645 var encodingStatus = function() {
646 var status
= _this
.fogg
.status();
648 if( _this
.show_preview
== true && _this
.fogg
.state
== 'encoding'){
649 _this
.doRenderPreview();
652 //update progress bar
653 _this
.updateProgress( _this
.fogg
.progress() );
655 //loop to get new status if still encoding
656 if( _this
.fogg
.state
== 'encoding' ) {
657 setTimeout(encodingStatus
, 500);
658 }else if ( _this
.fogg
.state
== 'encoding done' ) { //encoding done, state can also be 'encoding failed
660 }else if(_this
.fogg
.state
== 'encoding fail'){
661 //@@todo error handling:
662 js_error('encoding failed');
667 encodeDone:function(){
669 js_log('::encodeDone::');
670 _this
.action_done
= true;
671 //send to the post url:
672 if( _this
.form_rewrite
&& _this
.upload_mode
== 'post' ){
673 js_log('done with encoding do POST upload:' + _this
.editForm
.action
);
674 // ignore warnings & set source type
675 //_this.formData[ 'wpIgnoreWarning' ]='true';
676 _this
.formData
[ 'wpSourceType' ] = 'upload';
677 _this
.formData
[ 'action' ] = 'submit';
678 //wpUploadFile is set by firefogg
679 delete _this
.formData
[ 'file' ];
681 _this
.fogg
.post( _this
.editForm
.action
, 'wpUploadFile', JSON
.stringify( _this
.formData
) );
682 //update upload status:
683 _this
.doUploadStatus();
685 js_log("done with encoding (no upload) ");
686 //set stuats to 100% for one second:
687 _this
.updateProgress( 1 );
688 setTimeout(function(){
689 _this
.updateProgressWin(gM('fogg-encoding-done'),
690 gM('fogg-encoding-done') + '<br>' +
691 //show the video at full resolution upto 720px wide
692 '<video controls="true" style="margin:auto" id="fogg_final_vid" src="' +
693 _this
.fogg
.previewUrl
+ '"></video>'
695 //load the video and set a callback:
696 var v
= $j('#fogg_final_vid').get(0);
697 function resizeVid(){
698 var v
= $j('#fogg_final_vid').get(0);
699 if( v
.videoWidth
> 720 ){
701 var vH
= 720 * (v
.videoHeight
/v
.videoWidth
)
703 var vW
= v
.videoWidth
;
704 var vH
= v
.videoHeight
;
711 //if large video resize the dialog box:
713 //also resize the dialog box
714 $j('#upProgressDialog').dialog('option', 'width', vW
+ 20);
715 $j('#upProgressDialog').dialog('option', 'height', vH
+ 120);
717 //also position the dialog container
718 $j('#upProgressDialog').dialog('option', 'position', 'center');
721 v
.removeEventListener("loadedmetadata", resizeVid
, true);
722 v
.addEventListener("loadedmetadata", resizeVid
, true);
727 doUploadStatus:function() {
729 $j( '#up-status-state' ).html( gM('mwe-uploaded-status') );
731 _this
.oldResponseText
= '';
732 //setup a local function for timed callback:
733 var uploadStatus = function(){
734 //get the response text:
735 var response_text
= _this
.fogg
.responseText
;
738 var pstatus
= JSON
.parse( _this
.fogg
.uploadstatus() );
739 response_text
= pstatus
["responseText"];
741 js_log("could not parse uploadstatus / could not get responseText");
745 if( _this
.oldResponseText
!= response_text
){
746 js_log('new result text:' + response_text
+ ' state:' + _this
.fogg
.state
);
747 _this
.oldResponseText
= response_text
;
748 //try and parse the response text and check for errors
750 var apiResult
= JSON
.parse( response_text
);
752 js_log("could not parse response_text::" + response_text
+ ' ...for now try with eval...');
754 var apiResult
= eval( response_text
);
756 var apiResult
= null;
759 if(apiResult
&& _this
.apiUpdateErrorCheck( apiResult
) === false){
760 //stop status update we have an error
761 _this
.action_done
= true;
766 if( _this
.show_preview
== true ){
767 if( _this
.fogg
.state
== 'encoding' ){
768 _this
.doRenderPreview();
772 //update progress bar
773 _this
.updateProgress( _this
.fogg
.progress() );
775 //loop to get new status if still uploading (could also be encoding if we are in chunk upload mode)
776 if( _this
.fogg
.state
== 'encoding' || _this
.fogg
.state
== 'uploading') {
777 setTimeout(uploadStatus
, 100);
778 }//check upload state
779 else if( _this
.fogg
.state
== 'upload done' ||
780 _this
.fogg
.state
== 'done' ||
781 _this
.fogg
.state
== 'encoding done' ) {
782 //if in "post" upload mode read the html response (should be depricated):
783 if( _this
.upload_mode
== 'api' ){
784 if( apiResult
&& apiResult
.resultUrl
){
786 buttons
[gM('mwe-go-to-resource')] = function(){
787 window
.location
= apiResult
.resultUrl
;
789 var go_to_url_txt
= gM('mwe-go-to-resource');
790 if( typeof _this
.done_upload_cb
== 'function' ){
791 //if done action return 'true'
792 if( _this
.done_upload_cb( _this
.formData
) ){
794 _this
.updateProgressWin( gM('mwe-successfulupload'), gM( 'mwe-upload_done', apiResult
.resultUrl
),buttons
);
796 //if done action returns 'false' //close progress window
797 this.action_done
= true;
798 $j('#upProgressDialog').empty().dialog('close');
801 //update status (without done_upload_cb)
802 _this
.updateProgressWin( gM('mwe-successfulupload'), gM( 'mwe-upload_done', apiResult
.resultUrl
),buttons
);
805 //done state with error? ..not really possible given how firefogg works
806 js_log(" Upload done in chunks mode, but no resultUrl!");
808 }else if( _this
.upload_mode
== 'post' && _this
.api_url
) {
809 _this
.procPageResponse( response_text
);
813 js_log('Error:firefogg upload error: ' + _this
.fogg
.state
);
818 cancel_action:function( dlElm
){
819 if(!this.fogg_enabled
){
820 return this.pe_cancel_action();
822 js_log('firefogg:cancel')
823 if( confirm( gM('mwe-cancel-confim') )){
824 if(navigator
.oscpu
&& navigator
.oscpu
.search('Win') >= 0){
825 alert( 'sorry we do not yet support cancel on windows' );
827 this.action_done
= true;
829 $j(dlElm
).empty().dialog('close');
837 * procPageResponse should be faded out in favor of the upload api soon..
838 * its all very fragile to read the html output and guess at stuff
840 procPageResponse:function( result_page
){
842 js_log('f:procPageResponse');
843 var sstring
= 'var wgTitle = "' + this.formData
['filename'].replace('_',' ');
846 var result_txt
= gM('mwe-upload_done', wgArticlePath
.replace(/\$1/, 'File:' + _this
.formData
['filename'] ) );
848 result_txt
= 'File has uploaded but api "done" URL was provided. Check the log for result page output';
851 //set the error text in case we dont' get far along in processing the response
852 _this
.updateProgressWin( gM('mwe-upload_completed'), result_txt
);
854 if( result_page
&& result_page
.toLowerCase().indexOf( sstring
.toLowerCase() ) != -1){
855 js_log( 'upload done got redirect found: ' + sstring
+ ' r:' + _this
.done_upload_cb
);
856 if( _this
.done_upload_cb
== 'redirect' ){
857 $j( '#dlbox-centered' ).html( '<h3>Upload Completed:</h3>' + result_txt
+ '<br>' + form_txt
);
858 window
.location
= wgArticlePath
.replace( /\$1/, 'File:' + _this
.formData
['wpDestFile'] );
860 //check if the add_done_action is a callback:
861 if( typeof _this
.done_upload_cb
== 'function' )
862 _this
.done_upload_cb();
865 //js_log( 'upload page error: did not find: ' +sstring + ' in ' + "\n" + result_page );
869 //the mediaWiki upload system does not have an API so we can\'t read errors
871 var res
= grabWikiFormError( result_page
);
874 result_txt
= res
.error_txt
;
877 form_txt
= res
.form_txt
;
879 js_log( 'error text is: ' + result_txt
);
880 $j( '#dlbox-centered' ).html( '<h3>' + gM('mwe-upload_completed') + '</h3>' + result_txt
+ '<br>' + form_txt
);