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 ...",
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();
318 //if we are uploading video (not in passthrough mode show preview button)
319 if( ! this.encoder_settings
['passthrough'] && ! this.http_copy_upload
){
320 this.doPreviewControl();
323 doPreviewControl:function(){
325 //prepend preview (if fogg)
326 $j('#upProgressDialog').append(
327 '<div style="clear:both;height:3em"/>'+
328 $j
.btnHtml(gM('fogg-preview'), 'fogg_preview', 'triangle-1-e') +
329 '<div style="padding:10px;">' +
330 '<canvas style="margin:auto;" id="fogg_preview_canvas" />' +
334 if( _this
.show_preview
== true){
335 $j('#fogg_preview_canvas').show();
338 $j(this).children('.ui-icon')
339 .removeClass('ui-icon-triangle-1-s')
340 .addClass('ui-icon-triangle-1-e');
342 $j(this).children('.btnText').text( gM('fogg-preview') );
343 $j('#fogg_preview_canvas').hide();
345 //apply preview binding:
346 $j('#upProgressDialog .fogg_preview').btnBind().click( function(){
347 js_log("click .foog_preview" + $j(this).children('.ui-icon').attr('class') );
349 if( $j(this).children('.ui-icon').hasClass('ui-icon-triangle-1-e') ){
350 _this
.show_preview
= true;
352 $j(this).children('.ui-icon')
353 .removeClass('ui-icon-triangle-1-e')
354 .addClass('ui-icon-triangle-1-s');
356 $j(this).children('.btnText').text( gM('fogg-hidepreview') );
358 //show preview window
359 $j('#fogg_preview_canvas').show('fast');
361 _this
.show_preview
= false;
363 $j(this).children('.ui-icon')
364 .removeClass('ui-icon-triangle-1-s')
365 .addClass('ui-icon-triangle-1-e');
367 $j(this).children('.btnText').text( gM('fogg-preview') );
369 $j('#fogg_preview_canvas').hide('slow');
375 doRenderPreview:function(){
377 //set up the hidden video to pull frames from:
378 if( $j('#fogg_preview_vid').length
== 0 )
379 $j('body').append('<video id="fogg_preview_vid" style="display:none"></video>');
380 var v
= $j('#fogg_preview_vid').get(0);
382 function seekToEnd(){
383 var v
= $j('#fogg_preview_vid').get(0);
384 v
.currentTime
= v
.duration
-0.4;
386 function getFrame() {
387 var v
= $j('#fogg_preview_vid').get(0);
388 var canvas
= $j('#fogg_preview_canvas').get(0);
391 canvas
.height
= canvas
.width
* v
.videoHeight
/v
.videoWidth
;
392 var ctx
= canvas
.getContext("2d");
393 ctx
.drawImage(v
, 0, 0, canvas
.width
, canvas
.height
);
398 //initialize the video if not setup already:
399 var v
= $j('#fogg_preview_vid').get(0);
400 if( v
.src
!= _this
.fogg
.previewUrl
){
401 js_log('init preview with url:' + _this
.fogg
.previewUrl
);
402 v
.src
= _this
.fogg
.previewUrl
;
404 //set the video to seek to the end of the video
405 v
.removeEventListener("loadedmetadata", seekToEnd
, true);
406 v
.addEventListener("loadedmetadata", seekToEnd
, true);
408 //render a frame once seek is complete:
409 v
.removeEventListener("seeked", getFrame
, true);
410 v
.addEventListener("seeked", getFrame
, true);
412 //refresh the video duration/meta:
413 clearInterval(previewI
);
414 var previewI
= setInterval(function(){
415 if (_this
.fogg
.status() != "encoding"){
416 clearInterval(previewI
);
417 _this
.show_preview
== false;
419 if (_this
.show_preview
== true) {
427 getEditForm:function(){
428 if( this.target_edit_from
)
429 return this.pe_getEditForm();
430 //else try to get the parent "from" of the file selector:
431 return $j(this.selector
).parents('form:first').get(0);
433 selectFogg:function(){
435 if(_this
.fogg
.selectVideo() ){
436 this.selectFoggActions();
439 selectFoggActions:function(){
441 js_log('videoSelectReady');
442 //if not already hidden hide select file and show "select new":
443 $j(_this
.target_btn_select_file
).hide();
445 //show and setup binding for select new file:
446 $j(_this
.target_btn_select_new_file
).show().unbind().click(function(){
447 //create new fogg instance:
448 _this
.fogg
= new Firefogg();
452 //update if we are in passthrough mode or going to encode
453 if( _this
.fogg
.sourceInfo
&& _this
.fogg
.sourceFilename
){
454 //update the source status
456 _this
.sourceFileInfo
= JSON
.parse( _this
.fogg
.sourceInfo
) ;
458 js_error('error could not parse fogg sourceInfo');
461 //now setup encoder settings based source type:
462 _this
.autoEncoderSettings();
464 //if set to passthough update the interface (if not a form)
465 if(_this
.encoder_settings
['passthrough'] == true && !_this
.form_rewrite
){
466 $j(_this
.target_passthrough_mode
).show();
468 $j(_this
.target_passthrough_mode
).hide();
469 //if set to encoder expose the encode button:
470 if( !_this
.form_rewrite
){
471 $j(_this
.target_btn_save_local_file
).show();
474 //~otherwise the encoding will be triggered by the form~
476 //do source name update callback:
477 js_log(" should update: " + _this
.target_input_file_name
+ ' to: ' + _this
.fogg
.sourceFilename
);
478 $j(_this
.target_input_file_name
).val(_this
.fogg
.sourceFilename
).show();
480 if(_this
.new_source_cb
){
481 if(_this
.encoder_settings
['passthrough']){
482 var fName
= _this
.fogg
.sourceFilename
484 var oggExt
= (_this
.isSourceAudio())?'oga':'ogg';
485 oggExt
= (_this
.isSourceVideo())?'ogv':oggExt
;
486 oggExt
= (_this
.isUnknown())?'ogg':oggExt
;
487 oggName
= _this
.fogg
.sourceFilename
.substr(0,
488 _this
.fogg
.sourceFilename
.lastIndexOf('.'));
489 var fName
= oggName
+'.'+ oggExt
491 _this
.new_source_cb( _this
.fogg
.sourceFilename
, fName
);
495 saveLocalFogg:function(){
496 //request target location:
498 if(!this.fogg
.saveVideoAs() )
501 //we have set a target now call the encode:
505 //simple auto encoder settings just enable passthough if file is not video or > 480 pixles tall
506 autoEncoderSettings:function(){
508 //grab the extension:
509 var sf
= _this
.fogg
.sourceFilename
;
511 if( sf
.lastIndexOf('.') != -1)
512 ext
= sf
.substring( sf
.lastIndexOf('.')+1 ).toLowerCase();
514 //set to passthrough to true by default (images, arbitrary files that we want to send with http chunks)
515 this.encoder_settings
['passthrough'] = true;
517 //see if we have video or audio:
518 if( _this
.isSourceAudio() || _this
.isSourceVideo() )
519 _this
.encoder_settings
['passthrough'] = false;
521 //special case see if we already have ogg video:
522 if( _this
.isOggFormat() )
523 _this
.encoder_settings
['passthrough'] = true;
525 js_log('base autoEncoderSettings::' + _this
.sourceFileInfo
.contentType
+ ' passthrough:' + _this
.encoder_settings
['passthrough']);
527 isUnknown:function(){
528 return (this.sourceFileInfo
.contentType
.indexOf("unknown") != -1);
530 isSourceAudio:function(){
531 return (this.sourceFileInfo
.contentType
.indexOf("audio/") != -1);
533 isSourceVideo:function(){
534 return (this.sourceFileInfo
.contentType
.indexOf("video/") != -1);
536 isOggFormat:function(){
537 return ( this.sourceFileInfo
.contentType
.indexOf("video/ogg") != -1 ||
538 this.sourceFileInfo
.contentType
.indexOf("application/ogg") != -1 );
540 getProgressTitle:function(){
541 js_log("fogg:getProgressTitle f:" + this.fogg_enabled
+ ' rw:' + this.form_rewrite
);
542 //return the parent if we don't have fogg turned on:
543 if(! this.fogg_enabled
|| !this.firefogg_form_action
)
544 return this.pe_getProgressTitle();
545 if( !this.form_rewrite
)
546 return gM('fogg-transcoding');
547 //else return our upload+transcode msg:
548 return gM('mwe-upload-transcode-in-progress');
550 doUploadSwitch:function(){
552 js_log("firefogg: doUploadSwitch:: " + this.fogg_enabled
+ ' up mode:' + _this
.upload_mode
);
553 //make sure firefogg is enabled otherwise do parent UploadSwich:
554 if( !this.fogg_enabled
|| !this.firefogg_form_action
)
555 return _this
.pe_doUploadSwitch();
557 //check what mode to use firefogg in:
558 if( _this
.upload_mode
== 'post' ){
560 }else if( _this
.upload_mode
== 'api' ){ //if api mode and chunks supported do chunkUpload
561 _this
.doChunkUpload();
563 js_error( 'Error: unrecongized upload mode: ' + _this
.upload_mode
);
566 //doChunkUpload does both uploading and encoding at the same time and uploads one meg chunks as they are ready
567 doChunkUpload : function(){
568 js_log('firefogg::doChunkUpload');
570 _this
.action_done
= false;
572 //extension should already be ogg but since its user editable,
574 //we are transcoding so we know it will be an ogg
575 //(should not be done for passthrough mode)
576 var sf
= _this
.formData
['filename'];
578 if( sf
.lastIndexOf('.') != -1){
579 ext
= sf
.substring( sf
.lastIndexOf('.') ).toLowerCase();
581 if( !_this
.encoder_settings
['passthrough'] && $j
.inArray(ext
.substr(1), _this
.ogg_extensions
) == -1 ){
582 var extreg
= new RegExp(ext
+ '$', 'i');
583 _this
.formData
['filename'] = sf
.replace(extreg
, '.ogg');
585 //add chunk response hook to build the resultURL when uploading chunks
587 //check for editToken:
589 js_log('missing token try ' + _this
.formData
['token']);
590 if( _this
.formData
['token']){
591 _this
.etoken
= _this
.formData
['token'];
592 _this
.doChunkWithFormData();
595 'File:'+ _this
.formData
['filename'],
598 if( !eToken
|| eToken
== '+\\' ){
599 _this
.updateProgressWin( gM('fogg-badtoken'), gM('fogg-badtoken') );
602 _this
.etoken
= eToken
;
603 _this
.doChunkWithFormData();
608 js_log('we already have token: ' + this.etoken
);
609 _this
.doChunkWithFormData();
612 doChunkWithFormData:function(){
614 js_log("firefogg::doChunkWithFormData" + _this
.etoken
);
619 'filename': _this
.formData
['filename'],
620 'comment': _this
.formData
['comment'],
621 'enablechunks': 'true'
625 aReq
['token'] = this.etoken
;
627 if( _this
.formData
['watch'] )
628 aReq
['watch'] = _this
.formData
['watch'];
630 if( _this
.formData
['ignorewarnings'] )
631 aReq
['ignorewarnings'] = _this
.formData
['ignorewarnings'];
633 js_log('do fogg upload/encode call: '+ _this
.api_url
+ ' :: ' + JSON
.stringify( aReq
) );
634 js_log('foggEncode: '+ JSON
.stringify( _this
.encoder_settings
) );
635 _this
.fogg
.upload( JSON
.stringify( _this
.encoder_settings
), _this
.api_url
, JSON
.stringify( aReq
) );
637 //update upload status:
638 _this
.doUploadStatus();
640 //doEncode and monitor progress:
641 doEncode : function(){
643 _this
.action_done
= false;
644 _this
.dispProgressOverlay();
645 js_log('doEncode: with: ' + JSON
.stringify( _this
.encoder_settings
) );
646 _this
.fogg
.encode( JSON
.stringify( _this
.encoder_settings
) );
648 //show transcode status:
649 $j('#up-status-state').html( gM('mwe-upload-transcoded-status') );
651 //setup a local function for timed callback:
652 var encodingStatus = function() {
653 var status
= _this
.fogg
.status();
655 if( _this
.show_preview
== true && _this
.fogg
.state
== 'encoding'){
656 _this
.doRenderPreview();
659 //update progress bar
660 _this
.updateProgress( _this
.fogg
.progress() );
662 //loop to get new status if still encoding
663 if( _this
.fogg
.state
== 'encoding' ) {
664 setTimeout(encodingStatus
, 500);
665 }else if ( _this
.fogg
.state
== 'encoding done' ) { //encoding done, state can also be 'encoding failed
667 }else if(_this
.fogg
.state
== 'encoding fail'){
668 //@@todo error handling:
669 js_error('encoding failed');
674 encodeDone:function(){
676 js_log('::encodeDone::');
677 _this
.action_done
= true;
678 //send to the post url:
679 if( _this
.form_rewrite
&& _this
.upload_mode
== 'post' ){
680 js_log('done with encoding do POST upload:' + _this
.editForm
.action
);
681 // ignore warnings & set source type
682 //_this.formData[ 'wpIgnoreWarning' ]='true';
683 _this
.formData
[ 'wpSourceType' ] = 'upload';
684 _this
.formData
[ 'action' ] = 'submit';
685 //wpUploadFile is set by firefogg
686 delete _this
.formData
[ 'file' ];
688 _this
.fogg
.post( _this
.editForm
.action
, 'wpUploadFile', JSON
.stringify( _this
.formData
) );
689 //update upload status:
690 _this
.doUploadStatus();
692 js_log("done with encoding (no upload) ");
693 //set stuats to 100% for one second:
694 _this
.updateProgress( 1 );
695 setTimeout(function(){
696 _this
.updateProgressWin(gM('fogg-encoding-done'),
697 gM('fogg-encoding-done') + '<br>' +
698 //show the video at full resolution upto 720px wide
699 '<video controls="true" style="margin:auto" id="fogg_final_vid" src="' +
700 _this
.fogg
.previewUrl
+ '"></video>'
702 //load the video and set a callback:
703 var v
= $j('#fogg_final_vid').get(0);
704 function resizeVid(){
705 var v
= $j('#fogg_final_vid').get(0);
706 if( v
.videoWidth
> 720 ){
708 var vH
= 720 * (v
.videoHeight
/v
.videoWidth
)
710 var vW
= v
.videoWidth
;
711 var vH
= v
.videoHeight
;
718 //if large video resize the dialog box:
720 //also resize the dialog box
721 $j('#upProgressDialog').dialog('option', 'width', vW
+ 20);
722 $j('#upProgressDialog').dialog('option', 'height', vH
+ 120);
724 //also position the dialog container
725 $j('#upProgressDialog').dialog('option', 'position', 'center');
728 v
.removeEventListener("loadedmetadata", resizeVid
, true);
729 v
.addEventListener("loadedmetadata", resizeVid
, true);
734 doUploadStatus:function() {
736 $j( '#up-status-state' ).html( gM('mwe-uploaded-status') );
738 _this
.oldResponseText
= '';
739 //setup a local function for timed callback:
740 var uploadStatus = function(){
741 //get the response text:
742 var response_text
= _this
.fogg
.responseText
;
745 var pstatus
= JSON
.parse( _this
.fogg
.uploadstatus() );
746 response_text
= pstatus
["responseText"];
748 js_log("could not parse uploadstatus / could not get responseText");
752 if( _this
.oldResponseText
!= response_text
){
753 js_log('new result text:' + response_text
+ ' state:' + _this
.fogg
.state
);
754 _this
.oldResponseText
= response_text
;
755 //try and parse the response text and check for errors
757 var apiResult
= JSON
.parse( response_text
);
759 js_log("could not parse response_text::" + response_text
+ ' ...for now try with eval...');
761 var apiResult
= eval( response_text
);
763 var apiResult
= null;
766 if(apiResult
&& _this
.apiUpdateErrorCheck( apiResult
) === false){
767 //stop status update we have an error
768 _this
.action_done
= true;
773 if( _this
.show_preview
== true ){
774 if( _this
.fogg
.state
== 'encoding' ){
775 _this
.doRenderPreview();
779 //update progress bar
780 _this
.updateProgress( _this
.fogg
.progress() );
782 //loop to get new status if still uploading (could also be encoding if we are in chunk upload mode)
783 if( _this
.fogg
.state
== 'encoding' || _this
.fogg
.state
== 'uploading') {
784 setTimeout(uploadStatus
, 100);
785 }//check upload state
786 else if( _this
.fogg
.state
== 'upload done' ||
787 _this
.fogg
.state
== 'done' ||
788 _this
.fogg
.state
== 'encoding done' ) {
789 //if in "post" upload mode read the html response (should be depricated):
790 if( _this
.upload_mode
== 'api' ){
791 if( apiResult
&& apiResult
.resultUrl
){
793 buttons
[gM('mwe-go-to-resource')] = function(){
794 window
.location
= apiResult
.resultUrl
;
796 var go_to_url_txt
= gM('mwe-go-to-resource');
797 if( typeof _this
.done_upload_cb
== 'function' ){
798 //if done action return 'true'
799 if( _this
.done_upload_cb( _this
.formData
) ){
801 _this
.updateProgressWin( gM('mwe-successfulupload'), gM( 'mwe-upload_done', apiResult
.resultUrl
),buttons
);
803 //if done action returns 'false' //close progress window
804 this.action_done
= true;
805 $j('#upProgressDialog').empty().dialog('close');
808 //update status (without done_upload_cb)
809 _this
.updateProgressWin( gM('mwe-successfulupload'), gM( 'mwe-upload_done', apiResult
.resultUrl
),buttons
);
812 //done state with error? ..not really possible given how firefogg works
813 js_log(" Upload done in chunks mode, but no resultUrl!");
815 }else if( _this
.upload_mode
== 'post' && _this
.api_url
) {
816 _this
.procPageResponse( response_text
);
820 js_log('Error:firefogg upload error: ' + _this
.fogg
.state
);
825 cancel_action:function( dlElm
){
826 if(!this.fogg_enabled
){
827 return this.pe_cancel_action();
829 js_log('firefogg:cancel')
830 if( confirm( gM('mwe-cancel-confim') )){
831 if(navigator
.oscpu
&& navigator
.oscpu
.search('Win') >= 0){
832 alert( 'sorry we do not yet support cancel on windows' );
834 this.action_done
= true;
836 $j(dlElm
).empty().dialog('close');
839 //dont' follow the link:
843 * procPageResponse should be faded out in favor of the upload api soon..
844 * its all very fragile to read the html output and guess at stuff
846 procPageResponse:function( result_page
){
848 js_log('f:procPageResponse');
849 var sstring
= 'var wgTitle = "' + this.formData
['filename'].replace('_',' ');
852 var result_txt
= gM('mwe-upload_done', wgArticlePath
.replace(/\$1/, 'File:' + _this
.formData
['filename'] ) );
854 result_txt
= 'File has uploaded but api "done" URL was provided. Check the log for result page output';
857 //set the error text in case we dont' get far along in processing the response
858 _this
.updateProgressWin( gM('mwe-upload_completed'), result_txt
);
860 if( result_page
&& result_page
.toLowerCase().indexOf( sstring
.toLowerCase() ) != -1){
861 js_log( 'upload done got redirect found: ' + sstring
+ ' r:' + _this
.done_upload_cb
);
862 if( _this
.done_upload_cb
== 'redirect' ){
863 $j( '#dlbox-centered' ).html( '<h3>Upload Completed:</h3>' + result_txt
+ '<br>' + form_txt
);
864 window
.location
= wgArticlePath
.replace( /\$1/, 'File:' + _this
.formData
['wpDestFile'] );
866 //check if the add_done_action is a callback:
867 if( typeof _this
.done_upload_cb
== 'function' )
868 _this
.done_upload_cb();
871 //js_log( 'upload page error: did not find: ' +sstring + ' in ' + "\n" + result_page );
875 //the mediaWiki upload system does not have an API so we can\'t read errors
877 var res
= grabWikiFormError( result_page
);
880 result_txt
= res
.error_txt
;
883 form_txt
= res
.form_txt
;
885 js_log( 'error text is: ' + result_txt
);
886 $j( '#dlbox-centered' ).html( '<h3>' + gM('mwe-upload_completed') + '</h3>' + result_txt
+ '<br>' + form_txt
);