r50613 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50612‎ | r50613 | r50614 >
Date:01:58, 15 May 2009
Author:dale
Status:deferred
Tags:
Comment:
new-upload updates
Modified paths:
  • /branches/new-upload/phase3/includes/UploadFromUrl.php (modified) (history)
  • /branches/new-upload/phase3/includes/api/ApiUpload.php (modified) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvFirefogg.js (modified) (history)
  • /branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvUploader.js (modified) (history)
  • /branches/new-upload/phase3/js2/uploadPage.js (modified) (history)

Diff [purge]

Index: branches/new-upload/phase3/includes/UploadFromUrl.php
@@ -15,7 +15,7 @@
1616 return $wgAllowCopyUploads && parent::isEnabled();
1717 }
1818 /*entry point for Api upload:: ASYNC_DOWNLOAD (if possible) */
19 - function initialize( $name, $url, $asyncdownload) {
 19+ function initialize( $name, $url, $asyncdownload = Http::SYNC_DOWNLOAD ) {
2020 global $wgTmpDirectory, $wgPhpCliPath;
2121
2222 if($asyncdownload && $wgPhpCliPath && wfShellExecEnabled() ){
Index: branches/new-upload/phase3/includes/api/ApiUpload.php
@@ -103,7 +103,7 @@
104104 }else if( $this->mParams['sessionkey'] ) {
105105 // Stashed upload
106106 $this->mUpload = new UploadFromStash();
107 - $this->mUpload->initialize( $this->mParams['sessionkey'] );
 107+ $this->mUpload->initialize( $this->mParams['filename'], $_SESSION['wsUploadData'][$this->mParams['sessionkey']] );
108108 }else{
109109 // Upload from url or file
110110 // Parameter filename is required
Index: branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvFirefogg.js
@@ -146,10 +146,7 @@
147147 $j('#wgfogg_waring_bad_extension').show();
148148 return false;
149149 }
150 - }
151 - //run the onClick hanndle:
152 - if( toggleFilenameFiller )
153 - toggleFilenameFiller();
 150+ }
154151 }
155152 },
156153 getProgressTitle:function(){
Index: branches/new-upload/phase3/js2/mwEmbed/libAddMedia/mvUploader.js
@@ -25,8 +25,11 @@
2626 "unknown-error": "Unknown Error",
2727 "return-to-form": "Return to form",
2828
29 - "file-exists-duplicate" : "This file is a duplicate of the following file"
30 -
 29+ "file-exists-duplicate" : "This file is a duplicate of the following file",
 30+ "fileexists" : "A file with this name exists already, please check <b><tt>$1</tt></b> if you are not sure if you want to change it.",
 31+ "fileexists-thumb": "<center><b>Existing file</b></center>",
 32+ "ignorewarning" : "Ignore warning and save file anyway",
 33+ "file-thumbnail-no" : "The filename begins with <b><tt>$1</tt></b>"
3134 });
3235
3336 var default_upload_options = {
@@ -155,6 +158,115 @@
156159 '<input id="wgEnableFirefogg" type="checkbox" name="wgEnableFirefogg" >' +
157160 gM('upload-enable-converter') +
158161 '</span><br></p>');
 162+ },
 163+ /**
 164+ * doDestCheck checks the destination
 165+ * @@todo we should be able to configure its "targets" via parent config
 166+ */
 167+ doDestCheck:function(){
 168+ var _this = this;
 169+ $j('#wpDestFile-warning').empty();
 170+ //show loading
 171+ $j('#wpDestFile').after('<img id = "mw-spinner-wpDestFile" src ="'+ stylepath + '/common/images/spinner.gif" />');
 172+ //try and get a thumb of the current file (check its destination)
 173+ do_api_req({
 174+ 'data':{
 175+ 'titles': 'File:' + $j('#wpDestFile').val(),//@@todo we may need a more clever way to get a the filename
 176+ 'prop': 'imageinfo',
 177+ 'iiprop':'url|mime|size',
 178+ 'iiurlwidth': 150
 179+ },
 180+ 'url': _this.api_url
 181+ },function(data){
 182+ $j('#mw-spinner-wpDestFile').remove();
 183+ if(data && data.query && data.query.pages){
 184+ if( data.query.pages[-1] ){
 185+ //all good no file there
 186+ }else{
 187+ for(var page_id in data.query.pages){
 188+ if( data.query.normalized){
 189+ var ntitle = data.query.normalized[0].to;
 190+ }else{
 191+ var ntitle = data.query.pages[ page_id ].title;
 192+ }
 193+ var img = data.query.pages[ page_id ].imageinfo[0];
 194+ $j('#wpDestFile-warning').html(
 195+ '<ul>' +
 196+ '<li>'+
 197+ gM('fileexists', ntitle) +
 198+ '</li>'+
 199+ '<div class="thumb tright">' +
 200+ '<div style="width: ' + ( parseInt(img.thumbwidth)+2 ) + 'px;" class="thumbinner">' +
 201+ '<a title="' + ntitle + '" class="image" href="' + img.descriptionurl + '">' +
 202+ '<img width="' + img.thumbwidth + '" height="' + img.thumbheight + '" border="0" class="thumbimage" ' +
 203+ 'src="' + img.thumburl + '"' +
 204+ ' alt="' + ntitle + '"/>' +
 205+ '</a>' +
 206+ '<div class="thumbcaption">' +
 207+ '<div class="magnify">' +
 208+ '<a title="' + gM('thumbnail-more') + '" class="internal" ' +
 209+ 'href="' + img.descriptionurl +'"><img width="15" height="11" alt="" ' +
 210+ 'src="' + stylepath +"/>" +
 211+ '</a>'+
 212+ '</div>'+
 213+ gM('fileexists-thumb') +
 214+ '</div>' +
 215+ '</div>'+
 216+ '</div>' +
 217+ '</ul>'
 218+ );
 219+ }
 220+ }
 221+ }
 222+ });
 223+ },
 224+ /**
 225+ * doDestinationFill fills in a destination file-name based on a source asset name.
 226+ * @@todo we should be able to configure its "targets" via parent config
 227+ */
 228+ doDestinationFill:function( targetElm ){
 229+ js_log("doDestinationFill")
 230+ //remove any previously flagged errors
 231+ $j('#mw-upload-permitted,#mw-upload-prohibited').hide();
 232+
 233+ var path = $j(targetElm).val();
 234+ // Find trailing part
 235+ var slash = path.lastIndexOf('/');
 236+ var backslash = path.lastIndexOf('\\');
 237+ var fname;
 238+ if (slash == -1 && backslash == -1) {
 239+ fname = path;
 240+ } else if (slash > backslash) {
 241+ fname = path.substring(slash+1, 10000);
 242+ } else {
 243+ fname = path.substring(backslash+1, 10000);
 244+ }
 245+ //urls are less likely to have a usefull extension don't include them in the extention check
 246+ if( wgFileExtensions && $j(targetElm).attr('id') != 'wpUploadFileURL' ){
 247+ var found = false;
 248+ if( fname.lastIndexOf('.')!=-1 ){
 249+ var ext = fname.substr( fname.lastIndexOf('.')+1 );
 250+ for(var i=0; i < wgFileExtensions.length; i++){
 251+ if( wgFileExtensions[i].toLowerCase() == ext.toLowerCase() )
 252+ found = true;
 253+ }
 254+ }
 255+ if(!found){
 256+ //clear the upload set mw-upload-permitted to error
 257+ $j(targetElm).val('');
 258+ $j('#mw-upload-permitted,#mw-upload-prohibited').show().addClass('error');
 259+ //clear the wpDestFile as well:
 260+ $j('#wpDestFile').val('');
 261+ return false;
 262+ }
 263+ }
 264+ // Capitalise first letter and replace spaces by underscores
 265+ fname = fname.charAt(0).toUpperCase().concat(fname.substring(1,10000)).replace(/ /g, '_');
 266+ // Output result
 267+ $j('#wpDestFile').val( fname );
 268+
 269+ //do a destination check
 270+ this.doDestCheck();
159271 }
160272 }
161273 /**
@@ -171,6 +283,7 @@
172284 parent_uploader:false,
173285 formData:{}, //the form to be submitted
174286 upload_mode:'autodetect', //can be 'post', 'chunks' or autodetect. (autodetect issues an api call)
 287+ warnings_sessionkey:null,
175288 chunks_supported:false,
176289 form_post_override:false,
177290 init: function( iObj ){
@@ -217,12 +330,7 @@
218331 }
219332
220333 //get a clean loader:
221 - _this.dispProgressOverlay();
222 -
223 - //update the status to loading (we don't know if we will get status updates or not)
224 - $j('#dlbox-centered').html( '<h5>' + _this.getProgressTitle() + '</h5>' +
225 - mv_get_loading_img( 'left:40%;top:20%')
226 - );
 334+ _this.dispProgressOverlay();
227335
228336 //for some unknown reason we have to drop down the #p-search z-index:
229337 $j('#p-search').css('z-index', 1);
@@ -293,6 +401,7 @@
294402 //do the submit :
295403 _this.editForm.submit();
296404 }else if( _this.upload_mode == 'api' && $j('#wpSourceTypeURL').get(0).checked){
 405+ js_log('doHttpUpload (no form submit) ');
297406 //if the api is supported.. && source type is http do upload with http status updates
298407 _this.doHttpUpload();
299408 }else{
@@ -312,32 +421,24 @@
313422 },
314423 'url' : _this.api_url
315424 }, function( data ){
316 - //check for error:
317 - if( data.error){
318 - _this.updateUploadError( data.error.code );
319 - return ;
320 - }
321 - //check for warning:
322 - if( data.upload.warnings ){
323 - if( data.upload.warnings.duplicate ){
324 - _this.updateUploadError( gM('file-exists-duplicate', data.upload.warnings.duplicate[0].title.mTextform ) );
325 -
326 - //@@todo should use warning and let the user "ignore"
327 - //_this.updateUploadWarning( gM('file-exists-duplicate') );
328 - }
329 - }
330 - //check for session key:
331 - if( data.upload && data.upload.upload_session_key ){
332 - //set the session key
333 - _this.upload_session_key = data.upload.upload_session_key;
334 - js_log("set session key: " + _this.upload_session_key);
335 - //do ajax upload status:
336 - _this.doAjaxUploadStatus();
337 - return ;
338 - }
339 - js_log('could not parse upload api request result');
 425+ _this.processApiResult( data );
340426 });
341427 },
 428+ doAjaxWarningIgnore:function(){
 429+ var _this = this;
 430+ if( !_this.upload_session_key )
 431+ return js_error('missing upload_session_key (can\'t ignore warnigns');
 432+ //do the ignore warnings submit to the api:
 433+ do_api_req({
 434+ 'data':{
 435+ 'ignorewarnings' : 'true',
 436+ 'sessionkey' :!_this.upload_session_key
 437+ },
 438+ 'url': _this.api_url
 439+ },function(data){
 440+ _this.processApiResult(data);
 441+ });
 442+ },
342443 doAjaxUploadStatus:function() {
343444 var _this = this;
344445
@@ -413,26 +514,87 @@
414515 var _this = this;
415516 //check for simple error
416517 if( apiRes.error ){
417 - _this.updateUploadError( apiRes.error );
418 - //check for upload api error:
419 - }else if( apiRes.upload && apiRes.upload.result == "Failure" ){
 518+ if( apiRes.error.code )
 519+ _this.updateUploadError( apiRes.error.code );
 520+ //else just simple msg:
 521+ _this.updateUploadError( apiRes.error );
 522+ return false;
 523+ }
 524+ //check for upload api error:
 525+ if( apiRes.upload && apiRes.upload.result == "Failure" ){
 526+ var error_code = (typeof apiRes.upload.code == 'object')? apiRes.upload.code[0]:apiRes.upload.code;
420527 //error space is too large so we don't front load it
421528 //do a remote call to get the error msg:
422 - if( apiRes.upload.code[0]){
423 - gMsgLoadRemote(apiRes.upload.code[0], function(){
424 - js_log('send msg: ' + gM( apiRes.upload.code[0] ));
425 - _this.updateUploadError( gM( apiRes.upload.code[0] ));
 529+ if(!error_code || error_code == 'unknown-error'){
 530+ _this.updateUploadError( gM('unknown-error') );
 531+ }else{
 532+ gMsgLoadRemote(error_code, function(){
 533+ js_log('send msg: ' + gM( error_code ));
 534+ _this.updateUploadError( gM( error_code ));
426535 });
427 - }else{
428 - _this.updateUploadError( gM('unknown-error'));
 536+ }
 537+ return false;
 538+ }
 539+ //check for upload_session key for async upload:
 540+ if( apiRes.upload && apiRes.upload.upload_session_key ){
 541+ //set the session key
 542+ _this.upload_session_key = data.upload.upload_session_key;
 543+ js_log("set session key: " + _this.upload_session_key);
 544+ //do ajax upload status:
 545+ _this.doAjaxUploadStatus();
 546+ return true;
 547+ }
 548+
 549+ if( apiRes.upload.imageinfo && apiRes.upload.imageinfo.descriptionurl ){
 550+ _this.updateUploadDone( apiRes.upload.imageinfo.descriptionurl );
 551+ return true;
 552+ }
 553+
 554+ //check for upload error:
 555+ if( apiRes.upload && apiRes.upload.error){
 556+
 557+ }
 558+ //check for known warnings:
 559+ if( apiRes.upload.warnings ){
 560+ var wmsg = '<ul>';
 561+ for(var wtype in apiRes.upload.warnings){
 562+ var winfo = apiRes.upload.warnings[wtype]
 563+ wmsg+='<li>';
 564+ switch(wtype){
 565+ case 'duplicate':
 566+ case 'exists':
 567+ wmsg += gM('file-exists-duplicate') +' '+
 568+ '<b>' + winfo[1].title.mTextform + '</b>';
 569+ break;
 570+ case 'file-thumbnail-no':
 571+ wmsg += gM('file-thumbnail-no', winfo);
 572+ break;
 573+ default:
 574+ wmsg += gM('upload-misc-error') + ' ' + wtype;
 575+ break;
 576+ }
 577+ wmsg+='</li>';
429578 }
430 - }else if( apiRes.upload.imageinfo && apiRes.upload.imageinfo.descriptionurl ){
431 - _this.updateUploadDone( apiRes.upload.imageinfo.descriptionurl );
432 - }else{
433 - //nothing fits assume unkown error:
434 - _this.updateUploadError( gM('unknown-error'));
435 - }
 579+ wmsg+='</ul>';
 580+ if( apiRes.upload.warnings.sessionkey)
 581+ _this.warnings_sessionkey = apiRes.upload.warnings.sessionkey;
 582+ _this.updateUploadWarning( wmsg );
 583+ return false;
 584+ }
 585+
 586+ //nothing fits assume unkown error:
 587+ js_log('could not parse upload api request result');
 588+ _this.updateUploadError( gM('unknown-error'));
 589+ return false;
 590+
436591 },
 592+ updateUploadWarning:function( msg ){
 593+ $j( '#dlbox-centered' ).html( '<h3>' + gM('uploadwarning') + '</h3>' +
 594+ msg + '<p>' +
 595+ '<a id="mv-ignore-warnings">' + gM('ignorewarning') + '</a>'
 596+ );
 597+ //setup ignore warnings binding and ajax query:
 598+ },
437599 updateUploadError:function( msg ){
438600 $j( '#dlbox-centered' ).html( '<h3>' + gM('uploaderror') + '</h3>' +
439601 msg + '<p>' +
@@ -442,10 +604,7 @@
443605 $j('#dlbox-overlay,#dlbox-centered').hide();
444606 return false;
445607 });
446 - },
447 - updateUploadWarning:function( msg ){
448 -
449 - },
 608+ },
450609 updateUploadDone:function( url ){
451610 $j( '#dlbox-centered' ).html( '<h3>' + gM('successfulupload') + '</h3>' +
452611 gM( 'mv_upload_done', url) );
@@ -479,6 +638,5 @@
480639 '<div id="dlbox-overlay" class="dlbox-overlay" style="background:#000;cursor:wait;height:100%;'+
481640 'left:0;top:0;position:fixed;width:100%;z-index:99;filter:alpha(opacity=60);'+
482641 '-moz-opacity: 0.6; opacity: 0.6;" ></div>');
483 - }
484 -
 642+ }
485643 }
Index: branches/new-upload/phase3/js2/uploadPage.js
@@ -1,10 +1,7 @@
2 -
3 -loadGM({
4 - "fileexists" : "A file with this name exists already, please check <i><tt>$1</tt></i> if you are not sure if you want to change it.",
5 - "fileexists-thumb": "<center><b>Existing file<b></center>"
6 -});
7 -
8 -// simple script to invoke the upload with config:
 2+/*
 3+ * uploadPage.js to be run on specialUpload page.
 4+ * controls the invocation of the mvUploader class based on local config.
 5+ */
96 mwAddOnloadHook( function(){
107 //setup the upload handler for firefogg and normal uploads:
118 mvJsLoader.doLoad( {
@@ -12,69 +9,17 @@
1310 'mvUploader' : 'libAddMedia/mvUploader.js'
1411 },function(){
1512 mvUp = new mvUploader( { 'api_url' : wgServer + wgScriptPath + '/api.php' } );
16 - setupUploadFormBindings();
 13+ setupUploadFormBindings( mvUp );
1714 });
18 - //set up the upoload form bindings once all dom manipluation is done
19 - var setupUploadFormBindings = function(){
20 - if( wgAjaxUploadDestCheck ){
21 - //do destination check:
22 - var doDestCheck = function(){
23 - $j('#wpDestFile-warning').empty();
24 - //show loading
25 - $j('#wpDestFile').after('<img id = "mw-spinner-wpDestFile" src ="'+ stylepath + '/common/images/spinner.gif" />');
26 - //try and get a thumb of the current file (check its destination)
27 - do_api_req({
28 - 'data':{
29 - 'titles': 'File:' + $j('#wpDestFile').val(),//@@todo we may need a more clever way to get a the filename
30 - 'prop': 'imageinfo',
31 - 'iiprop':'url|mime|size',
32 - 'iiurlwidth': 150
33 - }
34 - },function(data){
35 - $j('#mw-spinner-wpDestFile').remove();
36 - if(data && data.query && data.query.pages){
37 - if( data.query.pages[-1] ){
38 - //all good no file there
39 - }else{
40 - for(var page_id in data.query.pages){
41 - if( data.query.normalized){
42 - var ntitle = data.query.normalized[0].to;
43 - }else{
44 - var ntitle = data.query.pages[ page_id ].title;
45 - }
46 - var img = data.query.pages[ page_id ].imageinfo[0];
47 - $j('#wpDestFile-warning').html(
48 - '<ul>' +
49 - '<li>'+
50 - gM('fileexists', ntitle) +
51 - '</li>'+
52 - '<div class="thumb tright">' +
53 - '<div style="width: ' + ( parseInt(img.thumbwidth)+2 ) + 'px;" class="thumbinner">' +
54 - '<a title="' + ntitle + '" class="image" href="' + img.descriptionurl + '">' +
55 - '<img width="' + img.thumbwidth + '" height="' + img.thumbheight + '" border="0" class="thumbimage" ' +
56 - 'src="' + img.thumburl + '"' +
57 - ' alt="' + ntitle + '"/>' +
58 - '</a>' +
59 - '<div class="thumbcaption">' +
60 - '<div class="magnify">' +
61 - '<a title="' + gM('thumbnail-more') + '" class="internal" ' +
62 - 'href="' + img.descriptionurl +'"><img width="15" height="11" alt="" ' +
63 - 'src="' + stylepath +"/>" +
64 - '</a>'+
65 - '</div>'+
66 - gM('fileexists-thumb') +
67 - '</div>' +
68 - '</div>'+
69 - '</div>' +
70 - '</ul>'
71 - );
72 - }
73 - }
74 - }
75 - });
76 - };
77 - $j('#wpDestFile').change(doDestCheck);
78 - }
 15+});
 16+//set up the upoload form bindings once all dom manipluation is done
 17+function setupUploadFormBindings( mvUp ){
 18+ if( wgAjaxUploadDestCheck ){
 19+ //do destination check:
 20+ $j('#wpDestFile').change( mvUp.doDestCheck );
 21+ }
 22+ //check if we have http enabled & setup enable/disable toggle:
 23+ if($j('#wpUploadFileURL').length != 0){
7924 var toggleUpType = function( set ){
8025 $j('#wpSourceTypeFile').get(0).checked = set;
8126 $j('#wpUploadFile').get(0).disabled = !set;
@@ -88,54 +33,13 @@
8934 $j("input[name='wpSourceType']").click(function(){
9035 toggleUpType( this.id == 'wpSourceTypeFile' );
9136 });
92 -
93 -
94 - $j('#wpUploadFile,#wpUploadFileURL').focus(function(){
95 - toggleUpType( this.id == 'wpUploadFile' );
96 - }).change(function(){ //also setup the onChange event binding:
97 - if (!wgUploadAutoFill) {
98 - return;
99 - }
100 - //remove any previously flagged errors
101 - $j('#mw-upload-permitted,#mw-upload-prohibited').hide();
102 -
103 - var path = $j(this).val();
104 - // Find trailing part
105 - var slash = path.lastIndexOf('/');
106 - var backslash = path.lastIndexOf('\\');
107 - var fname;
108 - if (slash == -1 && backslash == -1) {
109 - fname = path;
110 - } else if (slash > backslash) {
111 - fname = path.substring(slash+1, 10000);
112 - } else {
113 - fname = path.substring(backslash+1, 10000);
114 - }
115 - //urls are less likely to have a usefull extension don't include them in the extention check
116 - if( wgFileExtensions && $j(this).attr('id') != 'wpUploadFileURL' ){
117 - var found = false;
118 - if( fname.lastIndexOf('.')!=-1 ){
119 - var ext = fname.substr( fname.lastIndexOf('.')+1 );
120 - for(var i=0; i < wgFileExtensions.length; i++){
121 - if( wgFileExtensions[i].toLowerCase() == ext.toLowerCase() )
122 - found = true;
123 - }
124 - }
125 - if(!found){
126 - //clear the upload set mw-upload-permitted to error
127 - $j(this).val('');
128 - $j('#mw-upload-permitted,#mw-upload-prohibited').show().addClass('error');
129 - //clear the wpDestFile as well:
130 - $j('#wpDestFile').val('');
131 - return false;
132 - }
133 - }
134 - // Capitalise first letter and replace spaces by underscores
135 - fname = fname.charAt(0).toUpperCase().concat(fname.substring(1,10000)).replace(/ /g, '_');
136 - // Output result
137 - $j('#wpDestFile').val( fname );
138 - //do a destination check
139 - doDestCheck();
140 - });
14137 }
142 -});
\ No newline at end of file
 38+
 39+ $j('#wpUploadFile,#wpUploadFileURL').focus(function(){
 40+ toggleUpType( this.id == 'wpUploadFile' );
 41+ }).change(function(){ //also setup the onChange event binding:
 42+ if ( wgUploadAutoFill ) {
 43+ mvUp.doDestinationFill( this );
 44+ }
 45+ });
 46+}

Status & tagging log