r84068 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84067‎ | r84068 | r84069 >
Date:23:35, 15 March 2011
Author:neilk
Status:deferred
Tags:
Comment:
manually deleting these files which were added in r84000, because svn gives funny conflicts otherwise. See branch uploadwizard-firefogg for now
Modified paths:
  • /trunk/extensions/UploadWizard/resources/mw.FirefoggHandler.js (deleted) (history)
  • /trunk/extensions/UploadWizard/resources/mw.FirefoggTransport.js (deleted) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/resources/mw.FirefoggHandler.js
@@ -1,105 +0,0 @@
2 -/**
3 - * An attempt to refactor out the stuff that does API-via-iframe transport
4 - * In the hopes that this will eventually work for AddMediaWizard too
5 - */
6 -
7 -/**
8 - * Represents an object which configures a form to upload its files via an iframe talking to the MediaWiki API.
9 - * @param an UploadInterface object, which contains a .form property which points to a real HTML form in the DOM
10 - */
11 -mw.FirefoggHandler = function( upload ) {
12 - return this.init( upload );
13 -};
14 -
15 -mw.FirefoggHandler.prototype = {
16 - // The transport object
17 - transport : null, // lazy init
18 - /**
19 - * Constructor
20 - */
21 - init: function( upload ){
22 - this.upload = upload;
23 - this.api = upload.api;
24 -
25 - // Setup local pointer to firefogg instance
26 - this.fogg = new Firefogg();
27 -
28 - // the Iframe transport is hardcoded for now because it works everywhere
29 - // can also use Xhr Binary depending on browser
30 - var _this = this;
31 -
32 - },
33 - getTransport: function(){
34 - var _this = this;
35 - if( this.transport ){
36 - return this.transport;
37 - }
38 - this.transport = new mw.FirefoggTransport(
39 - this.getForm(),
40 - this.fogg,
41 - function( fraction ) {
42 - _this.upload.setTransportProgress( fraction );
43 - // also update preview video:
44 - },
45 - function( result ) {
46 - _this.upload.setTransported( result );
47 - }
48 - );
49 - return this.transport;
50 - },
51 - isGoodExtension: function( ext ){
52 - // First check if its an oky extension for the wiki:
53 - if( $j.inArray( ext.toLowerCase(), mw.UploadWizard.config[ 'fileExtensions' ] ) !== -1 ){
54 - return true;
55 - }
56 - // Check if its a file that can be transcoded:
57 - if( this.getTransport().isSourceAudio() || this.getTransport().isSourceVideo() ){
58 - return true;
59 - }
60 - return false;
61 - },
62 -
63 - getForm: function(){
64 - return $j( this.upload.ui.form );
65 - },
66 -
67 - /**
68 - * Get a pointer to the "file" input control
69 - */
70 - getInputControl: function(){
71 - var _this = this;
72 - return $j('<input />').attr({
73 - 'size': "1",
74 - 'name': "file",
75 - 'type': "text"
76 - })
77 - .addClass( "mwe-upwiz-file-input" )
78 - .click( function() {
79 - if( _this.fogg.selectVideo() ) {
80 - // Update the value of the input file:
81 - $j( _this.upload.ui.div ).find(".mwe-upwiz-file-input").val( _this.fogg.sourceFilename );
82 - // trigger the change event
83 - _this.upload.ui.fileChanged();
84 - }
85 - } );
86 - },
87 -
88 - /**
89 - * If chunks are disabled transcode then upload else
90 - * upload and transcode at the same time
91 - */
92 - start: function() {
93 - var _this = this;
94 - _this.api.getEditToken( function( token ) {
95 - mw.log( "mw.FirefoggHandler::start> upload start!" );
96 -
97 - _this.beginTime = ( new Date() ).getTime();
98 - _this.upload.ui.setStatus( 'mwe-upwiz-transport-started' );
99 - _this.upload.ui.showTransportProgress();
100 - _this.transport.doUpload( _this.fogg );
101 -
102 - }, function( code, info ) {
103 - _this.upload.setError( code, info );
104 - } );
105 - }
106 -};
Index: trunk/extensions/UploadWizard/resources/mw.FirefoggTransport.js
@@ -1,170 +0,0 @@
2 -/**
3 - * Represents a "transport" for files to upload; in this case an firefogg.
4 - * XXX dubious whether this is really separated from "ApiUploadHandler", which does a lot of form config.
5 - *
6 - * The iframe is made to be the target of a form so that the existing page does not reload, even though it's a POST.
7 - * @param form jQuery selector for HTML form
8 - * @param progressCb callback to execute when we've started. (does not do float here because iframes can't
9 - * monitor fractional progress).
10 - * @param transportedCb callback to execute when we've finished the upload
11 - */
12 -mw.FirefoggTransport = function( $form, fogg, progressCb, transportedCb ) {
13 - this.$form = $form;
14 - this.fogg = fogg;
15 - this.progressCb = progressCb;
16 - this.transportedCb = transportedCb;
17 -};
18 -
19 -mw.FirefoggTransport.prototype = {
20 -
21 - passthrough: false,
22 - /**
23 - * Do an upload on a given fogg object:
24 - */
25 - doUpload: function( fogg ){
26 - // check if the server supports chunks:
27 - if( this.isChunkUpload() ){
28 - mw.log("FirefoggTransport::doUpload> Chunks");
29 - // encode and upload at the same time:
30 - this.doChunkUpload();
31 - } else {
32 - mw.log("FirefoggTransport::doUpload> Encode then upload");
33 - this.doEncodeThenUpload();
34 - }
35 - },
36 - isChunkUpload: function(){
37 - return false;
38 - return ( mw.UploadWizard.config[ 'enableFirefoggChunkUpload' ] );
39 - },
40 - /**
41 - * Check if the asset should be uploaded in passthrough mode ( or if it should be encoded )
42 - */
43 - isPassThrough: function(){
44 - // Check if the server supports raw webm uploads:
45 - var wembExt = ( $j.inArray( mw.UploadWizard.config[ 'fileExtensions'], 'webm') !== -1 )
46 - // Determine passthrough mode
47 - if ( this.isOggFormat() || ( wembExt && isWebMFormat() ) ) {
48 - // Already Ogg, no need to encode
49 - return true;
50 - } else if ( this.isSourceAudio() || this.isSourceVideo() ) {
51 - // OK to encode
52 - return false;
53 - } else {
54 - // Not audio or video, can't encode
55 - return true;
56 - }
57 - },
58 -
59 - isSourceAudio: function() {
60 - return ( this.getSourceFileInfo().contentType.indexOf("audio/") != -1 );
61 - },
62 -
63 - isSourceVideo: function() {
64 - return ( this.getSourceFileInfo().contentType.indexOf("video/") != -1 );
65 - },
66 -
67 - isOggFormat: function() {
68 - var contentType = this.getSourceFileInfo().contentType;
69 - return ( contentType.indexOf("video/ogg") != -1
70 - || contentType.indexOf("application/ogg") != -1
71 - || contentType.indexOf("audio/ogg") );
72 - },
73 - isWebMFormat: function() {
74 - return ( this.getSourceFileInfo().contentType.indexOf('webm') != -1 );
75 - },
76 -
77 - /**
78 - * Get the source file info for the current file selected into this.fogg
79 - */
80 - getSourceFileInfo: function() {
81 - if ( !this.fogg.sourceInfo ) {
82 - mw.log( 'Error:: No firefogg source info is available' );
83 - return false;
84 - }
85 - try {
86 - this.sourceFileInfo = JSON.parse( this.fogg.sourceInfo );
87 - } catch ( e ) {
88 - mw.log( 'Error :: could not parse fogg sourceInfo' );
89 - return false;
90 - }
91 - return this.sourceFileInfo;
92 - },
93 -
94 - /**
95 - * Get the encode settings from configuration and the current selected video type
96 - */
97 - getEncodeSettings: function(){
98 - var encodeSettings = $j.extend( {}, mw.UploadWizard.config[ 'firefoggEncodeSettings'] , {
99 - 'passthrough' : this.isPassThrough()
100 - })
101 - mw.log("FirefoggTransport::getEncodeSettings> " + JSON.stringify( encodeSettings ) );
102 - return encodeSettings;
103 - },
104 -
105 -
106 -
107 - /**
108 - * Encode then upload
109 - */
110 - doEncodeThenUpload: function(){
111 - this.fogg.encode( JSON.stringify( this.getEncodeSettings() ) );
112 - this.monitorProgress();
113 - },
114 - /**
115 - * Encode and upload in chunks
116 - */
117 - doChunkUpload: function(){
118 - this.fogg.upload(
119 - JSON.stringify( this.getEncodeSettings() ),
120 - this.getUploadUrl(),
121 - JSON.stringify( this.getUploadRequest() )
122 - );
123 - this.monitorProgress();
124 - },
125 - // Get the upload url
126 - getUploadUrl: function(){
127 - return mw.UploadWizard.apiUrl;
128 - },
129 - /**
130 - * get the upload settings
131 - */
132 - getUploadRequest: function(){
133 - return {
134 - 'action' : ( this.isChunkUpload() )? 'firefoggupload' : 'upload',
135 - 'stash' :1,
136 - 'comment' : 'DUMMY TEXT',
137 - 'format' : 'json'
138 - }
139 - },
140 - /**
141 - * Monitor progress on an upload:
142 - */
143 - monitorProgress: function(){
144 - var fogg = this.fogg;
145 - var progress = fogg.progress();
146 -
147 - mw.log("FirefoggTransport::monitorProgress> " + progress + ' state: ' + fogg.state );
148 - this.progressCb( progress );
149 -
150 - if( fogg.state == 'encoding' || fogg.state == 'uploading'){
151 - setTimeout( this.monitorProgress, 500 );
152 - }
153 - // return the api result:
154 - if( fogg.state == 'done' ){
155 - this.transportedCb( this.fogg.responseText );
156 - }
157 -
158 - },
159 -
160 - /**
161 - * Process the result of the form submission, returned to an iframe.
162 - * This is the iframe's onload event.
163 - *
164 - * @param {Element} iframe iframe to extract result from
165 - */
166 - updateProgress: function( iframe ) {
167 - var _this = this;
168 - }
169 -};
170 -
171 -

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r84000* initial stubs for firefogg transport...dale06:20, 15 March 2011

Status & tagging log