r101973 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101972‎ | r101973 | r101974 >
Date:10:44, 4 November 2011
Author:j
Status:deferred
Tags:
Comment:
use Firefogg.setInput on change of file input
instead of replacing upload.ui.$fileInputCtrl
Modified paths:
  • /trunk/extensions/UploadWizard/resources/mw.FirefoggHandler.js (modified) (history)
  • /trunk/extensions/UploadWizard/resources/mw.FirefoggTransport.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/resources/mw.FirefoggHandler.js
@@ -14,13 +14,18 @@
1515 * Constructor
1616 */
1717 init: function( upload ){
 18+ var _this = this;
1819 this.upload = upload;
1920 this.api = upload.api;
20 - // update the mwe-upwiz-file-input target
21 - this.upload.ui.$fileInputCtrl = this.getInputControl();
22 - this.upload.ui.fileCtrlContainer.empty().append(
23 - this.upload.ui.$fileInputCtrl
24 - );
 21+ // pass file to Firefogg after selection
 22+ this.upload.ui.$fileInputCtrl.bind('change', function(event) {
 23+ if(_this.upload.ui.$fileInputCtrl[0].files.length) {
 24+ _this.getFogg().setInput(_this.upload.ui.$fileInputCtrl[0].files[0]);
 25+ //This is required to get the right requestedTitle in UploadWizardUpload
 26+ var title = _this.getTransport().getFileName().replace( /:/g, '_' );
 27+ _this.upload.title = new mw.Title( title , 'file' );
 28+ }
 29+ });
2530 // update the "valid" extension to include firefogg transcode extensions:
2631 mw.UploadWizard.config[ 'fileExtensions' ] = $.merge(
2732 mw.UploadWizard.config[ 'fileExtensions' ],
@@ -39,12 +44,12 @@
4045 var _this = this;
4146 if( !this.transport ){
4247 this.transport = new mw.FirefoggTransport(
43 - this.upload,
44 - this.api,
 48+ this.upload,
 49+ this.api,
4550 this.getFogg(),
46 - function( fraction ) {
47 - _this.upload.setTransportProgress( fraction );
48 - // also update preview video:
 51+ function( data ) {
 52+ _this.upload.setTransportProgress( data.progress );
 53+ // also update preview video, url is in data.preview
4954 },
5055 function( result ) {
5156 mw.log("FirefoggTransport::getTransport> Transport done " + JSON.stringify( result ) );
@@ -54,50 +59,8 @@
5560 }
5661 return this.transport;
5762 },
58 - isGoodExtension: function( ext ){
59 - // First check if its an oky extension for the wiki:
60 - if( $j.inArray( ext.toLowerCase(), mw.UploadWizard.config[ 'fileExtensions' ] ) !== -1 ){
61 - return true;
62 - }
63 - // Check if its a file that can be transcoded:
64 - if( this.getTransport().isSourceAudio() || this.getTransport().isSourceVideo() ){
65 - return true;
66 - }
67 - // file can't be transcoded
68 - return false;
69 - },
7063
71 - getForm: function(){
72 - return $j( this.upload.ui.form );
73 - },
74 -
7564 /**
76 - * Get a pointer to the "file" input control
77 - */
78 - getInputControl: function(){
79 - var _this = this;
80 - return $j('<input />').attr({
81 - 'size': "1",
82 - 'name': "file",
83 - 'type': "text"
84 - })
85 - .addClass( "mwe-upwiz-file-input" )
86 - .click( function() {
87 - if( _this.getFogg().selectVideo() ) {
88 - // Update the value of the input file:
89 - $j( this )
90 - .val( _this.getFogg().sourceFilename );
91 - //.trigger('change');
92 - // note the change trigger does not work because we replace the target:
93 - var title = _this.getTransport().getFileName().replace( /:/g, '_' );
94 - _this.upload.title = new mw.Title( title , 'file' );
95 - _this.upload.ui.fileChangedOk();
96 - _this.upload.filename = title;
97 - }
98 - } );
99 - },
100 -
101 - /**
10265 * If chunks are disabled transcode then upload else
10366 * upload and transcode at the same time
10467 */
Index: trunk/extensions/UploadWizard/resources/mw.FirefoggTransport.js
@@ -23,25 +23,29 @@
2424 doUpload: function() {
2525 var _this = this;
2626 //Encode or passthrough Firefogg before upload
27 - this.fogg.encode( JSON.stringify( this.getEncodeSettings() ),
28 - function(result, file) {
29 - result = JSON.parse(result);
30 - if(result.progress == 1) { //encoding done
31 - _this.doFormDataUpload(file);
32 - } else { //encoding failed
33 - var response = {
34 - error: {
35 - code: 500,
36 - info: 'Encoding failed'
37 - }
38 - };
39 - _this.transportedCb(response);
 27+ if (this.isUploadFormat()) {
 28+ _this.doFormDataUpload(this.upload.ui.$fileInputCtrl[0].files[0]);
 29+ } else {
 30+ this.fogg.encode( JSON.stringify( this.getEncodeSettings() ),
 31+ function(result, file) {
 32+ result = JSON.parse(result);
 33+ if(result.progress == 1) { //encoding done
 34+ _this.doFormDataUpload(file);
 35+ } else { //encoding failed
 36+ var response = {
 37+ error: {
 38+ code: 500,
 39+ info: 'Encoding failed'
 40+ }
 41+ };
 42+ _this.transportedCb(response);
 43+ }
 44+ }, function(progress) { //progress
 45+ progress = JSON.parse(progress);
 46+ _this.progressCb( progress );
4047 }
41 - }, function(progress) { //progress
42 - progress = JSON.parse(progress);
43 - _this.progressCb( progress.progress );
44 - }
45 - );
 48+ );
 49+ }
4650 },
4751 doFormDataUpload: function(file) {
4852 this.upload.file = file;
@@ -49,9 +53,9 @@
5054 this.uploadHandler.start();
5155 },
5256 /**
53 - * Check if the asset should be uploaded in passthrough mode ( or if it should be encoded )
 57+ * Check if the asset is in a format that can be upload without encoding.
5458 */
55 - isPassThrough: function(){
 59+ isUploadFormat: function(){
5660 // Check if the server supports webm uploads:
5761 var wembExt = ( $j.inArray( 'webm', mw.UploadWizard.config[ 'fileExtensions'] ) !== -1 )
5862 // Determine passthrough mode
@@ -104,8 +108,8 @@
105109
106110 // Get the filename
107111 getFileName: function(){
108 - // If passthrough don't change it
109 - if( this.isPassThrough() ){
 112+ // If file is in a supported format don't change extension
 113+ if( this.isUploadFormat() ){
110114 return this.fogg.sourceFilename;
111115 } else {
112116 if( this.isSourceAudio() ){
@@ -133,7 +137,7 @@
134138 * Get the encode settings from configuration and the current selected video type
135139 */
136140 getEncodeSettings: function(){
137 - if( this.isPassThrough() ){
 141+ if( this.isUploadFormat() ){
138142 return { 'passthrough' : true };
139143 }
140144 // Get the default encode settings:

Status & tagging log