MarkTraceur has uploaded a new change for review.
https://gerrit.wikimedia.org/r/178230
Change subject: Remove references to upload in FirefoggTransport
......................................................................
Remove references to upload in FirefoggTransport
Bug: T77124
Change-Id: Ief906848344d2986ddc28a095f9470b2b6299325
---
M resources/mw.FirefoggHandler.js
M resources/mw.FirefoggTransport.js
2 files changed, 42 insertions(+), 34 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard
refs/changes/30/178230/1
diff --git a/resources/mw.FirefoggHandler.js b/resources/mw.FirefoggHandler.js
index 8ef3c49..38c7bf8 100644
--- a/resources/mw.FirefoggHandler.js
+++ b/resources/mw.FirefoggHandler.js
@@ -28,21 +28,49 @@
},
getTransport: function () {
- var upload = this.upload;
+ var file, transport,
+ fogg = this.getFogg(),
+ upload = this.upload,
+ $fileInput = upload.ui.$fileInputCtrl[0];
+
+ if ( $fileInput.files && $fileInput.files.length ) {
+ file = $fileInput.files[0];
+ } else if ( upload.file ) {
+ file = upload.file;
+ } else if ( upload.providedFile ) {
+ file = upload.providedFile;
+ } else {
+ mw.log.warn( 'Firefogg tried to upload a file
but was unable to find one.' );
+ return false;
+ }
if ( !this.transport ) {
- this.transport = new mw.FirefoggTransport(
- this.upload,
+ transport = new mw.FirefoggTransport(
+ file,
this.api,
- this.getFogg()
+ fogg
).on( 'progress', function ( data ) {
- upload.setTransportProgress(
data.progress );
- // also update preview video, url is in
data.preview
+ if ( upload.state === 'aborted' ) {
+ fogg.cancel();
+ } else {
+ upload.setTransportProgress(
data.progress );
+ upload.ui.setStatus(
'mwe-upwiz-encoding' );
+ }
} ).on( 'transported', function ( result ) {
mw.log(
'FirefoggTransport::getTransport> Transport done ' + JSON.stringify( result ) );
upload.setTransported( result );
+ } ).on( 'encoding', function () {
+ upload.ui.setStatus(
'mwe-upwiz-encoding' );
+ } ).on( 'starting', function ( file ) {
+ upload.ui.setStatus(
'mwe-upwiz-uploading' );
+ upload.file = file;
+ transport.uploadHandler = new
mw.ApiUploadFormDataHandler( this.upload, this.api );
+ transport.uploadHandler.start();
} );
+
+ this.transport = transport;
}
+
return this.transport;
},
diff --git a/resources/mw.FirefoggTransport.js
b/resources/mw.FirefoggTransport.js
index bd90dbb..54e3f1c 100644
--- a/resources/mw.FirefoggTransport.js
+++ b/resources/mw.FirefoggTransport.js
@@ -4,14 +4,14 @@
* Represents a "transport" for files to upload; in this case using
Firefogg.
* @extends OO.EventEmitter
* @constructor
- * @param {mw.UploadWizardUpload} upload
+ * @param {File} file
* @param {mw.Api} api
* @param {Firefogg} fogg Firefogg instance
*/
- mw.FirefoggTransport = function ( upload, api, fogg ) {
+ mw.FirefoggTransport = function ( file, api, fogg ) {
oo.EventEmitter.call( this );
- this.upload = upload;
+ this.fileToUpload = file;
this.api = api;
this.fogg = fogg;
};
@@ -24,24 +24,13 @@
* Do an upload
*/
doUpload: function () {
- var fileToUpload, transport = this;
+ var fileToUpload = this.fileToUpload, transport = this;
//Encode or passthrough Firefogg before upload
if ( this.isUploadFormat() ) {
- if ( this.upload.ui.$fileInputCtrl[0].files &&
this.upload.ui.$fileInputCtrl[0].files.length ) {
- fileToUpload =
this.upload.ui.$fileInputCtrl[0].files[0];
- } else if ( this.upload.file ) {
- fileToUpload = this.upload.file;
- } else if ( this.upload.providedFile ) {
- fileToUpload = this.upload.providedFile;
- } else {
- mw.log.warn( 'Firefogg tried to upload
a file but was unable to find one.' );
- return false;
- }
-
this.doFormDataUpload( fileToUpload );
} else {
- this.upload.ui.setStatus( 'mwe-upwiz-encoding'
);
+ this.emit( 'encoding' );
this.fogg.encode( JSON.stringify(
this.getEncodeSettings() ),
function (result, file) {
result = JSON.parse(result);
@@ -59,24 +48,15 @@
transport.emit(
'transported', response );
}
- }, function ( progress ) { //progress
- if ( transport.upload.state ===
'aborted' ) {
- transport.fogg.cancel();
- } else {
- progress =
JSON.parse(progress);
- transport.emit(
'progress', progress );
-
transport.upload.ui.setStatus( 'mwe-upwiz-encoding' );
- }
+ }, function ( progress ) {
+ transport.emit( 'progress',
JSON.parse( progress ) );
}
);
}
},
doFormDataUpload: function (file) {
- this.upload.ui.setStatus( 'mwe-upwiz-uploading' );
- this.upload.file = file;
- this.uploadHandler = new mw.ApiUploadFormDataHandler(
this.upload, this.api );
- this.uploadHandler.start();
+ this.emit( 'starting', file );
},
/**
* Check if the asset is in a format that can be upload without
encoding.
--
To view, visit https://gerrit.wikimedia.org/r/178230
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ief906848344d2986ddc28a095f9470b2b6299325
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: MarkTraceur <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits