r62015 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62014‎ | r62015 | r62016 >
Date:06:19, 5 February 2010
Author:dale
Status:deferred
Tags:
Comment:
* 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 (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.BaseUploadInterface.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.Firefogg.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/mwEmbed.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/remotes/mediaWiki.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/skins/ctrlBuilder.js (modified) (history)
  • /branches/js2-work/phase3/js/uploadPage.js (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js/mwEmbed/skins/ctrlBuilder.js
@@ -178,25 +178,41 @@
179179 function() {
180180 if ( $j( '#gnp_' + embedPlayer.id ).length == 0 ) {
181181 var toppos = ( embedPlayer.instanceOf == 'mvPlayList' ) ? 25 : 10;
182 - $j( this ).append( '<div id="gnp_' + embedPlayer.id + '" class="ui-state-highlight ui-corner-all" ' +
183 - 'style="position:absolute;display:none;background:#FFF;color:#111;top:' + toppos + 'px;left:10px;right:10px;">' +
184 - gM( 'mwe-for_best_experience' ) +
185 - '<br><input id="ffwarn_' + embedPlayer.id + '" type=\"checkbox\">' +
186 - gM( 'mwe-do_not_warn_again' ) +
187 - '</div>' );
188 - $j( '#ffwarn_' + embedPlayer.id ).click( function() {
189 - if ( $j( this ).is( ':checked' ) ) {
190 - // Set up a cookie for 7 days:
191 - $j.cookie( 'show_player_warning', false, { expires: 7 } );
192 - // Set the current instance
193 - mw.setConfig( 'show_player_warning', false );
194 - $j( '#gnp_' + embedPlayer.id ).fadeOut( 'slow' );
195 - } else {
196 - mw.setConfig( 'show_player_warning', true );
197 - $j.cookie( 'show_player_warning', true );
198 - }
199 -
200 - } );
 182+ $j( this ).append(
 183+ $j('<div />')
 184+ .attr({
 185+ 'id': "gnp_" + embedPlayer.id,
 186+ })
 187+ .addClass('ui-state-highlight ui-corner-all')
 188+ .css({
 189+ 'position':'absolute',
 190+ 'display':'none',
 191+ 'background':'#FFF',
 192+ 'color':'#111',
 193+ 'top' : toppos + 'px',
 194+ 'left' : '10px',
 195+ 'right' : '10px'
 196+ })
 197+ .html( gM( 'mwe-for_best_experience' ) ),
 198+ $j('<br />'),
 199+ $j('<input />')
 200+ .attr({
 201+ 'id' : 'ffwarn_' + embedPlayer.id,
 202+ })
 203+ .text( gM( 'mwe-do_not_warn_again' ) )
 204+ .click( function() {
 205+ if ( $j( this ).is( ':checked' ) ) {
 206+ // Set up a cookie for 7 days:
 207+ $j.cookie( 'show_player_warning', false, { expires: 7 } );
 208+ // Set the current instance
 209+ mw.setConfig( 'show_player_warning', false );
 210+ $j( '#gnp_' + embedPlayer.id ).fadeOut( 'slow' );
 211+ } else {
 212+ mw.setConfig( 'show_player_warning', true );
 213+ $j.cookie( 'show_player_warning', true );
 214+ }
 215+ } )
 216+ );
201217 }
202218 // Only show the warning if cookie and config are true
203219 if ( mw.getConfig( 'show_player_warning' ) === true )
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.Firefogg.js
@@ -442,11 +442,21 @@
443443
444444 // Add the preview button and canvas
445445 $j( '#upProgressDialog' ).append(
446 - '<div style="clear:both;height:3em"/>' +
447 - buttonHtml +
448 - '<div style="padding:10px;">' +
449 - '<canvas style="margin:auto;" id="fogg_preview_canvas" />' +
450 - '</div>'
 446+ $j('<div />')
 447+ .css({
 448+ "clear" : 'both',
 449+ 'height' : '3em'
 450+ }),
 451+ buttonHtml,
 452+ $j('<div />')
 453+ .css({
 454+ "padding" : '10px'
 455+ })
 456+ .append(
 457+ $j( '<canvas />' )
 458+ .css('margin', 'auto' )
 459+ .attr( 'id', 'fogg_preview_canvas')
 460+ )
451461 );
452462
453463 // Set the initial state
@@ -494,13 +504,19 @@
495505 var _this = this;
496506 // Set up the hidden video to pull frames from
497507 if( $j( '#fogg_preview_vid' ).length == 0 )
498 - $j( 'body' ).append( '<video id="fogg_preview_vid" style="display:none"></video>' );
 508+ $j( 'body' ).append(
 509+ $j('<video />')
 510+ .attr( 'id', "fogg_preview_vid")
 511+ .css( "display", 'none' )
 512+ );
499513 var v = $j( '#fogg_preview_vid' ).get( 0 );
500514
501515 function seekToEnd() {
502516 var v = $j( '#fogg_preview_vid' ).get( 0 );
503 - // TODO: document arbitrary 0.4s constant
504 - v.currentTime = v.duration - 0.4;
 517+ if( v ){
 518+ // Seek to near the end of the clip ( arbitrary -.4 seconds from end )
 519+ v.currentTime = v.duration - 0.4;
 520+ }
505521 }
506522 function renderFrame() {
507523 var v = $j( '#fogg_preview_vid' ).get( 0 );
@@ -773,6 +789,7 @@
774790
775791 mw.log( 'base setupAutoEncoder::' + this.getSourceFileInfo().contentType +
776792 ' passthrough:' + settings['passthrough'] );
 793+
777794 this.current_encoder_settings = settings;
778795 }
779796 return this.current_encoder_settings;
@@ -791,7 +808,7 @@
792809 },
793810
794811 isOggFormat: function() {
795 - var contentType = this.getSourceFileInfo().contentType;
 812+ var contentType = this.getSourceFileInfo().contentType;
796813 return ( contentType.indexOf("video/ogg") != -1
797814 || contentType.indexOf("application/ogg") != -1 );
798815 },
@@ -824,7 +841,7 @@
825842 // If Firefogg is disabled or doing an copyByUrl upload, just invoke the parent method
826843 if( !this.getFirefogg() || this.isCopyUpload() ) {
827844 _this.pe_doUpload();
828 - return;
 845+ return ;
829846 }
830847 // Get the input form data into an array
831848 mw.log( 'get this.formData ::' );
@@ -839,9 +856,36 @@
840857 this.formData[ data[i]['name'] ] = data[i]['value'];
841858 }
842859 }
843 - }
 860+ }
844861
845 -
 862+ // Get the edit token from formData if it's not set already
 863+ if ( !_this.editToken && _this.formData['token'] ) {
 864+ _this.editToken = _this.formData['token'];
 865+ }
 866+
 867+ if( _this.editToken ) {
 868+ mw.log( 'we already have an edit token: ' + _this.editToken );
 869+ _this.doUploadWithFormData();
 870+ return;
 871+ }
 872+
 873+ // No edit token. Fetch it asynchronously and then do the upload.
 874+ mw.getToken( _this.api_url, 'File:'+ _this.formData['filename'], function( editToken ) {
 875+ if( !editToken || editToken == '+\\' ) {
 876+ _this.updateProgressWin( gM( 'fogg-badtoken' ), gM( 'fogg-badtoken' ) );
 877+ return false;
 878+ }
 879+ _this.editToken = editToken;
 880+ _this.doUploadWithFormData();
 881+ } );
 882+
 883+ },
 884+
 885+ /**
 886+ * Internal function called once the token and form data is avaliable
 887+ */
 888+ doUploadWithFormData: function(){
 889+ var _this = this;
846890 // We can do a chunk upload
847891 if( _this.upload_mode == 'post' && _this.enable_chunks ){
848892 _this.doChunkUpload();
@@ -853,16 +897,10 @@
854898 },
855899 function /* onDone */ () {
856900 mw.log( 'done with encoding do POST upload:' + _this.form.action );
857 - // ignore warnings & set source type
858 - //_this.formData[ 'wpIgnoreWarning' ]='true';
859 - _this.formData['wpSourceType'] = 'upload';
860 - _this.formData['action'] = 'submit';
861 -
862 - // wpUploadFile is set by firefogg
863 - delete _this.formData['file'];
864 -
865 - _this.fogg.post( _this.editForm.action, 'wpUploadFile',
866 - JSON.stringify( _this.formData ) );
 901+
 902+ var uploadRequest = _this.getUploadApiRequest();
 903+ _this.fogg.post( _this.api_url, 'file', JSON.stringify( uploadRequest ) );
 904+
867905 _this.doUploadStatus();
868906 }
869907 );
@@ -894,55 +932,52 @@
895933 _this.formData['filename'] = fileName.replace( extreg, '.ogg' );
896934 }
897935 }
 936+ _this.doChunkUploadWithFormData();
 937+ },
 938+
 939+ /**
 940+ * Get the uplaod api request object from _this.formData
 941+ *
 942+ * @param {Object} options Options
 943+ */
 944+ getUploadApiRequest: function( options ){
 945+ var _this = this;
 946+ var request = {
 947+ 'action': 'upload',
 948+ 'format': 'json',
 949+ 'filename': _this.formData['filename'],
 950+ 'comment': _this.formData['comment'],
 951+ };
 952+ if( options && options.enable_chunks == true ){
 953+ request[ 'enablechunks' ] = 'true';
 954+ }
898955
899 - // Get the edit token from formData if it's not set already
900 - if ( !_this.editToken && _this.formData['token'] ) {
901 - _this.editToken = _this.formData['token'];
 956+ if ( _this.editToken ){
 957+ request['token'] = this.editToken;
902958 }
903959
904 - if( _this.editToken ) {
905 - mw.log( 'we already have an edit token: ' + _this.editToken );
906 - _this.doChunkUploadWithFormData();
907 - return;
 960+ if ( _this.formData['watch'] ){
 961+ request['watch'] = _this.formData['watch'];
908962 }
909963
910 - // No edit token. Fetch it asynchronously and then do the upload.
911 - mw.getToken( _this.api_url, 'File:'+ _this.formData['filename'], function( editToken ) {
912 - if( !editToken || editToken == '+\\' ) {
913 - _this.updateProgressWin( gM( 'fogg-badtoken' ), gM( 'fogg-badtoken' ) );
914 - return false;
915 - }
916 - _this.editToken = editToken;
917 - _this.doChunkUploadWithFormData();
918 - } );
 964+ if ( _this.formData['ignorewarnings'] ){
 965+ request['ignorewarnings'] = _this.formData['ignorewarnings'];
 966+ }
 967+
 968+ return request;
919969 },
920 -
 970+
921971 /**
922 - * Internal function called from doChunkUpload() when the edit token is available
 972+ * Internal function called from doChunkUpload() when form data is available
923973 */
924974 doChunkUploadWithFormData: function() {
925975 var _this = this;
926976 mw.log( "firefogg::doChunkUploadWithFormData: " + _this.editToken );
927 - // Build the API URL
928 - var aReq = {
929 - 'action': 'upload',
930 - 'format': 'json',
931 - 'filename': _this.formData['filename'],
932 - 'comment': _this.formData['comment'],
933 - 'enablechunks': 'true'
934 - };
 977+ // get the upload api request;
 978+ var uploadRequest = this.getUploadApiRequest( { 'enable_chunks' : true } );
935979
936 - if ( _this.editToken )
937 - aReq['token'] = this.editToken;
938 -
939 - if ( _this.formData['watch'] )
940 - aReq['watch'] = _this.formData['watch'];
941 -
942 - if ( _this.formData['ignorewarnings'] )
943 - aReq['ignorewarnings'] = _this.formData['ignorewarnings'];
944 -
945980 var encoderSettings = this.getEncoderSettings();
946 - mw.log( 'do fogg upload/encode call: ' + _this.api_url + ' :: ' + JSON.stringify( aReq ) );
 981+ mw.log( 'do fogg upload/encode call: ' + _this.api_url + ' :: ' + JSON.stringify( uploadRequest ) );
947982 mw.log( 'foggEncode: ' + JSON.stringify( encoderSettings ) );
948983 _this.fogg.upload( JSON.stringify( encoderSettings ), _this.api_url,
949984 JSON.stringify( aReq ) );
@@ -959,11 +994,18 @@
960995 *
961996 * Asynchronous, returns immediately.
962997 */
963 - doEncode : function( progressCallback, doneCallback ) {
 998+ doEncode: function( progressCallback, doneCallback ) {
964999 var _this = this;
9651000 _this.action_done = false;
9661001 _this.displayProgressOverlay();
 1002+
9671003 var encoderSettings = this.getEncoderSettings();
 1004+
 1005+ // Check if encoderSettings passthrough is on ( then skip the encode )
 1006+ if( encoderSettings['passthrough'] == true){
 1007+ doneCallback();
 1008+ }
 1009+
9681010 mw.log( 'doEncode: with: ' + JSON.stringify( encoderSettings ) );
9691011 _this.fogg.encode( JSON.stringify( encoderSettings ) );
9701012
@@ -981,7 +1023,7 @@
9821024 // Update progress
9831025 progressCallback( _this.fogg.progress() );
9841026
985 - //loop to get new status if still encoding
 1027+ // Loop to get new status if still encoding
9861028 if ( _this.fogg.state == 'encoding' ) {
9871029 setTimeout( encodingStatus, 500 );
9881030 } else if ( _this.fogg.state == 'encoding done' ) {
@@ -1047,21 +1089,22 @@
10481090 _this.renderPreview();
10491091 }
10501092 }
1051 -
 1093+ mw.log("update progress: " + _this.fogg.progress() + ' state: ' + _this.fogg.state );
10521094 // Update the progress bar
10531095 _this.updateProgress( _this.fogg.progress() );
10541096
10551097 // If we're still uploading or encoding, continue to poll the status
10561098 if ( _this.fogg.state == 'encoding' || _this.fogg.state == 'uploading' ) {
10571099 setTimeout( uploadStatus, 100 );
1058 - return;
 1100+ return true;
10591101 }
10601102
10611103 // Upload done?
10621104 if ( -1 == $j.inArray( _this.fogg.state, [ 'upload done', 'done', 'encoding done' ] ) ) {
10631105 mw.log( 'Error:firefogg upload error: ' + _this.fogg.state );
1064 - return;
 1106+ return ;
10651107 }
 1108+
10661109 if ( apiResult && apiResult.resultUrl ) {
10671110 var buttons = {};
10681111 buttons[ gM( 'mwe-go-to-resource' ) ] = function() {
@@ -1092,8 +1135,9 @@
10931136
10941137 /**
10951138 * This is the cancel button handler, referenced by getCancelButton() in the parent.
 1139+ * @param {Element} dialogElement Dialog element that was "canceled"
10961140 */
1097 - onCancel: function( dlElm ) {
 1141+ onCancel: function( dialogElement ) {
10981142 if ( !this.have_firefogg ) {
10991143 return this.pe_cancel_action();
11001144 }
@@ -1104,8 +1148,8 @@
11051149 alert( 'sorry we do not yet support cancel on windows' );
11061150 } else {
11071151 this.action_done = true;
1108 - this.fogg.cancel();
1109 - $j( dlElm ).empty().dialog( 'close' );
 1152+ this.fogg.cancel();
 1153+ $j( dialogElement ).empty().dialog( 'close' );
11101154 }
11111155 }
11121156 // Don't follow the # link:
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/jquery.simpleUploadForm.js
@@ -147,7 +147,7 @@
148148 'form_rewrite': true,
149149
150150 // MediaWiki API supports chunk uploads:
151 - 'enable_chunks' : true,
 151+ 'enable_chunks' : false,
152152
153153 'form_selector' : '#suf_upload',
154154 'new_source_cb' : function( orgFilename, oggName ) {
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.BaseUploadInterface.js
@@ -104,7 +104,7 @@
105105 },
106106
107107 /**
108 - * onsubmit handler for the upload form
 108+ * onSubmit handler for the upload form
109109 */
110110 onSubmit: function() {
111111 var _this = this;
@@ -257,12 +257,26 @@
258258
259259 // Add API action
260260 if ( $form.find( "[name='action']" ).length == 0 ){
261 - $form.append( '<input type="hidden" name="action" value="upload">' );
 261+ $form.append(
 262+ $j('<input />')
 263+ .attr({
 264+ 'type': "hidden",
 265+ 'name' : "action",
 266+ 'value' : "upload"
 267+ })
 268+ )
262269 }
263270
264271 // Add JSON response format
265272 if ( $form.find( "[name='format']" ).length == 0 ){
266 - $form.append( '<input type="hidden" name="format" value="jsonfm">' );
 273+ $form.append(
 274+ $j( '<input />' )
 275+ .attr({
 276+ 'type' : "hidden",
 277+ 'name' : "format",
 278+ 'value' : "jsonfm"
 279+ })
 280+ )
267281 }
268282
269283 // Map a new hidden form
@@ -910,7 +924,7 @@
911925 beforeclose: function( event, ui ) {
912926 // If the upload is not complete, ask the user if they want to cancel
913927 if ( event.button == 0 && _this.action_done === false ) {
914 - _this.onCancel();
 928+ _this.onCancel( this );
915929 return false;
916930 } else {
917931 // Complete already, allow close
@@ -955,13 +969,13 @@
956970 /**
957971 * UI cancel button handler.
958972 * Show a dialog box asking the user whether they want to cancel an upload.
959 - * FIXME: doesn't work at all.
 973+ * @param Element dialogElement Dialog element to be canceled
960974 */
961 - onCancel: function( dlElm ) {
 975+ onCancel: function( dialogElement ) {
962976 //confirm:
963977 if ( confirm( gM( 'mwe-cancel-confim' ) ) ) {
964978 // NOTE: (cancel the encode / upload)
965 - $j( dlElm ).dialog( 'close' );
 979+ $j( dialogElement ).dialog( 'close' );
966980 }
967981 }
968982 };
Index: branches/js2-work/phase3/js/mwEmbed/mwEmbed.js
@@ -91,14 +91,7 @@
9292 mw.valid_skins = [ 'mvpcf', 'kskin' ];
9393
9494 // The version of mwEmbed
95 - mw.version = '1.1';
96 -
97 - /**
98 - * Some global containers flags
99 - */
100 - mw.skin_list = new Array();
101 - mw.init_done = false;
102 - mw.cb_count = 0;
 95+ mw.version = '1.1';
10396
10497 /**
10598 * Configuration System:
@@ -109,7 +102,7 @@
110103 // Local scope configuration var:
111104 var mwConfig = { };
112105
113 - // Stores global callbacks
 106+ // Stores global callbacks for script-loader loading
114107 var mwLoadDoneCB = { };
115108
116109 //Local scope mwUserConfig var. Stores user configuration
Index: branches/js2-work/phase3/js/mwEmbed/remotes/mediaWiki.js
@@ -7,7 +7,7 @@
88 var mwRemoteVersion = 'r90';
99 var mwUseScriptLoader = true;
1010
11 -//Log the mwRemote version ( will determine what version of js we get )
 11+// Log the mwRemote version ( will determine what version of js we get )
1212 if( window.console ){
1313 window.console.log( 'mwEmbed:remote:' + mwRemoteVersion );
1414 }
@@ -301,8 +301,8 @@
302302 */
303303 function mwGetReqArgs() {
304304 var rurl = '';
305 - //if ( mwReqParam['debug'] )
306 - // rurl += 'debug=true&';
 305+ if ( mwReqParam['debug'] )
 306+ rurl += 'debug=true&';
307307
308308 if ( mwReqParam['uselang'] )
309309 rurl += 'uselang=' + mwReqParam['uselang'] + '&';
Index: branches/js2-work/phase3/js/uploadPage.js
@@ -20,7 +20,7 @@
2121 'api_url': wgServer + wgScriptPath + '/api.php',
2222 'form_rewrite': true,
2323 // MediaWiki API supports chunk uploads:
24 - 'enable_chunks' : true,
 24+ 'enable_chunks' : false,
2525 'form_selector': mwUploadFormSelector,
2626 'new_source_cb': function( orgFilename, oggName ) {
2727 $j( '#wpDestFile' ).val( oggName );

Status & tagging log