r63451 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63450‎ | r63451 | r63452 >
Date:00:56, 9 March 2010
Author:neilk
Status:deferred
Tags:
Comment:
retrieve thumbnails once files uploaded
Modified paths:
  • /branches/js2-work/phase3/js/mwEmbed/modules/UploadWizard/mw.UploadWizard.js (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js/mwEmbed/modules/UploadWizard/mw.UploadWizard.js
@@ -147,7 +147,7 @@
148148 var filename = _this.convertPathToFilename(path);
149149 // XXX store the "desired" filename for later, when we rename the file
150150 // 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;
152152 $j(_this.filenameCtrl).attr('value', filename);
153153 _this.filenameAcceptedCb();
154154 },
@@ -293,7 +293,7 @@
294294
295295 _this.div = $j('<div class="mwe-upwiz-metadata-file"></div>');
296296
297 - _this.thumbnail = $j('<img class="mwe-upwiz-thumbnail"/>');
 297+ _this.thumbnail = $j('<img class="mwe-upwiz-thumbnail"/>').get(0);
298298 var thumbnailDiv = $j('<div class="mwe-upwiz-thumbnail"></div>').append(_this.thumbnail).get(0);
299299
300300 _this.errorDiv = $j('<div class="mwe-upwiz-metadata-error"></div>');
@@ -312,7 +312,7 @@
313313
314314
315315 $j(_this.div)
316 - .append(_this.thumbnailDiv)
 316+ .append(thumbnailDiv)
317317 .append(_this.errorDiv)
318318 .append($j(_this.dataDiv)
319319 .append(_this.descriptionsContainerDiv));
@@ -377,6 +377,7 @@
378378
379379 // just like error but with ok/cancel
380380 errorDuplicate: function(sessionKey, duplicates) {
 381+ var _this = this;
381382 /*
382383 TODO - do something clever to get page URLs and image URLs
383384 var duplicatePageTitles = result.upload.warnings.duplicate;
@@ -400,55 +401,76 @@
401402
402403 // given the API result pull some info into the form (for instance, extracted from EXIF, desired filename)
403404 populateFromResult: function(result) {
 405+ var _this = this;
404406 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...
410414 //_this.setProvenance(result);
411415 //_this.setAuthor(_this.config.user, upload.exif.Copyright);
412416 },
413417
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;
419421
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+ };
427428
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);
435431
436 - var basename = url.exec(/\/([^\/]+)$/)[1];
 432+ },
437433
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();
440441 }
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;
450442
451 - },
 443+ var params = {
 444+ 'titles': title,
 445+ 'iiurlwidth': width,
 446+ 'prop': 'imageinfo',
 447+ 'iiprop': 'url|mime|size'
 448+ };
452449
 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+
453475 getWikiText: function() {
454476 wikiText = '';
455477
@@ -517,8 +539,8 @@
518540
519541
520542 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
523545 tabs: [ 'file', 'metadata', 'thanks' ],
524546
525547 /*
@@ -829,7 +851,6 @@
830852 uploadProgress: function(upload, progress) {
831853 console.log("upload progress is " + progress);
832854 var _this = this;
833 - //debugger;
834855 upload.progress = progress;
835856 _this.showProgress();
836857 },
@@ -840,6 +861,7 @@
841862 _this.removeItem(_this._uploadsInProgress, upload);
842863
843864 if ( result.upload && result.upload.imageinfo && result.upload.imageinfo.descriptionurl ) {
 865+ // success
844866 setTimeout( function() { upload.metadata.populateFromResult(result); }, 0 );
845867
846868 } else if (result.upload && result.upload.sessionkey) {
@@ -901,7 +923,6 @@
902924 // likewise, the remaining time should disappear, fadeout maybe.
903925
904926 // do some sort of "all done" thing for the UI - advance to next tab maybe.
905 - alert("all done!");
906927 _this.moveToTab('metadata');
907928 }
908929

Status & tagging log