r48035 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48034‎ | r48035 | r48036 >
Date:20:51, 4 March 2009
Author:dale
Status:deferred
Tags:
Comment:
* more firefogg refactor to use chunk upload api
* supports auto detect for upload api (uses html form otherwise)
Modified paths:
  • /trunk/extensions/MetavidWiki/includes/MV_GlobalFunctions.php (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/add_media_wizard.js (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_custom.css (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/mvFirefogg.js (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/mvUploader.js (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/remoteSearchDriver.js (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/searchLibs/mediaWikiSearch.js (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/libClipEdit/mvClipEdit.js (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/libSequencer/mvSequencer.js (modified) (history)
  • /trunk/extensions/MetavidWiki/skins/mv_embed/mv_embed.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MetavidWiki/includes/MV_GlobalFunctions.php
@@ -119,7 +119,7 @@
120120 $wgJSAutoloadClasses['j.fn.hoverIntent'] = $mvjsp . 'jquery/plugins/jquery.hoverIntent.js';
121121
122122 //libAddMedia:
123 - $wgJSAutoloadClasses['upFirefogg'] = $mvjsp . 'libAddMedia/firefogg.js';
 123+ $wgJSAutoloadClasses['mvFirefogg'] = $mvjsp . 'libAddMedia/mvFirefogg.js';
124124 $wgJSAutoloadClasses['mvUploader'] = $mvjsp . 'libAddMedia/mvUploader.js';
125125 $wgJSAutoloadClasses['remoteSearchDriver'] = $mvjsp . 'libAddMedia/remoteSearchDriver.js';
126126 $wgJSAutoloadClasses['seqRemoteSearchDriver'] = $mvjsp . 'libAddMedia/seqRemoteSearchDriver.js';
Index: trunk/extensions/MetavidWiki/skins/add_media_wizard.js
@@ -44,9 +44,10 @@
4545 //load jQuery and what not (we need to refactor the loading system for mv_embed)
4646 mvJsLoader.loadBaseLibs(function(){
4747 mvJsLoader.doLoad( {
 48+ 'mvFirefogg' : 'libAddMedia/mvFirefogg.js',
4849 'mvUploader' : 'libAddMedia/mvUploader.js'
4950 },function(){
50 - mvUp = new mvUploader();
 51+ mvUp = new mvUploader( { 'api_url' : wg_local_wiki_api_url } );
5152 });
5253 });
5354 });
Index: trunk/extensions/MetavidWiki/skins/mv_custom.css
@@ -540,7 +540,7 @@
541541 font-size:115%;".
542542 width:40%;
543543 height:50%;
544 - margin: -20% 10% -20% 10%;
 544+ /*margin: -20% 10% -20% 10%;*/
545545 padding: 10px;
546546 z-index:100;
547547 }
Index: trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/searchLibs/mediaWikiSearch.js
@@ -24,8 +24,7 @@
2525
2626 //build the image request object:
2727 var reqObj = {
28 - 'action':'query',
29 - 'format':'json',
 28+ 'action':'query',
3029 'generator':'search',
3130 'gsrsearch': encodeURIComponent( $j('#rsd_q').val() ),
3231 'gsrnamespace':6, //(only search the "file" namespace (audio, video, images)
Index: trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/mvFirefogg.js
@@ -4,7 +4,8 @@
55
66 var default_firefogg_options = {
77 'upload_done_action':'redirect',
8 - 'enabled':false
 8+ 'enabled':false,
 9+ 'api_url':false
910 }
1011 var mvFirefogg = function(initObj){
1112 return this.init( initObj );
@@ -18,10 +19,11 @@
1920 'maxSize': 400,
2021 'videoBitrate': 400
2122 },
 23+ formData:{}, //the form to be submited
 24+
2225 init : function( iObj ){
2326 if(!iObj)
2427 iObj = {};
25 - js_log("wtf");
2628 //inherit iObj properties:
2729 for(var i in default_firefogg_options){
2830 if(iObj[i]){
@@ -45,7 +47,7 @@
4648 $j('#wgfogg_installed,#wgEnableFirefogg').show();
4749
4850 if( $j('#wgEnableFirefogg').length > 0 ){
49 - this.fogg = new Firefogg();
 51+ _this.fogg = new Firefogg();
5052 //do the version check:
5153 if( this.fogg.version.replace(/[^0-9]/gi, '') < this.min_firefogg_version.replace(/[^0-9]/gi, '' ) ){
5254 //show wrong version error:
@@ -100,7 +102,7 @@
101103 },
102104 select_fogg:function(){
103105 var _this = this;
104 - if(_this.fogg.selectVideo()) {
 106+ if( _this.fogg.selectVideo() ) {
105107 //update destination filename:
106108 if( _this.fogg.sourceFilename ){
107109 var sf = _this.fogg.sourceFilename;
@@ -127,13 +129,14 @@
128130 }
129131
130132 //setup the form handling
131 - var editForm = $j('#mw-upload-form').get(0);
 133+ _this.editForm = $j('#mw-upload-form').get(0);
132134
133135 //set up the org_onsubmit if not set:
134136 if( typeof( _this.org_onsubmit ) == 'undefined' )
135 - _this.org_onsubmit = editForm.onsubmit;
 137+ _this.org_onsubmit = _this.editForm.onsubmit;
136138
137 - editForm.onsubmit = function() {
 139+ _this.editForm.onsubmit = function() {
 140+
138141 //run the original onsubmit (if not run yet set flag to avoid excessive chaining )
139142 if( typeof( _this.org_onsubmit ) == 'function' ){
140143 if( ! _this.org_onsubmit() ){
@@ -141,125 +144,187 @@
142145 return false;
143146 }
144147 }
145 - //get the input
146 - //var formData = _this.getEditFormData( editForm );
147 - var tmpAryData = $j( editForm ).serializeArray();
 148+ //get the input form data in flat json:
 149+ var tmpAryData = $j( _this.editForm ).serializeArray();
148150 for(var i=0; i < tmpAryData.length; i++){
149151 if( tmpAryData[i]['name'] )
150 - formData[ mpAryData[i]['name'] ] = mpAryData[i]['value'];
151 - }
152 -
 152+ _this.formData[ tmpAryData[i]['name'] ] = tmpAryData[i]['value'];
 153+ }
 154+ //hard code a value
 155+ _this.formData['wpSourceType']='file';
 156+
153157 //display the loader:
154158 $j('#dlbox-centered,#dlbox-overlay').show();
155159
156160 //for some unknown reason we have to drop down the #p-search z-index:
157161 $j('#p-search').css('z-index', 1);
158162
159 - //check the upload mode:
160 - if( _this.upload_mode == 'autodetect'){
161 -
162 - }else{
163 -
164 - }
165 - var options = JSON.stringify( _this.encoder_settings );
166 - _this.fogg.encode(options);
167 -
168 - var encodingStatus = function() {
169 - var status = _this.fogg.status();
 163+ //select upload mode:
 164+ _this.doUploadSwitch();
 165+ //don't submit the form (firefogg will handle that)
 166+ return false;
 167+ }
 168+ }
 169+ },
 170+ doUploadSwitch:function(){
 171+ var _this = this;
 172+ //check the upload mode:
 173+ if( _this.upload_mode == 'autodetect' ){
 174+ if( ! _this.api_url )
 175+ return js_error( 'Error: can\'t autodetect mode without api url' );
 176+ do_api_req( {
 177+ 'data':{ 'action':'paraminfo','modules':'upload' },
 178+ 'url':_this.api_url
 179+ }, function(data){
 180+ if( typeof data.paraminfo == 'undefined' || typeof data.paraminfo.modules == 'undefined' )
 181+ return js_error( 'Error: bad api results' );
 182+ if( typeof data.paraminfo.modules[0].classname == 'undefined'){
 183+ js_log( 'Autodetect Upload Mode: \'post\' ');
 184+ _this.upload_mode = 'post';
 185+ }else{
 186+ for( var i in data.paraminfo.modules[0].parameters ){
 187+ var pname = data.paraminfo.modules[0].parameters[i].name;
 188+ if( pname == 'chunks' ){
 189+ js_log( 'Autodetect Upload Mode: chunks ' );
 190+ _this.upload_mode = 'chunks';
 191+ break;
 192+ }
 193+ }
 194+ //somewhat verbose
 195+ if( _this.upload_mode != 'chunks'){
 196+ return js_error('Upload API without chunks param is not supported');
 197+ }
 198+ }
 199+ _this.doUploadSwitch();
 200+ });
 201+ }else if( _this.upload_mode == 'post') {
 202+ _this.doEncUpload();
 203+ }else if( _this.upload_mode == 'chunks'){
 204+ _this.doChunkUpload();
 205+ }else{
 206+ js_error( 'Error: unrecongized upload mode: ' + _this.upload_mode );
 207+ }
 208+ },
 209+ //doChunkUpload does both uploading and encoding at the same time and uploads one meg chunks as they are ready
 210+ doChunkUpload : function(){
 211+ var _this = this;
 212+ _this.fogg.upload( JSON.stringify( _this.encoder_settings ), _this.editForm.action , JSON.stringify( _this.formData ) );
 213+ //update upload status:
 214+ _this.doUploadStatus();
 215+ },
 216+ //doEncUpload first encodes then uploads
 217+ doEncUpload : function(){
 218+ var _this = this;
 219+ _this.fogg.encode( JSON.stringify( _this.encoder_settings ) );
 220+
 221+ //setup a local function for timed callback:
 222+ var encodingStatus = function() {
 223+ var status = _this.fogg.status();
170224
171 - //update progress bar
172 - _this.fogg_update_progress( _this.fogg.progress() );
 225+ //update progress bar
 226+ _this.fogg_update_progress( _this.fogg.progress() );
173227
174 - //loop to get new status if still encoding
175 - if( _this.fogg.state == 'encoding' ) {
176 - setTimeout(encodingStatus, 500);
177 - }
178 - //encoding done, state can also be 'encoding failed'
179 - else if ( _this.fogg.state == 'encoding done' ) {
180 - //hide the fogg-status-transcode
181 - $j('#fogg-status-transcode').hide();
 228+ //loop to get new status if still encoding
 229+ if( _this.fogg.state == 'encoding' ) {
 230+ setTimeout(encodingStatus, 500);
 231+ }else if ( _this.fogg.state == 'encoding done' ) { //encoding done, state can also be 'encoding failed'
 232+ //now call the upload function
 233+
 234+ //hide the fogg-status-transcode
 235+ $j('#fogg-status-transcode').hide();
182236
183 - //show the fogg-status-upload
184 - $j('#fogg-status-upload').show();
185 -
186 - //hard code some values
187 - formData['wpSourceType']='file';
188 -
189 - var data = JSON.stringify( formData );
190 - //send to the post url:
191 - _this.fogg.post( editForm.action, 'wpUploadFile', data);
192 - var uploadStatus = function() {
193 - var status = _this.fogg.status();
194 - //js_log(' up stats: ' + status + ' p:' + _this.fogg.progress() + ' state: '+ _this.fogg.state + ' result page:' + result_page);
195 -
196 - //update progress bar
197 - _this.fogg_update_progress( _this.fogg.progress() );
198 -
199 - //loop to get new status if still uploading
200 - if(_this.fogg.state == 'uploading') {
201 - setTimeout(uploadStatus, 500);
202 - }
203 - //upload sucesfull, state can also be 'upload failed'
204 - else if( _this.fogg.state == 'upload done' ) {
205 - //js_log( 'firefogg:upload done: ');
206 - //@@todo handle errors same problem as #695 in remoteSearchDriver.js
207 - //we need to add image uploading to the api rather than parse the HTML output of the pages
208 - var result_page = _this.fogg.responseText;
209 - var sstring = 'var wgTitle = "' + formData['wpDestFile'].replace('_',' ');
210 - if( result_page && result_page.toLowerCase().indexOf( sstring.toLowerCase() ) != -1){
211 - js_log('upload done got redirect found: ' +sstring + ' r:' + _this.upload_done_action);
212 - if( _this.upload_done_action == 'redirect'){
213 - window.location = wgArticlePath.replace(/\$1/, 'File:' + formData['wpDestFile'] );
214 - }else{
215 - //check if the add_done_action is a callback:
216 - if( typeof _this.upload_done_action == 'function' )
217 - _this.upload_done_action();
218 - }
219 - }else{
220 - js_log('upload page error: did not find: ' +sstring);
221 - var error_txt = 'Unkown error';
222 - if(!result_page){
223 - //@@todo fix this:
224 - //the mediaWiki upload system does not have an API so we can\'t accuratly read errors
225 - error_txt = 'Your upload should be accessible <a href="' +
226 - wgArticlePath.replace(/\$1/, 'File:' + formData['wpDestFile'] ) + '">'+
227 - 'here</a> \n';
228 - }else{
229 - sp = result_page.indexOf('<span class="error">');
230 - if(sp!=-1){
231 - se = result_page.indexOf('</span>', sp);
232 - error_txt = result_page.substr(sp, (sp-se));
233 - }else{
234 - //look for warning:
235 - sp = result_page.indexOf('<ul class="warning">')
236 - if(sp!=-1){
237 - se = result_page.indexOf('</ul>', sp);
238 - error_txt = result_page.substr(sp, (sp-se));
239 - }
240 - }
241 - }
242 - e = document.getElementById('dlbox-centered');
243 - if(e)
244 - e.innerHTML = '<h3>Upload Completed:</h3>' + error_txt;
245 - }
246 - }
247 - //upload error:
248 - else{
249 - alert('firefogg upload error: ' + _this.fogg.state);
250 - }
251 - }
252 - uploadStatus();
253 - }else if(_this.fogg.state == 'encoding fail'){
254 - //@@todo error handling:
255 - alert('encoding failed');
256 - }
257 - }
258 - encodingStatus();
259 - //don't submit the form (let firefogg handle it)
260 - return false;
261 - }; //addHandler mapping
262 - }else{
263 - //remove upload binding if no file was selected
264 - }
265 - }
 237+ //show the fogg-status-upload
 238+ $j('#fogg-status-upload').show();
 239+
 240+ //send to the post url:
 241+ _this.fogg.post( _this.editForm.action, 'wpUploadFile', JSON.stringify( _this.formData ) );
 242+ //update upload status:
 243+ _this.doUploadStatus();
 244+ }else if(_this.fogg.state == 'encoding fail'){
 245+ //@@todo error handling:
 246+ alert('encoding failed');
 247+ }
 248+ }
 249+ encodingStatus();
 250+ },
 251+ doUploadStatus:function() {
 252+ var _this = this;
 253+ //setup a local function for timed callback:
 254+ var uploadStatus = function(){
 255+ var status = _this.fogg.status();
 256+ js_log(' up stats: ' + status + ' p:' + _this.fogg.progress() + ' state: '+ _this.fogg.state + ' result page:' + _this.fogg.responseText);
 257+
 258+ //update progress bar
 259+ _this.fogg_update_progress( _this.fogg.progress() );
 260+
 261+ //loop to get new status if still uploading (could also be encoding if we are in chunk upload mode)
 262+ if( _this.fogg.state == 'encoding' || _this.fogg.state == 'uploading') {
 263+ setTimeout(uploadStatus, 500);
 264+ }
 265+ //check upload state
 266+ else if( _this.fogg.state == 'upload done' || _this.fogg.state == 'done' ) {
 267+ js_log( 'firefogg:upload done: ');
 268+ //@@todo handle errors same problem as #695 in remoteSearchDriver.js
 269+
 270+ //if in "post" upload mode read the html response:
 271+ if( _this.upload_mode == 'post' ) {
 272+ //var foo = _this;
 273+ //var cat = _this.fogg.responseText;
 274+ //var cat_json = eval('var result =' + _this.fogg.responseText );
 275+ //debugger;
 276+ js_log('done upload response is:' + _this.fogg.responseText );
 277+ _this.procPageResponse( _this.fogg.responseText );
 278+ }else if( _this.upload_mode == 'chunks'){
 279+ //should have an json result:\
 280+ var foo = _this;
 281+ var cat = _this.fogg.responseText;
 282+ var cat_json = eval('var result =' + _this.fogg.responseText );
 283+ debugger;
 284+ }
 285+ }
 286+ //upload error:
 287+ else{
 288+ alert('firefogg upload error: ' + _this.fogg.state );
 289+ }
 290+ }
 291+ uploadStatus();
 292+ },
 293+ procPageResponse:function( result_page ){
 294+ js_log('f:procPageResponse');
 295+ var sstring = 'var wgTitle = "' + this.formData['wpDestFile'].replace('_',' ');
 296+ if( result_page && result_page.toLowerCase().indexOf( sstring.toLowerCase() ) != -1){
 297+ js_log( 'upload done got redirect found: ' + sstring + ' r:' + _this.upload_done_action );
 298+ if( _this.upload_done_action == 'redirect' ){
 299+ window.location = wgArticlePath.replace( /\$1/, 'File:' + formData['wpDestFile'] );
 300+ }else{
 301+ //check if the add_done_action is a callback:
 302+ if( typeof _this.upload_done_action == 'function' )
 303+ _this.upload_done_action();
 304+ }
 305+ }else{
 306+ js_log( 'upload page error: did not find: ' +sstring + ' in ' + "\n" + result_page );
 307+ var error_txt = 'Unkown error';
 308+ if( !result_page ){
 309+ //@@todo fix this:
 310+ //the mediaWiki upload system does not have an API so we can\'t acuratly read errors
 311+ error_txt = 'Your upload should be accessible <a href="' +
 312+ wgArticlePath.replace(/\$1/, 'File:' + this.formData['wpDestFile'] ) + '">'+
 313+ 'here</a> \n';
 314+ }else{
 315+ sp = result_page.indexOf('<span class="error">');
 316+ if(sp!=-1){
 317+ se = result_page.indexOf('</span>', sp);
 318+ error_txt = result_page.substr(sp, (sp-se));
 319+ }else{
 320+ //look for warning:
 321+ sp = result_page.indexOf('<ul class="warning">')
 322+ if(sp!=-1){
 323+ se = result_page.indexOf('</ul>', sp);
 324+ error_txt = result_page.substr(sp, (sp-se));
 325+ }
 326+ }
 327+ }
 328+ $j( '#dlbox-centered' ).html( '<h3>Upload Completed:</h3>' + error_txt);
 329+ }
 330+ }
266331 }
\ No newline at end of file
Index: trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/remoteSearchDriver.js
@@ -420,8 +420,7 @@
421421 var _this = this;
422422 reqObj={
423423 'action':'query',
424 - 'titles': _this.cFileNS + ':' + rTitle,
425 - 'format':'json'
 424+ 'titles': _this.cFileNS + ':' + rTitle
426425 };
427426 do_api_req( {
428427 'data':reqObj,
Index: trunk/extensions/MetavidWiki/skins/mv_embed/libAddMedia/mvUploader.js
@@ -16,7 +16,8 @@
1717
1818 var default_upload_options = {
1919 'target_div':'',
20 - 'upload_done_action':'redirect'
 20+ 'upload_done_action':'redirect',
 21+ 'api_url':false
2122 }
2223
2324 var mvUploader = function(initObj){
@@ -89,6 +90,8 @@
9091 _this.upload_done_action( rTitle );
9192 }
9293 };
 94+ if( _this.api_url )
 95+ intFirefoggObj['api_url'] = _this.api_url;
9396 js_log('new mvFirefogg');
9497 //if firefog is not taking over the submit we can here:
9598 _this.fogg = new mvFirefogg( intFirefoggObj );
Index: trunk/extensions/MetavidWiki/skins/mv_embed/libSequencer/mvSequencer.js
@@ -452,7 +452,6 @@
453453 if(typeof this.sequenceEditToken == 'undefined'){
454454 var reqObj = {
455455 'action':'query',
456 - 'format':'json',
457456 'prop':'info',
458457 'intoken':'edit',
459458 'titles': this_seq.plObj.mTitle
Index: trunk/extensions/MetavidWiki/skins/mv_embed/libClipEdit/mvClipEdit.js
@@ -184,7 +184,6 @@
185185 if(_this.media_type == 'template' && !_this.rObj.tVars){
186186 mv_set_loading('#sub_cliplib_ic');
187187 var reqObj ={ 'action':'query',
188 - 'format':'json',
189188 'prop':'revisions',
190189 'titles': _this.rObj.uri,
191190 'rvprop':'content'
Index: trunk/extensions/MetavidWiki/skins/mv_embed/mv_embed.js
@@ -1067,7 +1067,7 @@
10681068 }
10691069
10701070 //does a remote or local api request based on request url
1071 -//@param : url, data, cbParam, callback
 1071+//@param options: url, data, cbParam, callback
10721072 function do_api_req( options, callback ){
10731073 if(typeof options.data != 'object'){
10741074 js_log('Error: request paramaters must be an object');
@@ -1083,9 +1083,14 @@
10841084 options.url = options.url.replace('index.php', 'api.php');
10851085 }
10861086 if(typeof options.data == 'undefined')
1087 - options.data = {};
1088 - //build request string: (force the format to json):
1089 - if( parseUri(document.URL).host == parseUri( options['api_url'] ).host ){
 1087+ options.data = {};
 1088+
 1089+ //set the format to json (if not already set)
 1090+ if(typeof options.data['format'] == 'undefined')
 1091+ options.data['format'] = 'json';
 1092+
 1093+ //build request string:
 1094+ if( parseUri( document.URL ).host == parseUri( options['api_url'] ).host ){
10901095 //local request do api request directly
10911096 $j.ajax({
10921097 type: "POST",
@@ -1097,8 +1102,10 @@
10981103 }
10991104 });
11001105 }else{
 1106+ //set the callback param if not already set:
11011107 if( typeof options.jsonCB == 'undefined')
11021108 options.jsonCB = 'callback';
 1109+
11031110 var req_url = options.url;
11041111 var paramAnd = (req_url.indexOf('?')==-1)?'?':'&';
11051112 //put all the values into the GET req:
@@ -1306,5 +1313,6 @@
13071314
13081315 function js_error(string){
13091316 alert(string);
 1317+ return false;
13101318 }
13111319

Status & tagging log