http://www.mediawiki.org/wiki/Special:Code/MediaWiki/62015
Revision: 62015 Author: dale Date: 2010-02-05 06:19:57 +0000 (Fri, 05 Feb 2010) Log Message: ----------- * some firefogg code refactor clean/up * fixed onCancel call missing dialog element * removed some deprecated mw vars * disabled chunk uploading per Tims disabled on commons Modified Paths: -------------- branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/jquery.simpleUploadForm.js branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.BaseUploadInterface.js branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.Firefogg.js branches/js2-work/phase3/js/mwEmbed/mwEmbed.js branches/js2-work/phase3/js/mwEmbed/remotes/mediaWiki.js branches/js2-work/phase3/js/mwEmbed/skins/ctrlBuilder.js branches/js2-work/phase3/js/uploadPage.js Modified: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/jquery.simpleUploadForm.js =================================================================== --- branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/jquery.simpleUploadForm.js 2010-02-05 05:52:27 UTC (rev 62014) +++ branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/jquery.simpleUploadForm.js 2010-02-05 06:19:57 UTC (rev 62015) @@ -147,7 +147,7 @@ 'form_rewrite': true, // MediaWiki API supports chunk uploads: - 'enable_chunks' : true, + 'enable_chunks' : false, 'form_selector' : '#suf_upload', 'new_source_cb' : function( orgFilename, oggName ) { Modified: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.BaseUploadInterface.js =================================================================== --- branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.BaseUploadInterface.js 2010-02-05 05:52:27 UTC (rev 62014) +++ branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.BaseUploadInterface.js 2010-02-05 06:19:57 UTC (rev 62015) @@ -104,7 +104,7 @@ }, /** - * onsubmit handler for the upload form + * onSubmit handler for the upload form */ onSubmit: function() { var _this = this; @@ -257,12 +257,26 @@ // Add API action if ( $form.find( "[name='action']" ).length == 0 ){ - $form.append( '<input type="hidden" name="action" value="upload">' ); + $form.append( + $j('<input />') + .attr({ + 'type': "hidden", + 'name' : "action", + 'value' : "upload" + }) + ) } // Add JSON response format if ( $form.find( "[name='format']" ).length == 0 ){ - $form.append( '<input type="hidden" name="format" value="jsonfm">' ); + $form.append( + $j( '<input />' ) + .attr({ + 'type' : "hidden", + 'name' : "format", + 'value' : "jsonfm" + }) + ) } // Map a new hidden form @@ -910,7 +924,7 @@ beforeclose: function( event, ui ) { // If the upload is not complete, ask the user if they want to cancel if ( event.button == 0 && _this.action_done === false ) { - _this.onCancel(); + _this.onCancel( this ); return false; } else { // Complete already, allow close @@ -955,13 +969,13 @@ /** * UI cancel button handler. * Show a dialog box asking the user whether they want to cancel an upload. - * FIXME: doesn't work at all. + * @param Element dialogElement Dialog element to be canceled */ - onCancel: function( dlElm ) { + onCancel: function( dialogElement ) { //confirm: if ( confirm( gM( 'mwe-cancel-confim' ) ) ) { // NOTE: (cancel the encode / upload) - $j( dlElm ).dialog( 'close' ); + $j( dialogElement ).dialog( 'close' ); } } }; Modified: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.Firefogg.js =================================================================== --- branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.Firefogg.js 2010-02-05 05:52:27 UTC (rev 62014) +++ branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.Firefogg.js 2010-02-05 06:19:57 UTC (rev 62015) @@ -442,11 +442,21 @@ // Add the preview button and canvas $j( '#upProgressDialog' ).append( - '<div style="clear:both;height:3em"/>' + - buttonHtml + - '<div style="padding:10px;">' + - '<canvas style="margin:auto;" id="fogg_preview_canvas" />' + - '</div>' + $j('<div />') + .css({ + "clear" : 'both', + 'height' : '3em' + }), + buttonHtml, + $j('<div />') + .css({ + "padding" : '10px' + }) + .append( + $j( '<canvas />' ) + .css('margin', 'auto' ) + .attr( 'id', 'fogg_preview_canvas') + ) ); // Set the initial state @@ -494,13 +504,19 @@ var _this = this; // Set up the hidden video to pull frames from if( $j( '#fogg_preview_vid' ).length == 0 ) - $j( 'body' ).append( '<video id="fogg_preview_vid" style="display:none"></video>' ); + $j( 'body' ).append( + $j('<video />') + .attr( 'id', "fogg_preview_vid") + .css( "display", 'none' ) + ); var v = $j( '#fogg_preview_vid' ).get( 0 ); function seekToEnd() { var v = $j( '#fogg_preview_vid' ).get( 0 ); - // TODO: document arbitrary 0.4s constant - v.currentTime = v.duration - 0.4; + if( v ){ + // Seek to near the end of the clip ( arbitrary -.4 seconds from end ) + v.currentTime = v.duration - 0.4; + } } function renderFrame() { var v = $j( '#fogg_preview_vid' ).get( 0 ); @@ -773,6 +789,7 @@ mw.log( 'base setupAutoEncoder::' + this.getSourceFileInfo().contentType + ' passthrough:' + settings['passthrough'] ); + this.current_encoder_settings = settings; } return this.current_encoder_settings; @@ -791,7 +808,7 @@ }, isOggFormat: function() { - var contentType = this.getSourceFileInfo().contentType; + var contentType = this.getSourceFileInfo().contentType; return ( contentType.indexOf("video/ogg") != -1 || contentType.indexOf("application/ogg") != -1 ); }, @@ -824,7 +841,7 @@ // If Firefogg is disabled or doing an copyByUrl upload, just invoke the parent method if( !this.getFirefogg() || this.isCopyUpload() ) { _this.pe_doUpload(); - return; + return ; } // Get the input form data into an array mw.log( 'get this.formData ::' ); @@ -839,9 +856,36 @@ this.formData[ data[i]['name'] ] = data[i]['value']; } } - } + } - + // Get the edit token from formData if it's not set already + if ( !_this.editToken && _this.formData['token'] ) { + _this.editToken = _this.formData['token']; + } + + if( _this.editToken ) { + mw.log( 'we already have an edit token: ' + _this.editToken ); + _this.doUploadWithFormData(); + return; + } + + // No edit token. Fetch it asynchronously and then do the upload. + mw.getToken( _this.api_url, 'File:'+ _this.formData['filename'], function( editToken ) { + if( !editToken || editToken == '+\\' ) { + _this.updateProgressWin( gM( 'fogg-badtoken' ), gM( 'fogg-badtoken' ) ); + return false; + } + _this.editToken = editToken; + _this.doUploadWithFormData(); + } ); + + }, + + /** + * Internal function called once the token and form data is avaliable + */ + doUploadWithFormData: function(){ + var _this = this; // We can do a chunk upload if( _this.upload_mode == 'post' && _this.enable_chunks ){ _this.doChunkUpload(); @@ -853,16 +897,10 @@ }, function /* onDone */ () { mw.log( 'done with encoding do POST upload:' + _this.form.action ); - // ignore warnings & set source type - //_this.formData[ 'wpIgnoreWarning' ]='true'; - _this.formData['wpSourceType'] = 'upload'; - _this.formData['action'] = 'submit'; - - // wpUploadFile is set by firefogg - delete _this.formData['file']; - - _this.fogg.post( _this.editForm.action, 'wpUploadFile', - JSON.stringify( _this.formData ) ); + + var uploadRequest = _this.getUploadApiRequest(); + _this.fogg.post( _this.api_url, 'file', JSON.stringify( uploadRequest ) ); + _this.doUploadStatus(); } ); @@ -894,55 +932,52 @@ _this.formData['filename'] = fileName.replace( extreg, '.ogg' ); } } + _this.doChunkUploadWithFormData(); + }, + + /** + * Get the uplaod api request object from _this.formData + * + * @param {Object} options Options + */ + getUploadApiRequest: function( options ){ + var _this = this; + var request = { + 'action': 'upload', + 'format': 'json', + 'filename': _this.formData['filename'], + 'comment': _this.formData['comment'], + }; + if( options && options.enable_chunks == true ){ + request[ 'enablechunks' ] = 'true'; + } - // Get the edit token from formData if it's not set already - if ( !_this.editToken && _this.formData['token'] ) { - _this.editToken = _this.formData['token']; + if ( _this.editToken ){ + request['token'] = this.editToken; } - if( _this.editToken ) { - mw.log( 'we already have an edit token: ' + _this.editToken ); - _this.doChunkUploadWithFormData(); - return; + if ( _this.formData['watch'] ){ + request['watch'] = _this.formData['watch']; } - // No edit token. Fetch it asynchronously and then do the upload. - mw.getToken( _this.api_url, 'File:'+ _this.formData['filename'], function( editToken ) { - if( !editToken || editToken == '+\\' ) { - _this.updateProgressWin( gM( 'fogg-badtoken' ), gM( 'fogg-badtoken' ) ); - return false; - } - _this.editToken = editToken; - _this.doChunkUploadWithFormData(); - } ); + if ( _this.formData['ignorewarnings'] ){ + request['ignorewarnings'] = _this.formData['ignorewarnings']; + } + + return request; }, - + /** - * Internal function called from doChunkUpload() when the edit token is available + * Internal function called from doChunkUpload() when form data is available */ doChunkUploadWithFormData: function() { var _this = this; mw.log( "firefogg::doChunkUploadWithFormData: " + _this.editToken ); - // Build the API URL - var aReq = { - 'action': 'upload', - 'format': 'json', - 'filename': _this.formData['filename'], - 'comment': _this.formData['comment'], - 'enablechunks': 'true' - }; + // get the upload api request; + var uploadRequest = this.getUploadApiRequest( { 'enable_chunks' : true } ); - if ( _this.editToken ) - aReq['token'] = this.editToken; - - if ( _this.formData['watch'] ) - aReq['watch'] = _this.formData['watch']; - - if ( _this.formData['ignorewarnings'] ) - aReq['ignorewarnings'] = _this.formData['ignorewarnings']; - var encoderSettings = this.getEncoderSettings(); - mw.log( 'do fogg upload/encode call: ' + _this.api_url + ' :: ' + JSON.stringify( aReq ) ); + mw.log( 'do fogg upload/encode call: ' + _this.api_url + ' :: ' + JSON.stringify( uploadRequest ) ); mw.log( 'foggEncode: ' + JSON.stringify( encoderSettings ) ); _this.fogg.upload( JSON.stringify( encoderSettings ), _this.api_url, JSON.stringify( aReq ) ); @@ -959,11 +994,18 @@ * * Asynchronous, returns immediately. */ - doEncode : function( progressCallback, doneCallback ) { + doEncode: function( progressCallback, doneCallback ) { var _this = this; _this.action_done = false; _this.displayProgressOverlay(); + var encoderSettings = this.getEncoderSettings(); + + // Check if encoderSettings passthrough is on ( then skip the encode ) + if( encoderSettings['passthrough'] == true){ + doneCallback(); + } + mw.log( 'doEncode: with: ' + JSON.stringify( encoderSettings ) ); _this.fogg.encode( JSON.stringify( encoderSettings ) ); @@ -981,7 +1023,7 @@ // Update progress progressCallback( _this.fogg.progress() ); - //loop to get new status if still encoding + // Loop to get new status if still encoding if ( _this.fogg.state == 'encoding' ) { setTimeout( encodingStatus, 500 ); } else if ( _this.fogg.state == 'encoding done' ) { @@ -1047,21 +1089,22 @@ _this.renderPreview(); } } - + mw.log("update progress: " + _this.fogg.progress() + ' state: ' + _this.fogg.state ); // Update the progress bar _this.updateProgress( _this.fogg.progress() ); // If we're still uploading or encoding, continue to poll the status if ( _this.fogg.state == 'encoding' || _this.fogg.state == 'uploading' ) { setTimeout( uploadStatus, 100 ); - return; + return true; } // Upload done? if ( -1 == $j.inArray( _this.fogg.state, [ 'upload done', 'done', 'encoding done' ] ) ) { mw.log( 'Error:firefogg upload error: ' + _this.fogg.state ); - return; + return ; } + if ( apiResult && apiResult.resultUrl ) { var buttons = {}; buttons[ gM( 'mwe-go-to-resource' ) ] = function() { @@ -1092,8 +1135,9 @@ /** * This is the cancel button handler, referenced by getCancelButton() in the parent. + * @param {Element} dialogElement Dialog element that was "canceled" */ - onCancel: function( dlElm ) { + onCancel: function( dialogElement ) { if ( !this.have_firefogg ) { return this.pe_cancel_action(); } @@ -1104,8 +1148,8 @@ alert( 'sorry we do not yet support cancel on windows' ); } else { this.action_done = true; - this.fogg.cancel(); - $j( dlElm ).empty().dialog( 'close' ); + this.fogg.cancel(); + $j( dialogElement ).empty().dialog( 'close' ); } } // Don't follow the # link: Modified: branches/js2-work/phase3/js/mwEmbed/mwEmbed.js =================================================================== --- branches/js2-work/phase3/js/mwEmbed/mwEmbed.js 2010-02-05 05:52:27 UTC (rev 62014) +++ branches/js2-work/phase3/js/mwEmbed/mwEmbed.js 2010-02-05 06:19:57 UTC (rev 62015) @@ -91,14 +91,7 @@ mw.valid_skins = [ 'mvpcf', 'kskin' ]; // The version of mwEmbed - mw.version = '1.1'; - - /** - * Some global containers flags - */ - mw.skin_list = new Array(); - mw.init_done = false; - mw.cb_count = 0; + mw.version = '1.1'; /** * Configuration System: @@ -109,7 +102,7 @@ // Local scope configuration var: var mwConfig = { }; - // Stores global callbacks + // Stores global callbacks for script-loader loading var mwLoadDoneCB = { }; //Local scope mwUserConfig var. Stores user configuration Modified: branches/js2-work/phase3/js/mwEmbed/remotes/mediaWiki.js =================================================================== --- branches/js2-work/phase3/js/mwEmbed/remotes/mediaWiki.js 2010-02-05 05:52:27 UTC (rev 62014) +++ branches/js2-work/phase3/js/mwEmbed/remotes/mediaWiki.js 2010-02-05 06:19:57 UTC (rev 62015) @@ -7,7 +7,7 @@ var mwRemoteVersion = 'r90'; var mwUseScriptLoader = true; -//Log the mwRemote version ( will determine what version of js we get ) +// Log the mwRemote version ( will determine what version of js we get ) if( window.console ){ window.console.log( 'mwEmbed:remote:' + mwRemoteVersion ); } @@ -301,8 +301,8 @@ */ function mwGetReqArgs() { var rurl = ''; - //if ( mwReqParam['debug'] ) - // rurl += 'debug=true&'; + if ( mwReqParam['debug'] ) + rurl += 'debug=true&'; if ( mwReqParam['uselang'] ) rurl += 'uselang=' + mwReqParam['uselang'] + '&'; Modified: branches/js2-work/phase3/js/mwEmbed/skins/ctrlBuilder.js =================================================================== --- branches/js2-work/phase3/js/mwEmbed/skins/ctrlBuilder.js 2010-02-05 05:52:27 UTC (rev 62014) +++ branches/js2-work/phase3/js/mwEmbed/skins/ctrlBuilder.js 2010-02-05 06:19:57 UTC (rev 62015) @@ -178,25 +178,41 @@ function() { if ( $j( '#gnp_' + embedPlayer.id ).length == 0 ) { var toppos = ( embedPlayer.instanceOf == 'mvPlayList' ) ? 25 : 10; - $j( this ).append( '<div id="gnp_' + embedPlayer.id + '" class="ui-state-highlight ui-corner-all" ' + - 'style="position:absolute;display:none;background:#FFF;color:#111;top:' + toppos + 'px;left:10px;right:10px;">' + - gM( 'mwe-for_best_experience' ) + - '<br><input id="ffwarn_' + embedPlayer.id + '" type=\"checkbox\">' + - gM( 'mwe-do_not_warn_again' ) + - '</div>' ); - $j( '#ffwarn_' + embedPlayer.id ).click( function() { - if ( $j( this ).is( ':checked' ) ) { - // Set up a cookie for 7 days: - $j.cookie( 'show_player_warning', false, { expires: 7 } ); - // Set the current instance - mw.setConfig( 'show_player_warning', false ); - $j( '#gnp_' + embedPlayer.id ).fadeOut( 'slow' ); - } else { - mw.setConfig( 'show_player_warning', true ); - $j.cookie( 'show_player_warning', true ); - } - - } ); + $j( this ).append( + $j('<div />') + .attr({ + 'id': "gnp_" + embedPlayer.id, + }) + .addClass('ui-state-highlight ui-corner-all') + .css({ + 'position':'absolute', + 'display':'none', + 'background':'#FFF', + 'color':'#111', + 'top' : toppos + 'px', + 'left' : '10px', + 'right' : '10px' + }) + .html( gM( 'mwe-for_best_experience' ) ), + $j('<br />'), + $j('<input />') + .attr({ + 'id' : 'ffwarn_' + embedPlayer.id, + }) + .text( gM( 'mwe-do_not_warn_again' ) ) + .click( function() { + if ( $j( this ).is( ':checked' ) ) { + // Set up a cookie for 7 days: + $j.cookie( 'show_player_warning', false, { expires: 7 } ); + // Set the current instance + mw.setConfig( 'show_player_warning', false ); + $j( '#gnp_' + embedPlayer.id ).fadeOut( 'slow' ); + } else { + mw.setConfig( 'show_player_warning', true ); + $j.cookie( 'show_player_warning', true ); + } + } ) + ); } // Only show the warning if cookie and config are true if ( mw.getConfig( 'show_player_warning' ) === true ) Modified: branches/js2-work/phase3/js/uploadPage.js =================================================================== --- branches/js2-work/phase3/js/uploadPage.js 2010-02-05 05:52:27 UTC (rev 62014) +++ branches/js2-work/phase3/js/uploadPage.js 2010-02-05 06:19:57 UTC (rev 62015) @@ -20,7 +20,7 @@ 'api_url': wgServer + wgScriptPath + '/api.php', 'form_rewrite': true, // MediaWiki API supports chunk uploads: - 'enable_chunks' : true, + 'enable_chunks' : false, 'form_selector': mwUploadFormSelector, 'new_source_cb': function( orgFilename, oggName ) { $j( '#wpDestFile' ).val( oggName ); _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs