r63801 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63800‎ | r63801 | r63802 >
Date:05:02, 16 March 2010
Author:neilk
Status:deferred
Tags:
Comment:
date entry
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
@@ -86,9 +86,18 @@
8787 _this.filename = result.upload.filename;
8888 _this.title = "File:" + _this.filename;
8989
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+ }
92100 }
 101+
93102 },
94103
95104 /**
@@ -111,8 +120,8 @@
112121
113122 var params = {
114123 'titles': _this.title,
 124+ 'prop': 'imageinfo',
115125 'iiurlwidth': width,
116 - 'prop': 'imageinfo',
117126 'iiprop': 'url'
118127 };
119128
@@ -136,7 +145,7 @@
137146 var thumbnail = {
138147 width: imageInfo.thumbwidth,
139148 height: imageInfo.thumbheight,
140 - url: imageInfo.url
 149+ url: imageInfo.thumburl
141150 }
142151 _this._thumbnails[ "width" + width ] = thumbnail;
143152 callback( thumbnail );
@@ -420,6 +429,7 @@
421430 _this.dataDiv = $j( '<div class="mwe-upwiz-details-data"></div>' );
422431
423432 _this.descriptionsDiv = $j( '<div class="mwe-upwiz-details-descriptions"></div>' );
 433+
424434
425435 _this.descriptionAdder = $j( '<a id="mwe-upwiz-desc-add"/>' )
426436 .attr( 'href', '#' )
@@ -433,24 +443,23 @@
434444 .append( $j( '<div class="mwe-upwiz-details-descriptions-add"></div>' )
435445 .append( _this.descriptionAdder ) );
436446
 447+ _this.dateInput = $j( '<input type="text" class="mwe-date" size="20"/>' );
 448+ $j( _this.dateInput ).datepicker( { dateFormat: 'yyyy-mm-dd' } );
437449
438450 $j( _this.div )
439451 .append( _this.macroDiv )
440452 .append( _this.thumbnailDiv )
441453 .append( _this.errorDiv )
442454 .append( $j( _this.dataDiv )
443 - .append( _this.descriptionsContainerDiv ));
 455+ .append( _this.descriptionsContainerDiv )
 456+ .append( _this.dateInput )
 457+ );
444458
445459
446460
447461 // create the basic HTML
448462 // thumbnail
449463
450 -
451 - // description in [ English ]
452 - // description field
453 - // title
454 -
455464 // about this work
456465 // media type
457466 // date created
@@ -566,7 +575,7 @@
567576 var _this = this;
568577 mw.log( "populating details from upload" );
569578 _this.setThumbnail( mw.getConfig( 'thumbnailWidth' ) );
570 - //_this.setDate();
 579+ _this.setDate();
571580
572581 //_this.setSource();
573582
@@ -578,7 +587,7 @@
579588
580589 /**
581590 * look up thumbnail info and set it on the form, with loading spinner
582 - * @param filename
 591+ *
583592 * @param width
584593 */
585594 setThumbnail: function( width ) {
@@ -603,6 +612,44 @@
604613 },
605614
606615 /**
 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+ /**
607654 * Convert entire details for this file into wikiText, which will then be posted to the file
608655 * @return wikitext representing all details
609656 */
@@ -631,15 +678,18 @@
632679 // we should not even allow them to press the button ( ? ) but then what about the queue...
633680 }
634681 $j.each( _this.descriptions, function( i, desc ) {
635 - information.description += desc.getWikiText();
 682+ information['description'] += desc.getWikiText();
636683 } )
 684+
 685+ // XXX add a sanity check here for good date
 686+ information['date'] = $j(_this.dateInput).val();
637687
638688 var info = '';
639689 for ( var key in information ) {
640690 info += '|' + key + '=' + information[key] + "\n";
641691 }
642692
643 - wikiText += "=={int:filedesc}==\n";
 693+ wikiText += "=={{int:filedesc}}==\n";
644694
645695 wikiText += '{{Information\n' + info + '}}\n';
646696
@@ -667,19 +717,31 @@
668718 var _this = this;
669719 // are we okay to submit?
670720 // 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?
674721
675722 // XXX check state of details for okayness ( license selected, at least one desc, sane filename )
676723 var wikiText = _this.getWikiText();
677724 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);
679745
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 -
684746 // then, if the filename was changed, do another api call to move the page
685747 // 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
686748 // we need an "incomplete" upload status
@@ -716,6 +778,10 @@
717779
718780 };
719781
 782+mw.UploadWizard.userAgent = "UploadWizard (alpha) on " + $j.browser.name + " " + $j.browser.version;
 783+
 784+
 785+
720786 mw.UploadWizard.prototype = {
721787 maxUploads: 10, // XXX get this from config
722788 maxSimultaneousUploads: 2, // XXX get this from config

Status & tagging log