Index: branches/js2-work/phase3/js/mwEmbed/modules/UploadWizard/mw.UploadWizard.js |
— | — | @@ -86,9 +86,18 @@ |
87 | 87 | _this.filename = result.upload.filename; |
88 | 88 | _this.title = "File:" + _this.filename; |
89 | 89 | |
90 | | - for (var key in result.upload.imageinfo) { |
91 | | - _this.imageinfo[key] = result.upload.imageinfo[key]; |
| 90 | + for ( var key in result.upload.imageinfo ) { |
| 91 | + // we get metadata as list of key-val pairs; convert to object for easier lookup. Assuming that EXIF fields are unique. |
| 92 | + if ( key === 'metadata' ) { |
| 93 | + _this.imageinfo.metadata = {}; |
| 94 | + $j.each( result.upload.imageinfo.metadata, function( i, pair ) { |
| 95 | + _this.imageinfo.metadata[pair['name']] = pair['value']; |
| 96 | + }); |
| 97 | + } else { |
| 98 | + _this.imageinfo[key] = result.upload.imageinfo[key]; |
| 99 | + } |
92 | 100 | } |
| 101 | + |
93 | 102 | }, |
94 | 103 | |
95 | 104 | /** |
— | — | @@ -111,8 +120,8 @@ |
112 | 121 | |
113 | 122 | var params = { |
114 | 123 | 'titles': _this.title, |
| 124 | + 'prop': 'imageinfo', |
115 | 125 | 'iiurlwidth': width, |
116 | | - 'prop': 'imageinfo', |
117 | 126 | 'iiprop': 'url' |
118 | 127 | }; |
119 | 128 | |
— | — | @@ -136,7 +145,7 @@ |
137 | 146 | var thumbnail = { |
138 | 147 | width: imageInfo.thumbwidth, |
139 | 148 | height: imageInfo.thumbheight, |
140 | | - url: imageInfo.url |
| 149 | + url: imageInfo.thumburl |
141 | 150 | } |
142 | 151 | _this._thumbnails[ "width" + width ] = thumbnail; |
143 | 152 | callback( thumbnail ); |
— | — | @@ -420,6 +429,7 @@ |
421 | 430 | _this.dataDiv = $j( '<div class="mwe-upwiz-details-data"></div>' ); |
422 | 431 | |
423 | 432 | _this.descriptionsDiv = $j( '<div class="mwe-upwiz-details-descriptions"></div>' ); |
| 433 | + |
424 | 434 | |
425 | 435 | _this.descriptionAdder = $j( '<a id="mwe-upwiz-desc-add"/>' ) |
426 | 436 | .attr( 'href', '#' ) |
— | — | @@ -433,24 +443,23 @@ |
434 | 444 | .append( $j( '<div class="mwe-upwiz-details-descriptions-add"></div>' ) |
435 | 445 | .append( _this.descriptionAdder ) ); |
436 | 446 | |
| 447 | + _this.dateInput = $j( '<input type="text" class="mwe-date" size="20"/>' ); |
| 448 | + $j( _this.dateInput ).datepicker( { dateFormat: 'yyyy-mm-dd' } ); |
437 | 449 | |
438 | 450 | $j( _this.div ) |
439 | 451 | .append( _this.macroDiv ) |
440 | 452 | .append( _this.thumbnailDiv ) |
441 | 453 | .append( _this.errorDiv ) |
442 | 454 | .append( $j( _this.dataDiv ) |
443 | | - .append( _this.descriptionsContainerDiv )); |
| 455 | + .append( _this.descriptionsContainerDiv ) |
| 456 | + .append( _this.dateInput ) |
| 457 | + ); |
444 | 458 | |
445 | 459 | |
446 | 460 | |
447 | 461 | // create the basic HTML |
448 | 462 | // thumbnail |
449 | 463 | |
450 | | - |
451 | | - // description in [ English ] |
452 | | - // description field |
453 | | - // title |
454 | | - |
455 | 464 | // about this work |
456 | 465 | // media type |
457 | 466 | // date created |
— | — | @@ -566,7 +575,7 @@ |
567 | 576 | var _this = this; |
568 | 577 | mw.log( "populating details from upload" ); |
569 | 578 | _this.setThumbnail( mw.getConfig( 'thumbnailWidth' ) ); |
570 | | - //_this.setDate(); |
| 579 | + _this.setDate(); |
571 | 580 | |
572 | 581 | //_this.setSource(); |
573 | 582 | |
— | — | @@ -578,7 +587,7 @@ |
579 | 588 | |
580 | 589 | /** |
581 | 590 | * look up thumbnail info and set it on the form, with loading spinner |
582 | | - * @param filename |
| 591 | + * |
583 | 592 | * @param width |
584 | 593 | */ |
585 | 594 | setThumbnail: function( width ) { |
— | — | @@ -603,6 +612,44 @@ |
604 | 613 | }, |
605 | 614 | |
606 | 615 | /** |
| 616 | + * Check if we got an EXIF date back; otherwise use today's date; and enter it into the details |
| 617 | + * XXX We ought to be using date + time here... |
| 618 | + * EXIF examples tend to be in ISO 8601, but the separators are sometimes things like colons, and they have lots of trailing info |
| 619 | + * (which we should actually be using, such as time and timezone) |
| 620 | + */ |
| 621 | + setDate: function() { |
| 622 | + var _this = this; |
| 623 | + var iso8601regex = /^(\d\d\d\d)[:\/-](\d\d)[:\/-](\d\d)\D.*/; |
| 624 | + var dateStr; |
| 625 | + var metadata = _this.upload.imageinfo.metadata; |
| 626 | + $j.each([metadata.DateTimeOriginal, metadata.DateTimeDigitized, metadata.DateTime], |
| 627 | + function( i, imageinfoDate ) { |
| 628 | + if ( imageinfoDate !== undefined ) { |
| 629 | + var d = imageinfoDate.trim(); |
| 630 | + if ( d.match( iso8601regex ) ) { |
| 631 | + dateStr = d.replace( iso8601regex, "$1-$2-$3" ); |
| 632 | + return false; // break from $j.each |
| 633 | + } |
| 634 | + } |
| 635 | + } |
| 636 | + ); |
| 637 | + // if we don't have EXIF or other metadata, let's use "now" |
| 638 | + // XXX if we have FileAPI, it might be clever to look at time created of the file. Save that in the |
| 639 | + // upload object for use here later, perhaps |
| 640 | + function pad( n ) { |
| 641 | + return n < 10 ? "0" + n : n; |
| 642 | + } |
| 643 | + |
| 644 | + if (dateStr === undefined) { |
| 645 | + d = new Date(); |
| 646 | + dateStr = d.getUTCFullYear() + '-' + pad(d.getUTCMonth()) + pad(d.getUTCDate()); |
| 647 | + } |
| 648 | + |
| 649 | + // ok by now we should definitely have a date string formatted in YYYY-MM-DD |
| 650 | + $j(_this.dateInput).val(dateStr); |
| 651 | + }, |
| 652 | + |
| 653 | + /** |
607 | 654 | * Convert entire details for this file into wikiText, which will then be posted to the file |
608 | 655 | * @return wikitext representing all details |
609 | 656 | */ |
— | — | @@ -631,15 +678,18 @@ |
632 | 679 | // we should not even allow them to press the button ( ? ) but then what about the queue... |
633 | 680 | } |
634 | 681 | $j.each( _this.descriptions, function( i, desc ) { |
635 | | - information.description += desc.getWikiText(); |
| 682 | + information['description'] += desc.getWikiText(); |
636 | 683 | } ) |
| 684 | + |
| 685 | + // XXX add a sanity check here for good date |
| 686 | + information['date'] = $j(_this.dateInput).val(); |
637 | 687 | |
638 | 688 | var info = ''; |
639 | 689 | for ( var key in information ) { |
640 | 690 | info += '|' + key + '=' + information[key] + "\n"; |
641 | 691 | } |
642 | 692 | |
643 | | - wikiText += "=={int:filedesc}==\n"; |
| 693 | + wikiText += "=={{int:filedesc}}==\n"; |
644 | 694 | |
645 | 695 | wikiText += '{{Information\n' + info + '}}\n'; |
646 | 696 | |
— | — | @@ -667,19 +717,31 @@ |
668 | 718 | var _this = this; |
669 | 719 | // are we okay to submit? |
670 | 720 | // check descriptions |
671 | | - |
672 | | - // are we changing the name ( moving the file? ) if so, do that first, and the rest of this submission has to become |
673 | | - // a callback when that is transported? |
674 | 721 | |
675 | 722 | // XXX check state of details for okayness ( license selected, at least one desc, sane filename ) |
676 | 723 | var wikiText = _this.getWikiText(); |
677 | 724 | mw.log( wikiText ); |
678 | | - // do some api call to edit the info |
| 725 | + |
| 726 | + var params = { |
| 727 | + action: 'edit', |
| 728 | + token: mw.getConfig('token'), |
| 729 | + title: _this.upload.title, |
| 730 | + // section: 0, ?? causing issues? |
| 731 | + text: wikiText, |
| 732 | + summary: "User edited page with " + mw.UploadWizard.userAgent, |
| 733 | + // notminor: 1, |
| 734 | + // basetimestamp: _this.upload.imageinfo.timestamp, (conflicts?) |
| 735 | + nocreate: 1 |
| 736 | + }; |
| 737 | + mw.log("editing!"); |
| 738 | + mw.log(params); |
| 739 | + var callback = function(result) { |
| 740 | + mw.log(result); |
| 741 | + mw.log("successful edit"); |
| 742 | + alert("posted successfully"); |
| 743 | + } |
| 744 | + mw.getJSON(params, callback); |
679 | 745 | |
680 | | - // api.php ? action = edit & title = Talk:Main_Page & section = new & summary = Hello%20World & text = Hello%20everyone! & watch & basetimestamp = 2008 - 03 - 20T17:26:39Z & token = cecded1f35005d22904a35cc7b736e18%2B%5C |
681 | | - // caution this may result in a captcha response, which user will have to solve |
682 | | - // |
683 | | - |
684 | 746 | // then, if the filename was changed, do another api call to move the page |
685 | 747 | // THIS MAY NOT WORK ON ALL WIKIS. for instance, on Commons, it may be that only admins can move pages. This is another example of how |
686 | 748 | // we need an "incomplete" upload status |
— | — | @@ -716,6 +778,10 @@ |
717 | 779 | |
718 | 780 | }; |
719 | 781 | |
| 782 | +mw.UploadWizard.userAgent = "UploadWizard (alpha) on " + $j.browser.name + " " + $j.browser.version; |
| 783 | + |
| 784 | + |
| 785 | + |
720 | 786 | mw.UploadWizard.prototype = { |
721 | 787 | maxUploads: 10, // XXX get this from config |
722 | 788 | maxSimultaneousUploads: 2, // XXX get this from config |