Index: branches/js2-work/phase3/js/mwEmbed/modules/UploadWizard/mw.UploadWizard.js |
— | — | @@ -147,7 +147,7 @@ |
148 | 148 | var filename = _this.convertPathToFilename(path); |
149 | 149 | // XXX store the "desired" filename for later, when we rename the file |
150 | 150 | // this is a hack to get a temporary file guaranteed unique -- will change perhaps, later |
151 | | - filename = mw.getConfig('userName') + "-" + (new Date()).getTime() + "-" + filename; |
| 151 | + filename = mw.getConfig('userName') + "_" + (new Date()).getTime() + "_" + filename; |
152 | 152 | $j(_this.filenameCtrl).attr('value', filename); |
153 | 153 | _this.filenameAcceptedCb(); |
154 | 154 | }, |
— | — | @@ -293,7 +293,7 @@ |
294 | 294 | |
295 | 295 | _this.div = $j('<div class="mwe-upwiz-metadata-file"></div>'); |
296 | 296 | |
297 | | - _this.thumbnail = $j('<img class="mwe-upwiz-thumbnail"/>'); |
| 297 | + _this.thumbnail = $j('<img class="mwe-upwiz-thumbnail"/>').get(0); |
298 | 298 | var thumbnailDiv = $j('<div class="mwe-upwiz-thumbnail"></div>').append(_this.thumbnail).get(0); |
299 | 299 | |
300 | 300 | _this.errorDiv = $j('<div class="mwe-upwiz-metadata-error"></div>'); |
— | — | @@ -312,7 +312,7 @@ |
313 | 313 | |
314 | 314 | |
315 | 315 | $j(_this.div) |
316 | | - .append(_this.thumbnailDiv) |
| 316 | + .append(thumbnailDiv) |
317 | 317 | .append(_this.errorDiv) |
318 | 318 | .append($j(_this.dataDiv) |
319 | 319 | .append(_this.descriptionsContainerDiv)); |
— | — | @@ -377,6 +377,7 @@ |
378 | 378 | |
379 | 379 | // just like error but with ok/cancel |
380 | 380 | errorDuplicate: function(sessionKey, duplicates) { |
| 381 | + var _this = this; |
381 | 382 | /* |
382 | 383 | TODO - do something clever to get page URLs and image URLs |
383 | 384 | var duplicatePageTitles = result.upload.warnings.duplicate; |
— | — | @@ -400,55 +401,76 @@ |
401 | 402 | |
402 | 403 | // given the API result pull some info into the form (for instance, extracted from EXIF, desired filename) |
403 | 404 | populateFromResult: function(result) { |
| 405 | + var _this = this; |
404 | 406 | var upload = result.upload; |
405 | | - _this.setThumbnail(upload.imageinfo, mw.getConfig('thumbnailWidth')); |
406 | | - _this.setFilename(upload.filename); |
407 | | - _this.setDescription(); // is there anything worthwhile here? image comment? |
408 | | - _this.setDate(upload.metadata); |
409 | | - _this.setLocation(upload.metadata); // we could be VERY clever with location sensing... |
| 407 | + console.log("populating from result"); |
| 408 | + _this.setThumbnail(upload.filename, mw.getConfig('thumbnailWidth')); |
| 409 | + |
| 410 | + // _this.setFilename(upload.filename); |
| 411 | + //_this.setDescription(); // is there anything worthwhile here? image comment? |
| 412 | + //_this.setDate(upload.metadata); |
| 413 | + //_this.setLocation(upload.metadata); // we could be VERY clever with location sensing... |
410 | 414 | //_this.setProvenance(result); |
411 | 415 | //_this.setAuthor(_this.config.user, upload.exif.Copyright); |
412 | 416 | }, |
413 | 417 | |
414 | | - // transform the url of the image into a suitable thumbnail url |
415 | | - // XXX THIS IS EVIL AND WRONG TO DO ON THE CLIENT SIDE |
416 | | - // the API should be returning a "thumbnail template" of sorts, as has been proposed before |
417 | | - // desiredWidth is in pixels |
418 | | - setThumbnail: function(imageInfo, desiredWidth) { |
| 418 | + // look up thumbnail info and set it |
| 419 | + setThumbnail: function(filename, width) { |
| 420 | + var _this = this; |
419 | 421 | |
420 | | - var url = imageInfo.url; |
421 | | - |
422 | | - // may be off-by-ones if the image scaler on the server rounds differently |
423 | | - var desiredHeight = desiredWidth; // assume square |
424 | | - if (imageInfo.height && imageInfo.width) { |
425 | | - desiredHeight = parseInt(imageInfo.height * (desiredWidth / imageInfo.width)); |
426 | | - } |
| 422 | + var callback = function(img) { |
| 423 | + _this.thumbnail.width = img.width; |
| 424 | + _this.thumbnail.height = img.height; |
| 425 | + _this.thumbnail.src = img.src; |
| 426 | + // XXX stop thumbnail spinner |
| 427 | + }; |
427 | 428 | |
428 | | - if (url === undefined || url === '') { |
429 | | - // XXX what the hell? |
430 | | - } |
431 | | - |
432 | | - // the image url looks like: http://host/path/to/images/filename.jpg |
433 | | - // a thumbnail url looks like: http://host/path/to/images/filename.jpg/120px-filename.jpg |
434 | | - // filename.jpg must be identical in both cases |
| 429 | + // XXX start thumbnail spinner |
| 430 | + _this.getThumbnail("File:" + filename, width, callback); |
435 | 431 | |
436 | | - var basename = url.exec(/\/([^\/]+)$/)[1]; |
| 432 | + }, |
437 | 433 | |
438 | | - if (basename == undefined || basename == '') { |
439 | | - // XXX what the hell? |
| 434 | + // use iinfo to get thumbnail info |
| 435 | + // this API method can be used to get a lot of thumbnails at once, but that may not be so useful for us ATM |
| 436 | + // this is mostly ripped off from mw.UploadHandler's doDestCheck, but: stripped of UI, does only one, does not check for name collisions. |
| 437 | + getThumbnail: function(title, width, setThumbnailCb, apiUrl) { |
| 438 | + |
| 439 | + if (apiUrl === undefined) { |
| 440 | + apiUrl = mw.getLocalApiUrl(); |
440 | 441 | } |
441 | | - |
442 | | - var thumbnailUrl = url + '/' + desiredWidth + 'px-' + basename; |
443 | | - |
444 | | - // this should already be true |
445 | | - _this.thumbnail.width = desiredWidth; |
446 | | - |
447 | | - // but this might be new info |
448 | | - _this.thumbnail.height = desiredHeight; |
449 | | - _this.thumbnail.src = thumbnailUrl; |
450 | 442 | |
451 | | - }, |
| 443 | + var params = { |
| 444 | + 'titles': title, |
| 445 | + 'iiurlwidth': width, |
| 446 | + 'prop': 'imageinfo', |
| 447 | + 'iiprop': 'url|mime|size' |
| 448 | + }; |
452 | 449 | |
| 450 | + mw.getJSON(apiUrl, params, function( data ) { |
| 451 | + if ( !data || !data.query || !data.query.pages ) { |
| 452 | + mw.log(" No data? ") |
| 453 | + return; |
| 454 | + } |
| 455 | + |
| 456 | + if (data.query.pages[-1]) { |
| 457 | + // not found ? error |
| 458 | + } |
| 459 | + // this long chain of properties only works because this method expects exactly one result |
| 460 | + for ( var page_id in data.query.pages ) { |
| 461 | + var page = data.query.pages[ page_id ]; |
| 462 | + if (! page.imageinfo ) { |
| 463 | + // not found? error |
| 464 | + } else { |
| 465 | + var img = page.imageinfo[0]; |
| 466 | + setThumbnailCb( { src: img.thumburl, |
| 467 | + width: img.thumbwidth, |
| 468 | + height: img.thumbheight }); |
| 469 | + } |
| 470 | + } |
| 471 | + }); |
| 472 | + }, |
| 473 | + |
| 474 | + |
453 | 475 | getWikiText: function() { |
454 | 476 | wikiText = ''; |
455 | 477 | |
— | — | @@ -517,8 +539,8 @@ |
518 | 540 | |
519 | 541 | |
520 | 542 | mw.UploadWizard.prototype = { |
521 | | - maxUploads: 10, // arbitrary |
522 | | - maxSimultaneousUploads: 2, // arbitrary |
| 543 | + maxUploads: 10, // XXX get this from config |
| 544 | + maxSimultaneousUploads: 2, // XXX get this from config |
523 | 545 | tabs: [ 'file', 'metadata', 'thanks' ], |
524 | 546 | |
525 | 547 | /* |
— | — | @@ -829,7 +851,6 @@ |
830 | 852 | uploadProgress: function(upload, progress) { |
831 | 853 | console.log("upload progress is " + progress); |
832 | 854 | var _this = this; |
833 | | - //debugger; |
834 | 855 | upload.progress = progress; |
835 | 856 | _this.showProgress(); |
836 | 857 | }, |
— | — | @@ -840,6 +861,7 @@ |
841 | 862 | _this.removeItem(_this._uploadsInProgress, upload); |
842 | 863 | |
843 | 864 | if ( result.upload && result.upload.imageinfo && result.upload.imageinfo.descriptionurl ) { |
| 865 | + // success |
844 | 866 | setTimeout( function() { upload.metadata.populateFromResult(result); }, 0 ); |
845 | 867 | |
846 | 868 | } else if (result.upload && result.upload.sessionkey) { |
— | — | @@ -901,7 +923,6 @@ |
902 | 924 | // likewise, the remaining time should disappear, fadeout maybe. |
903 | 925 | |
904 | 926 | // do some sort of "all done" thing for the UI - advance to next tab maybe. |
905 | | - alert("all done!"); |
906 | 927 | _this.moveToTab('metadata'); |
907 | 928 | } |
908 | 929 | |