From 3192363855b9f5b0f55522e6e711fb670127f842 Mon Sep 17 00:00:00 2001 From: Michael Dale Date: Wed, 25 Nov 2009 19:02:37 +0000 Subject: [PATCH] * restored basic non-firefogg upload functionality per r59320 breakage --- .../libAddMedia/mvBaseUploadInterface.js | 49 +++++++++---------- js2/mwEmbed/libAddMedia/mvFirefogg.js | 26 +++++----- js2/mwEmbed/libAddMedia/simpleUploadForm.js | 8 +-- 3 files changed, 40 insertions(+), 43 deletions(-) diff --git a/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js b/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js index 9833d54ee8..c223a256ea 100644 --- a/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js +++ b/js2/mwEmbed/libAddMedia/mvBaseUploadInterface.js @@ -93,7 +93,7 @@ mvBaseUploadInterface.prototype = { // Set up the submit action: $j( this.form ).submit( function() { - _this.onSubmit(); + return _this.onSubmit(); } ); }, @@ -101,8 +101,8 @@ mvBaseUploadInterface.prototype = { * onsubmit handler for the upload form */ onSubmit: function() { + var _this = this; js_log( 'Base::onSubmit:' ); - // Run the original onsubmit (if not run yet set flag to avoid excessive chaining) if ( typeof( this.orig_onsubmit ) == 'function' ) { if ( ! this.orig_onsubmit() ) { @@ -123,18 +123,19 @@ mvBaseUploadInterface.prototype = { for ( var i = 0; i < data.length; i++ ) { if ( data[i]['name'] ) this.formData[ data[i]['name'] ] = data[i]['value']; - } + } // Put into a try catch so we are sure to return false: try { - // Get a clean loader: - // FIXME: this function does not exist in this class - this.displayProgressOverlay(); + + // Display a progress dialog + _this.displayProgressOverlay(); // For some unknown reason we have to drop down the #p-search z-index: $j( '#p-search' ).css( 'z-index', 1 ); var _this = this; - this.detectUploadMode( function( mode ) { + _this.detectUploadMode( function( mode ) { + _this.upload_mode = mode; _this.doUpload(); } ); } catch( e ) { @@ -143,7 +144,7 @@ mvBaseUploadInterface.prototype = { // Don't submit the form we will do the post in ajax return false; - } + }, /** * Determine the correct upload mode. @@ -218,13 +219,13 @@ mvBaseUploadInterface.prototype = { */ doUpload: function() { if ( this.upload_mode == 'api' ) { - _this.doApiCopyUpload(); + this.doApiCopyUpload(); } else if ( this.upload_mode == 'post' ) { - _this.doPostUpload(); + this.doPostUpload(); } else { js_error( 'Error: unrecongized upload mode: ' + this.upload_mode ); } - } + }, /** * Change the upload form so that when submitted, it sends a request to @@ -235,6 +236,7 @@ mvBaseUploadInterface.prototype = { * selected a file in them, which they may well do before DOM ready. */ remapFormToApi: function() { + var _this = this; if ( !this.api_url ) return false; @@ -263,15 +265,13 @@ mvBaseUploadInterface.prototype = { /** * Returns true if the current form has copy upload selected, false otherwise. */ - isCopyUpload: function() { - if ( this.http_copy_upload == null ) { - if ( $j( '#wpSourceTypeFile' ).length == 0 - || $j( '#wpSourceTypeFile' ).get( 0 ).checked ) - { - this.http_copy_upload = false; - } else if ( $j('#wpSourceTypeURL').get( 0 ).checked ) { - this.http_copy_upload = true; - } + isCopyUpload: function() { + if ( $j( '#wpSourceTypeFile' ).length == 0 + || $j( '#wpSourceTypeFile' ).get( 0 ).checked ) + { + this.http_copy_upload = false; + } else if ( $j('#wpSourceTypeURL').get( 0 ).checked ) { + this.http_copy_upload = true; } return this.http_copy_upload; }, @@ -358,7 +358,7 @@ mvBaseUploadInterface.prototype = { } else if ( doc.body ) { // Get the json string json = $j( doc.body ).find( 'pre' ).text(); - js_log( 'iframe:json::' + json_str + "\nbody:" + $j( doc.body ).html() ); + //js_log( 'iframe:json::' + json_str + "\nbody:" + $j( doc.body ).html() ); if ( json ) { response = window["eval"]( "(" + json + ")" ); } else { @@ -436,7 +436,7 @@ mvBaseUploadInterface.prototype = { // Trigger an initial request (subsequent ones will be done by a timer) this.onAjaxUploadStatusTimer(); - } + }, /** * This is called when the timer which separates XHR requests elapses. @@ -778,7 +778,7 @@ mvBaseUploadInterface.prototype = { js_log( "call done_upload_cb" ); // This overrides our normal completion handling so we close the // dialog immediately. - $j( '#upProgressDialog' ).dialog( 'close' ); + $j( '#upProgressDialog' ).dialog( 'destroy' ).remove(); _this.done_upload_cb( apiRes.upload ); return false; } @@ -786,7 +786,7 @@ mvBaseUploadInterface.prototype = { var buttons = {}; // "Return" button buttons[ gM( 'mwe-return-to-form' ) ] = function() { - $j( this ).dialog( 'close' ); + $j( this ).dialog( 'destroy' ).remove(); _this.form_post_override = false; } // "Go to resource" button @@ -866,7 +866,6 @@ mvBaseUploadInterface.prototype = { */ displayProgressOverlay: function() { var _this = this; - // Remove the old instance if present if( $j( '#upProgressDialog' ).length != 0 ) { $j( '#upProgressDialog' ).dialog( 'destroy' ).remove(); diff --git a/js2/mwEmbed/libAddMedia/mvFirefogg.js b/js2/mwEmbed/libAddMedia/mvFirefogg.js index 4149093a77..92629b2420 100644 --- a/js2/mwEmbed/libAddMedia/mvFirefogg.js +++ b/js2/mwEmbed/libAddMedia/mvFirefogg.js @@ -243,7 +243,7 @@ mvFirefogg.prototype = { // extends mvBaseUploadInterface // Now show the form $j( _this.selector ).show(); - if ( _this.firefoggCheck() ) { + if ( _this.getFirefogg() ) { // Firefogg enabled // If we're in upload mode, show the input filename if ( _this.form_type == 'upload' ) @@ -294,11 +294,13 @@ mvFirefogg.prototype = { // extends mvBaseUploadInterface } // Set up the click handler for the "save local file" button - $j( _this.target_btn_save_local_file ) + if( _this.target_btn_save_local_file ){ + $j( _this.target_btn_save_local_file ) .unbind() .click( function() { _this.doLocalEncodeAndSave(); } ); + } }, /* @@ -347,7 +349,7 @@ mvFirefogg.prototype = { // extends mvBaseUploadInterface } // If Firefogg is not available, just show a "please install" message - if ( !this.firefoggCheck() ) { + if ( !this.getFirefogg() ) { if ( !this.target_please_install ) { $j( this.selector ).after( this.getControlHtml( 'target_please_install' ) ); this.target_please_install = this.selector + ' ~ .target_please_install'; @@ -393,7 +395,7 @@ mvFirefogg.prototype = { // extends mvBaseUploadInterface * Display an upload progress overlay. Overrides the function in mvBaseUploadInterface. */ displayProgressOverlay: function() { - this.pe_dispProgressOverlay(); + this.pe_displayProgressOverlay(); // If we are uploading video (not in passthrough mode), show preview button if( this.getFirefogg() && !this.getEncoderSettings()['passthrough'] && !this.isCopyUpload() ) @@ -666,7 +668,7 @@ mvFirefogg.prototype = { // extends mvBaseUploadInterface _this.updateProgress( 1 ); setTimeout( function() { _this.onLocalEncodeDone(); - } + }); } ); }, @@ -674,7 +676,7 @@ mvFirefogg.prototype = { // extends mvBaseUploadInterface /** * This is called when a local encode operation has completed. It updates the UI. */ - onLocalEncodeDone() { + onLocalEncodeDone: function() { var _this = this; _this.updateProgressWin( gM( 'fogg-encoding-done' ), gM( 'fogg-encoding-done' ) + '
' + @@ -717,11 +719,11 @@ mvFirefogg.prototype = { // extends mvBaseUploadInterface * Get the appropriate encoder settings for the current Firefogg object, * into which a video has already been selected. */ - getEncoderSettings function() { + getEncoderSettings: function() { if ( this.current_encoder_settings == null ) { // Clone the default settings - var defaults = function () {}; - var defaults.prototype = this.default_encoder_settings; + var defaults = function () { }; + defaults.prototype = this.default_encoder_settings; var settings = new defaults(); // Grab the extension @@ -848,11 +850,7 @@ mvFirefogg.prototype = { // extends mvBaseUploadInterface if ( dotPos != -1 ) { ext = fileName.substring( dotPos ).toLowerCase(); } - if ( $j.inArray( ext.substr( 1 ), _this.ogg_extensions ) == -1 ) { - _this.formData['filename'] = fileName.substr( - 0, - - + if ( $j.inArray( ext.substr( 1 ), _this.ogg_extensions ) == -1 ) { var extreg = new RegExp( ext + '$', 'i' ); _this.formData['filename'] = fileName.replace( extreg, '.ogg' ); } diff --git a/js2/mwEmbed/libAddMedia/simpleUploadForm.js b/js2/mwEmbed/libAddMedia/simpleUploadForm.js index e3013ad5b7..a2ec3fb693 100644 --- a/js2/mwEmbed/libAddMedia/simpleUploadForm.js +++ b/js2/mwEmbed/libAddMedia/simpleUploadForm.js @@ -19,7 +19,7 @@ loadGM( { var default_form_options = { 'enable_fogg' : true, - 'licence_options':['cc-by-sa'], + 'licence_options' : ['cc-by-sa'], 'api_target' : false, 'ondone_cb' : null }; @@ -53,7 +53,7 @@ var default_form_options = { // hidden input: '' + '' + - '' + + '' + // form name set: '
' + @@ -121,7 +121,7 @@ var default_form_options = { // do destination check: - $j( "#wpDestFile" ).change( function() { + $j( "#wpDestFile" ).change( function() { $j( "#wpDestFile" ).doDestCheck( { 'warn_target':'#wpDestFile-warning' } ); @@ -136,7 +136,7 @@ var default_form_options = { // an api url (we won't submit directly to action of the form) 'api_url' : opt.api_target, 'form_rewrite': true, - 'target_edit_from' : '#suf-upload', + 'edit_form_selector' : '#suf-upload', 'new_source_cb' : function( orgFilename, oggName ) { $j( "#wpDestFile" ).val( oggName ).doDestCheck( { warn_target: "#wpDestFile-warning" -- 2.20.1