r61042 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61041‎ | r61042 | r61043 >
Date:05:02, 14 January 2010
Author:dale
Status:deferred
Tags:
Comment:
* some code refactoring
* possible fix for javascript side of upload commons hack for non-firefogg usage
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/modules/AddMedia/mw.RemoteSearchDriver.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/Sequencer/mw.FirefoggRender.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/Sequencer/mw.PlayList.js (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/Sequencer/mw.Sequencer.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/tests/Firefogg_GUI.html (modified) (history)
  • /branches/js2-work/phase3/js/uploadPage.js (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js/mwEmbed/tests/Firefogg_GUI.html
@@ -83,10 +83,12 @@
8484 </a><br>
8585 Make Ogg Video</h1>
8686 <br>
 87+<div style="margin-right:auto;margin-left:auto;width:500px;">
 88+Note: Your video file will be locally encoded and not upload to any server
 89+</div>
8790 <br>
8891
89 - <div style="margin-right:auto;margin-left:auto;width:500px;" id="firefogg_app">
90 - Loading firefogg...
 92+ <div style="margin-right:auto;margin-left:auto;width:500px;" id="firefogg_app">
9193 </div>
9294
9395 <div style="height:295px"></div>
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.Firefogg.js
@@ -362,7 +362,7 @@
363363 */
364364 setupForm: function() {
365365 mw.log( 'firefogg::setupForm::' );
366 - var _this = this;
 366+ var _this = this;
367367 // Set up the parent if we are in upload mode
368368 if ( this.form_type == 'upload' ) {
369369 this.pe_setupForm();
@@ -547,7 +547,7 @@
548548 * Returns false if it can't be found.
549549 * Overrides mw.BaseUploadInterface.getForm().
550550 */
551 - getForm: function() {
 551+ getForm: function() {
552552 if ( this.form_selector ) {
553553 return this.pe_getForm();
554554 } else {
@@ -826,6 +826,22 @@
827827 _this.pe_doUpload();
828828 return;
829829 }
 830+ // Get the input form data into an array
 831+ mw.log( 'get this.formData ::' );
 832+ var data = $j( this.form ).serializeArray();
 833+ this.formData = {};
 834+ for ( var i = 0; i < data.length; i++ ) {
 835+ if ( data[i]['name'] ){
 836+ // Special case of upload.js commons hack:
 837+ if( data[i]['name'] == 'wpUploadDescription' ){
 838+ this.formData[ 'comment' ] = data[i]['value'];
 839+ }else{
 840+ this.formData[ data[i]['name'] ] = data[i]['value'];
 841+ }
 842+ }
 843+ }
 844+
 845+
830846 // We can do a chunk upload
831847 if( _this.upload_mode == 'post' && _this.enable_chunks ){
832848 _this.doChunkUpload();
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.RemoteSearchDriver.js
@@ -956,13 +956,13 @@
957957 var wTitle = resultData['filename'];
958958 // Add a loading div
959959 _this.addResourceEditLoader();
960 -
961960 //Add the uploaded result
962961 provider.sObj.addByTitle( wTitle, function( resource ) {
963962 // Redraw ( with added result if new )
964963 _this.showResults();
965964 // Pull up resource editor:
966 - _this.showResourceEditor( resource, $j( '#res_upload__' + resource.id ).get( 0 ) );
 965+ debugger;
 966+ _this.showResourceEditor( resource, $j( '#res_this_wiki_' + resource.id ).get( 0 ) );
967967 } );
968968 // Return false to close progress window:
969969 return false;
@@ -1607,7 +1607,7 @@
16081608 $j( _this.target_container ).dialog( 'option', 'title', dialogTitle );
16091609 mw.log( 'did append to: ' + _this.target_container );
16101610
1611 - // Left side holds the image right size the controls /
 1611+ // Left side holds the image right size the controls
16121612 $j( rsdElement )
16131613 .clone()
16141614 .attr( 'id', 'rsd_edit_img' )
@@ -2504,7 +2504,7 @@
25052505 setTimeout(
25062506 function() {
25072507 $j( _this.target_container ).dialog( 'close' );
2508 - $j( '#rsd_modal_target').remove();
 2508+ $j( _this.target_container ).remove();
25092509 }, 25
25102510 );
25112511 },
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/jquery.simpleUploadForm.js
@@ -46,15 +46,15 @@
4747 }
4848
4949 // Get an edit Token for "uploading"
50 - mw.getToken( 'File:MyRandomFileTokenCheck', options.api_target, function( eToken ) {
 50+ mw.getToken( 'File:MyRandomFileTokenCheck.jpg', options.api_target, function( eToken ) {
5151 if ( !eToken || eToken == '+\\' ) {
52 - $( this.selector ).html( gM( 'mwe-error_not_loggedin' ) );
 52+ $( _this.selector ).html( gM( 'mwe-error_not_loggedin' ) );
5353 return false;
5454 }
5555
5656 // Build an upload form:
5757 var o = '<div>' +
58 - '<form id="suf-upload" enctype="multipart/form-data" action="' + options.api_target + '" method="post">' +
 58+ '<form id="suf_upload" name="suf_upload" enctype="multipart/form-data" action="' + options.api_target + '" method="post">' +
5959 // hidden input:
6060 '<input type="hidden" name="action" value="upload">' +
6161 '<input type="hidden" name="format" value="jsonfm">' +
@@ -149,7 +149,7 @@
150150 // MediaWiki API supports chunk uploads:
151151 'enable_chunks' : true,
152152
153 - 'edit_form_selector' : '#suf-upload',
 153+ 'form_selector' : '#suf_upload',
154154 'new_source_cb' : function( orgFilename, oggName ) {
155155 $j( "#wpDestFile" ).val( oggName ).doDestCheck( {
156156 warn_target: "#wpDestFile-warning"
Index: branches/js2-work/phase3/js/mwEmbed/modules/AddMedia/mw.BaseUploadInterface.js
@@ -74,25 +74,28 @@
7575 setupForm: function() {
7676 mw.log( "Base::setupForm::" );
7777 var _this = this;
 78+
7879 // Set up the local pointer to the edit form:
79 - this.form = this.getForm();
 80+ this.form = this.getForm();
 81+
8082 if ( !this.form ) {
8183 mw.log( "Upload form not found!" );
8284 return;
83 - }
 85+ }
8486
85 - // If we're in API mode, re-map the upload form to API.
86 - if ( this.upload_mode == 'api' ) {
87 - this.remapFormToApi();
88 - }
89 -
9087 // Set up the orig_onsubmit if not set:
9188 if ( typeof( this.orig_onsubmit ) == 'undefined' && this.form.onsubmit ) {
9289 this.orig_onsubmit = this.form.onsubmit;
9390 }
9491
9592 // Set up the submit action:
96 - $j( this.form ).submit( function() {
 93+ $j( this.form ).submit( function() {
 94+ mw.log( "FORM SUBMIT::" );
 95+ var data = $j( this ).serializeArray();
 96+ for ( var i = 0; i < data.length; i++ ) {
 97+ mw.log( $j( data[i] ).attr('name') + ' : ' + $j(data[i]).val() );
 98+ }
 99+
97100 return _this.onSubmit();
98101 } );
99102 },
@@ -110,30 +113,18 @@
111114 return false;
112115 }
113116 }
 117+ // Remap the upload form to the "api" form:
 118+ this.remapFormToApi();
 119+
114120 // Check for post action override
115121 if ( this.form_post_override ) {
116122 mw.log( 'form_post_override is true, do ordinary form submit' );
117123 return true;
118 - }
119 -
120 - // Get the input form data into an array
121 - mw.log( 'update formData::' );
122 - var data = $j( this.form ).serializeArray();
123 - this.formData = {};
124 - for ( var i = 0; i < data.length; i++ ) {
125 - if ( data[i]['name'] ){
126 - // Special case of upload.js commons hack:
127 - if( data[i]['name'] == 'wpUploadDescription' ){
128 - this.formData[ 'comment' ] = data[i]['value'];
129 - }else{
130 - this.formData[ data[i]['name'] ] = data[i]['value'];
131 - }
132 - }
133 - }
134 -
 124+ }
 125+
 126+
135127 // Put into a try catch so we are sure to return false:
136 - try {
137 -
 128+ try {
138129 // Display a progress dialog
139130 _this.displayProgressOverlay();
140131
@@ -165,6 +156,7 @@
166157 detectUploadMode: function( callback ) {
167158 var _this = this;
168159 mw.log( 'detectUploadMode::' + _this.upload_mode );
 160+ //debugger;
169161 // Check the upload mode
170162 if ( _this.upload_mode == 'detect_in_progress' ) {
171163 // Don't send another request, wait for the pending one.
@@ -182,6 +174,7 @@
183175
184176 // FIXME: move this to configuration and avoid this API request
185177 mw.getJSON( _this.api_url, { 'action' : 'paraminfo', 'modules' : 'upload' }, function( data ) {
 178+ debugger;
186179 if ( typeof data.paraminfo == 'undefined'
187180 || typeof data.paraminfo.modules == 'undefined' )
188181 {
@@ -219,7 +212,8 @@
220213 /**
221214 * Do an upload, with the mode given by this.upload_mode
222215 */
223 - doUpload: function() {
 216+ doUpload: function() {
 217+ // Note "api" should be called "http_copy_upload" and /post/ should be "form_upload"
224218 if ( this.upload_mode == 'api' ) {
225219 this.doApiCopyUpload();
226220 } else if ( this.upload_mode == 'post' ) {
@@ -236,32 +230,42 @@
237231 * This is rather ugly, but solutions are constrained by the fact that
238232 * file inputs can't be moved around or recreated after the user has
239233 * selected a file in them, which they may well do before DOM ready.
 234+ *
 235+ * It is also constrained by upload form hacks on commons.
240236 */
241237 remapFormToApi: function() {
242238 var _this = this;
243 - if ( !this.api_url )
 239+ //
 240+ mw.log("remapFormToApi:: " + this.api_url + ' form: ' + this.form);
 241+
 242+ if ( !this.api_url ){
 243+ mw.log( 'Error: no api url target' );
244244 return false;
 245+ }
 246+ var $form = $j( this.form_selector );
245247
246 - var form = $j( this.form );
247 -
248248 // Set the form action
249 - form.attr('action', _this.api_url);
 249+ $form.attr('action', _this.api_url);
250250
251251 // Add API action
252 - if ( form.find( "[name='action']" ).length == 0 )
253 - form.append( '<input type="hidden" name="action" value="upload">' );
 252+ if ( $form.find( "[name='action']" ).length == 0 ){
 253+ $form.append( '<input type="hidden" name="action" value="upload">' );
 254+ }
254255
255 - // Add JSON format
256 - if ( form.find( "[name='format']" ).length == 0 )
257 - form.append( '<input type="hidden" name="format" value="jsonfm">' );
 256+ // Add JSON response format
 257+ if ( $form.find( "[name='format']" ).length == 0 ){
 258+ $form.append( '<input type="hidden" name="format" value="jsonfm">' );
 259+ }
258260
259261 // Map a new hidden form
260 - form.find( "[name='wpUploadFile']" ).attr( 'name', 'file' );
261 - form.find( "[name='wpDestFile']" ).attr( 'name', 'filename' );
262 - form.find( "[name='wpUploadDescription']" ).attr( 'name', 'comment' );
263 - form.find( "[name='wpEditToken']" ).attr( 'name', 'token' );
264 - form.find( "[name='wpIgnoreWarning']" ).attr( 'name', 'ignorewarnings' );
265 - form.find( "[name='wpWatchthis']" ).attr( 'name', 'watch' );
 262+ $form.find( "[name='wpUploadFile']" ).attr( 'name', 'file' );
 263+ $form.find( "[name='wpDestFile']" ).attr( 'name', 'filename' );
 264+ $form.find( "[name='wpUploadDescription']" ).attr( 'name', 'comment' );
 265+ $form.find( "[name='wpEditToken']" ).attr( 'name', 'token' );
 266+ $form.find( "[name='wpIgnoreWarning']" ).attr( 'name', 'ignorewarnings' );
 267+ $form.find( "[name='wpWatchthis']" ).attr( 'name', 'watch' );
 268+
 269+ //mw.log( 'comment: ' + $form.find( "[name='comment']" ).val() );
266270 },
267271
268272 /**
@@ -283,23 +287,26 @@
284288 */
285289 doPostUpload: function() {
286290 var _this = this;
287 - var form = $j( _this.form );
 291+ var $form = $j( _this.form );
288292 mw.log( 'mvBaseUploadInterface.doPostUpload' );
289 -
290293 // Issue a normal post request
291294 // Get the token from the page
292295 _this.editToken = $j( "#wpEditToken" ).val();
293296
294297 //@@TODO check for sendAsBinary to support Firefox/HTML5 progress on upload
295 -
296 -
 298+
 299+ //Update the progress dialog (no bar without XHR request)
 300+ $j( '#upProgressDialog' ).html(
 301+ mw.loading_spinner()
 302+ );
 303+
297304 // Add the iframe
298305 _this.iframeId = 'f_' + ( $j( 'iframe' ).length + 1 );
299306 $j( "body" ).append( '<iframe src="javascript:false;" id="' + _this.iframeId + '" ' +
300307 'name="' + _this.iframeId + '" style="display:none;" ></iframe>' );
301308
302309 // Set the form target to the iframe
303 - form.attr( 'target', _this.iframeId );
 310+ $form.attr( 'target', _this.iframeId );
304311
305312 // Set up the completion callback
306313 $j( '#' + _this.iframeId ).load( function() {
@@ -307,17 +314,18 @@
308315 });
309316
310317 // Set the action to the API URL:
311 - form.attr( 'action', _this.api_url );
 318+ $form.attr( 'action', _this.api_url );
312319
313 - mw.log( 'Do iframe form submit to: ' + form.attr( 'target' ) );
314 - mw.log( ' destName:' + form.find( "[name='filename']" ).val() );
 320+ mw.log( 'Do iframe form submit of: ' + $form.attr( 'target' ) + ' to: ' + $form.attr('action') );
 321+ mw.log( ' destName:' + $form.find( "[name='filename']" ).val() );
 322+ mw.log( ' content:' + $form.find( "[name='comment']" ).val() );
315323
316324 // Do post override
317325 _this.form_post_override = true;
 326+
318327 // Reset the done with action flag
319 - _this.action_done = false;
320 -
321 - form.submit();
 328+ _this.action_done = false;
 329+ $form.submit();
322330 },
323331
324332 /**
@@ -749,7 +757,7 @@
750758 */
751759 processApiResult: function( apiRes ) {
752760 var _this = this;
753 - mw.log( 'processApiResult::' );
 761+ mw.log( 'processApiResult::' );
754762 if ( !_this.isApiSuccess( apiRes ) ) {
755763 // Error detected, show it to the user
756764 _this.showApiError( apiRes );
@@ -838,6 +846,18 @@
839847 * Returns false if it can't be found.
840848 */
841849 getForm: function() {
 850+
 851+ /*debugger;
 852+ var cat = this.form_selector;
 853+ var forms = document.getElementsByTagName('form');
 854+ mw.log('got ' + forms.length + ' foms ');
 855+ for( var i in forms ){
 856+ var fish = forms[ i ];
 857+ mw.log( 'fish: ' + fish.id );
 858+ }
 859+ var cat = $j( this.form_selector ).get(0);
 860+ mw.log( 'getForm::' + cat.id );
 861+ */
842862 if ( this.form_selector && $j( this.form_selector ).length != 0 ) {
843863 return $j( this.form_selector ).get( 0 );
844864 } else {
@@ -886,6 +906,8 @@
887907 },
888908 buttons: _this.getCancelButton()
889909 } );
 910+ mw.log( 'upProgressDialog::dialog done' );
 911+
890912 $j( '#upProgressDialog' ).html(
891913 '<div id="up-pbar-container" style="width:90%;height:15px;" >' +
892914 '<div id="up-progressbar" style="height:15px;"></div>' +
@@ -905,13 +927,14 @@
906928 },
907929
908930 /**
909 - * Get a standard cancel button in the jQuery.ui dialog format
910 - */
 931+ * Get a standard cancel button in the jQuery.ui dialog format
 932+ */
911933 getCancelButton: function() {
912934 var _this = this;
913 - var cancelBtn = new Array();
 935+ mw.log( 'f: getCancelButton()' );
 936+ var cancelBtn = [];
914937 cancelBtn[ gM( 'mwe-cancel' ) ] = function() {
915 - return _this.onCancel( this )
 938+ $j( dlElm ).dialog( 'close' );
916939 };
917940 return cancelBtn;
918941 },
@@ -925,7 +948,7 @@
926949 //confirm:
927950 if ( confirm( gM( 'mwe-cancel-confim' ) ) ) {
928951 //@@todo (cancel the encode / upload)
929 - $j( this ).dialog( 'close' );
 952+ $j( dlElm ).dialog( 'close' );
930953 }
931954 }
932955 };
Index: branches/js2-work/phase3/js/mwEmbed/modules/Sequencer/mw.FirefoggRender.js
@@ -138,7 +138,10 @@
139139 _this.doNextFrame();
140140 });
141141 },
142 - // Do the next frame in the render target
 142+
 143+ /**
 144+ * Do the next frame in the render target
 145+ */
143146 doNextFrame: function(){
144147 var _this = this;
145148 // internal function to handle updates:
@@ -149,7 +152,7 @@
150153 //mw.log( 'addFrame:' + $j( _this.player_target ).attr( 'id' ) );
151154 _this.fogg.addFrame( $j( _this.player_target ).attr( 'id' ) );
152155 _this.render_time += _this.interval;
153 - if ( _this.render_time >= _this.player.getDuration() && _this.continue_rendering) {
 156+ if ( _this.render_time >= _this.player.getDuration() || ! _this.continue_rendering ) {
154157 _this.doFinalRender();
155158 } else {
156159 _this.doNextFrame();
@@ -160,7 +163,7 @@
161164 /**
162165 * Stop the current render proccess on the next frame
163166 */
164 - stopRender:function() {
 167+ stopRender: function() {
165168 this.continue_rendering = false;
166169 },
167170
Index: branches/js2-work/phase3/js/mwEmbed/modules/Sequencer/mw.Sequencer.js
@@ -836,10 +836,10 @@
837837 mw.load( [
838838 'mw.ClipEdit'
839839 ], function() {
840 - // Zero out the current editor:
 840+ // Zero out the current editor:
841841 _this.myClipEditor = { };
842842 // Setup the cliploader options
843 - _this.myClipEditor = new mvClipEdit( {
 843+ _this.myClipEditor = new mw.ClipEdit( {
844844 'resource' : resource,
845845 'target_control_display' : 'clipedit_ic',
846846 'target_clip_display' : resource.id,
Index: branches/js2-work/phase3/js/mwEmbed/modules/Sequencer/mw.PlayList.js
@@ -448,10 +448,12 @@
449449
450450 // Update the target player:
451451 this.$interface = $j( this ).parent( '.interface_wrap' );
 452+
 453+ // Empty out the old interface:
452454 this.ctrlBuilder.embedPlayer = this;
453455
454 - if ( this.controls == true ) {
455 - // prepend the title (ontop)
 456+ if ( this.controls == true && $j('#ptitle_' + this.id).length == 0 ) {
 457+ // prepend the title (ontop) if not there
456458 this.$interface.prepend(
457459 $j('<div>')
458460 .css({
Index: branches/js2-work/phase3/js/mwEmbed/mwEmbed.js
@@ -25,6 +25,11 @@
2626 window['mw'] = { }
2727 }
2828
 29+/*
 30+* Set the mwEmbedVersion ( not set by stopgap )
 31+*/
 32+var MW_EMBED_VERSION = '1.0';
 33+
2934 /**
3035 * The set of modules that you want enable.
3136 *
@@ -57,10 +62,8 @@
5863 */
5964 var mwDefaultConf = {
6065
61 -
6266 'enabledModules' : mwEnabledModuleList,
6367
64 -
6568 // Default skin name
6669 'skinName' : 'mvpcf',
6770
@@ -92,7 +95,7 @@
9396 // The mediaWiki path of mvEmbed
9497 'mediaWiki_mwEmbedPath' : 'js/mwEmbed/',
9598
96 - // Api actions that must be submited in a POST, and need an api proxy for cross domain calls
 99+ // Api actions that must be submitted in a POST, and need an api proxy for cross domain calls
97100 'apiPostActions': [ 'login', 'purge', 'rollback', 'delete', 'undelete',
98101 'protect', 'block', 'unblock', 'move', 'edit', 'upload', 'emailuser',
99102 'import', 'userrights' ],
@@ -2262,7 +2265,7 @@
22632266 * so avoid calling this function where possible and
22642267 * cache its result
22652268 *
2266 - * Note this only works when mwEmbed is on the same domain as the style sheets
 2269+ * Note this only works for style sheets on the same domain :(
22672270 *
22682271 * @param {String} styleRule Style rule name to check
22692272 * @return
@@ -2274,7 +2277,7 @@
22752278 // Set up the skin paths configuration
22762279 for( var i=0 ; i < document.styleSheets.length ; i++ ){
22772280 var rules = null;
2278 - try {
 2281+ try{
22792282 if ( document.styleSheets[i].cssRules )
22802283 rules = document.styleSheets[i].cssRules
22812284 else if (document.styleSheets[0].rules)
@@ -2285,8 +2288,8 @@
22862289 return true;
22872290 }
22882291 }
2289 - } catch ( e ){
2290 - mw.log( 'Error: cross domain style sheet:' + document.styleSheets[i].href);
 2292+ }catch ( e ){
 2293+ mw.log( 'Error: cant check rule on cross domain style sheet:' + document.styleSheets[i].href );
22912294 }
22922295 }
22932296 return false;
Index: branches/js2-work/phase3/js/mwEmbed/remotes/mediaWiki.js
@@ -4,7 +4,7 @@
55 */
66 var urlparts = getRemoteEmbedPath();
77 var mwEmbedHostPath = urlparts[0];
8 -var mwRemoteVersion = 'r74';
 8+var mwRemoteVersion = 'r75';
99 var mwUseScriptLoader = true;
1010
1111 // Setup up request Params:
@@ -36,7 +36,7 @@
3737 return ;
3838 ranRewrites = 'done';
3939 // Add media wizard
40 - if ( wgAction == 'edit' || wgAction == 'submit' ) {
 40+ if ( wgAction == 'edit' || wgAction == 'submit' ) {
4141 loadMwEmbed( [
4242 'mw.RemoteSearchDriver',
4343 '$j.fn.textSelection',
@@ -319,7 +319,7 @@
320320 callback = classSet;
321321
322322 // Inject mwEmbed if needed
323 - if ( typeof mw == 'undefined' ) {
 323+ if ( typeof MW_EMBED_VERSION == 'undefined' ) {
324324 if ( ( mwReqParam['uselang'] || mwReqParam[ 'useloader' ] ) && mwUseScriptLoader ) {
325325 var rurl = mwEmbedHostPath + '/mwEmbed/jsScriptLoader.php?class=mwEmbed';
326326
Index: branches/js2-work/phase3/js/uploadPage.js
@@ -21,7 +21,7 @@
2222 'form_rewrite': true,
2323 // MediaWiki API supports chunk uploads:
2424 'enable_chunks' : true,
25 - 'edit_form_selector': mwUploadFormSelector,
 25+ 'form_selector': mwUploadFormSelector,
2626 'new_source_cb': function( orgFilename, oggName ) {
2727 $j( '#wpDestFile' ).val( oggName );
2828 $j( '#wpDestFile' ).doDestCheck( {

Status & tagging log