r65680 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65679‎ | r65680 | r65681 >
Date:03:03, 30 April 2010
Author:neilk
Status:deferred
Tags:
Comment:
beginning 4-step uploadwizard
Modified paths:
  • /branches/js2-work/phase3/js/mwEmbed/modules/UploadWizard/css/uploadWizard.css (modified) (history)
  • /branches/js2-work/phase3/js/mwEmbed/modules/UploadWizard/mw.UploadWizard.js (modified) (history)
  • /branches/js2-work/phase3/js/specialUploadWizardPage.js (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/js/mwEmbed/modules/UploadWizard/mw.UploadWizard.js
@@ -1,7 +1,8 @@
22 mw.addMessages( {
33 "mwe-upwiz-tab-file": "1. Upload your files",
4 - "mwe-upwiz-tab-details": "2. Add licenses and descriptions",
5 - "mwe-upwiz-tab-thanks": "3. Use your files",
 4+ "mwe-upwiz-tab-deeds": "2. Add licenses",
 5+ "mwe-upwiz-tab-details": "3. Add descriptions",
 6+ "mwe-upwiz-tab-thanks": "4. Use your files",
67 "mwe-upwiz-intro": "Welcome to Wikimedia Commons, a repository of images, sounds, and movies that anyone can freely download and use. Add to humanity's knowledge by uploading files that could be used for an educational purpose.",
78
89 "mwe-upwiz-add-file-n": "Add another file",
@@ -17,7 +18,8 @@
1819 "mwe-upwiz-upload-count": "$1 of $2 files uploaded",
1920 "mwe-upwiz-progressbar-uploading": "uploading",
2021 "mwe-upwiz-remaining": "$1 remaining",
21 - "mwe-upwiz-intro-details": "Thank you! Now we need some basic information about the files you just uploaded.",
 22+ "mwe-upwiz-deeds-intro": "Thank you! Now we need to set a license for these files, so everyone can legally view or modify them. First, we'll have to know where you got them.",
 23+ "mwe-upwiz-details-intro": "Now we need some basic information about the files.",
2224 "mwe-upwiz-source-ownwork": "This file is my own work.",
2325 "mwe-upwiz-source-ownwork-plural": "These files are my own work.",
2426 "mwe-upwiz-source-ownwork-assert": "I, $1, the copyright holder of this work, hereby grant anyone the right to use this work for any purpose, as long as they credit me and share derivative work under the same terms.",
@@ -421,6 +423,7 @@
422424 if ( result.upload && result.upload.imageinfo && result.upload.imageinfo.descriptionurl ) {
423425 // success
424426 _this.extractUploadInfo( result );
 427+ _this.deedPreview.setup();
425428 _this.details.populate();
426429
427430 } else if ( result.upload && result.upload.sessionkey ) {
@@ -557,7 +560,48 @@
558561 }
559562 } );
560563
 564+ },
 565+
 566+
 567+ /**
 568+ * look up thumbnail info and set it in HTML, with loading spinner
 569+ * it might be interesting to make this more of a publish/subscribe thing, since we have to do this 3x
 570+ * the callbacks may pile up, getting unnecessary info
 571+ *
 572+ * @param selector
 573+ * @param width
 574+ */
 575+ setThumbnail: function( selector, width, imgClass ) {
 576+ var _this = this;
 577+ if ( typeof width === 'undefined' || width === null || width <= 0 ) {
 578+ width = mw.getConfig( 'thumbnailWidth' );
 579+ }
 580+ width = parseInt( width, 10 );
 581+
 582+ if ( typeof imgClass === 'undefined' || imgClass === null ) {
 583+ imgClass = 'mwe-upwiz-thumbnail';
 584+ }
 585+
 586+ var callback = function( thumbnail ) {
 587+ // side effect: will replace thumbnail's loadingSpinner
 588+ $j( selector ).html(
 589+ $j('<a/>')
 590+ .attr( { 'href': _this.imageinfo.descriptionurl,
 591+ 'target' : '_new' } )
 592+ .append(
 593+ $j( '<img/>' )
 594+ .addClass( imgClass )
 595+ .attr( 'width', thumbnail.width )
 596+ .attr( 'height', thumbnail.height )
 597+ .attr( 'src', thumbnail.url ) ) );
 598+ };
 599+
 600+ $j( selector ).loadingSpinner();
 601+ _this.getThumbnail( width, callback );
561602 }
 603+
 604+
 605+
562606 };
563607
564608 /**
@@ -1307,7 +1351,7 @@
13081352 populate: function() {
13091353 var _this = this;
13101354 mw.log( "populating details from upload" );
1311 - _this.setThumbnail( mw.getConfig( 'thumbnailWidth' ) );
 1355+ _this.upload.setThumbnail( _this.thumbnailDiv );
13121356 _this.prefillDate();
13131357 _this.prefillSource();
13141358 _this.prefillAuthor();
@@ -1317,33 +1361,6 @@
13181362 },
13191363
13201364 /**
1321 - * look up thumbnail info and set it on the form, with loading spinner
1322 - *
1323 - * @param width
1324 - */
1325 - setThumbnail: function( width ) {
1326 - var _this = this;
1327 -
1328 - var callback = function( thumbnail ) {
1329 - // side effect: will replace thumbnail's loadingSpinner
1330 - _this.thumbnailDiv.html(
1331 - $j('<a/>')
1332 - .attr( { 'href': _this.upload.imageinfo.descriptionurl,
1333 - 'target' : '_new' } )
1334 - .append(
1335 - $j( '<img/>' )
1336 - .addClass( "mwe-upwiz-thumbnail" )
1337 - .attr( 'width', thumbnail.width )
1338 - .attr( 'height', thumbnail.height )
1339 - .attr( 'src', thumbnail.url ) ) );
1340 - };
1341 -
1342 - _this.thumbnailDiv.loadingSpinner();
1343 - _this.upload.getThumbnail( width, callback );
1344 -
1345 - },
1346 -
1347 - /**
13481365 * Check if we got an EXIF date back; otherwise use today's date; and enter it into the details
13491366 * XXX We ought to be using date + time here...
13501367 * EXIF examples tend to be in ISO 8601, but the separators are sometimes things like colons, and they have lots of trailing info
@@ -1764,7 +1781,7 @@
17651782 mw.UploadWizard.prototype = {
17661783 maxUploads: 10, // XXX get this from config
17671784 maxSimultaneousUploads: 2, // XXX get this from config
1768 - tabNames: [ 'file', 'details', 'thanks' ],
 1785+ tabNames: [ 'file', 'deeds', 'details', 'thanks' ],
17691786 currentTabName: undefined,
17701787
17711788 /*
@@ -1811,6 +1828,7 @@
18121829 '<div id="mwe-upwiz-tabs">'
18131830 + '<ul>'
18141831 + '<li id="mwe-upwiz-tab-file"><span class="mwe-arrow-text">' + gM('mwe-upwiz-tab-file') + '<span class="mwe-arrow"/></span></span></li>'
 1832+ + '<li id="mwe-upwiz-tab-deeds"><span class="mwe-arrow-text">' + gM('mwe-upwiz-tab-deeds') + '<span class="mwe-arrow"/></span></span></li>'
18151833 + '<li id="mwe-upwiz-tab-details"><span class="mwe-arrow-text">' + gM('mwe-upwiz-tab-details') + '<span class="mwe-arrow"/></span></span></li>'
18161834 + '<li id="mwe-upwiz-tab-thanks"><span class="mwe-arrow-text">' + gM('mwe-upwiz-tab-thanks') + '<span class="mwe-arrow"/></span></span></li>'
18171835 + '</ul>'
@@ -1836,12 +1854,16 @@
18371855 + '</div>'
18381856 + '<div style="clear: left;"></div>'
18391857 + '</div>'
 1858+ + '<div class="mwe-upwiz-tabdiv" id="mwe-upwiz-tabdiv-deeds">'
 1859+ + '<div id="mwe-upwiz-deeds-intro"></div>'
 1860+ + '<div id="mwe-upwiz-deeds-thumbnails"></div>'
 1861+ + '<div id="mwe-upwiz-deeds"></div>'
 1862+ + '</div>'
18401863 + '<div class="mwe-upwiz-tabdiv" id="mwe-upwiz-tabdiv-details">'
18411864 + '<div id="mwe-upwiz-macro">'
18421865 + '<div id="mwe-upwiz-macro-progress" class="ui-helper-clearfix"></div>'
18431866 + '<div id="mwe-upwiz-macro-choice">'
1844 - + '<div>' + gM( 'mwe-upwiz-intro-details' ) + '</div>'
1845 - + '<div id="mwe-upwiz-macro-deeds"></div>'
 1867+ + '<div>' + gM( 'mwe-upwiz-details-intro' ) + '</div>'
18461868 + '</div>'
18471869 + '<div id="mwe-upwiz-macro-files"></div>'
18481870 + '<div class="mwe-upwiz-macro-edit-submit"></div>' // button added below
@@ -1855,8 +1877,21 @@
18561878 + '<div class="mwe-upwiz-clearing"></div>';
18571879
18581880 // within FILE tab div
1859 - $j('#mwe-upwiz-upload-ctrl').click( function() { _this.startUploads(); } );
 1881+ $j('#mwe-upwiz-upload-ctrl').click( function() {
 1882+ _this.removeEmptyUploads();
 1883+
 1884+ // we set up deed chooser here, because it's only now that we know how many uploads there are
 1885+ // possibly it should have some kind of morphing interface for singular/plural, but this doesn't
 1886+ // seem too bad for now.
 1887+ _this.deedChooser = new mw.UploadWizardDeedChooser( '#mwe-upwiz-deeds', ( _this.uploads.length > 1 ) );
18601888
 1889+ _this.startUploads();
 1890+ } );
 1891+
 1892+ // deeds div
 1893+ $j( '#mwe-upwiz-deeds-intro' ).html( gM( 'mwe-upwiz-deeds-intro' ) );
 1894+
 1895+
18611896 // DETAILS div
18621897 $j( '.mwe-upwiz-deed-form' ).maskSafeHide();
18631898
@@ -1876,13 +1911,12 @@
18771912 } ) );
18781913 } );
18791914
1880 - _this.deedChooser = new mw.UploadWizardDeedChooser( '#mwe-upwiz-macro-deeds', true );
18811915
18821916 // add one to start
18831917 var upload = _this.newUpload( '#mwe-upwiz-add-file' );
18841918
18851919 // "select" the first tab - highlight, make it visible, hide all others
1886 - _this.moveToTab('file', function() {
 1920+ _this.moveToTab( 'file', function() {
18871921 // XXX moving the file input doesn't seem to work at this point
18881922 // we are catching up to the application of CSS or something
18891923 // XXX using a timeout is lame, are there other options?
@@ -1925,7 +1959,7 @@
19261960 } else {
19271961 // it's neither the formerly active nor the newly active one, so don't show it
19281962 // we don't use hide() because we want to manipulate elements within future tabs, and calculate their dimensions.
1929 - tabDiv.maskSafeHide();
 1963+ // tabDiv.maskSafeHide();
19301964 }
19311965 } );
19321966
@@ -1974,24 +2008,12 @@
19752009 // XXX check if it has a file?
19762010 _this.uploads.push( upload );
19772011 _this.updateFileCounts();
1978 - // maybe it would be better to defer details to later?
 2012+
 2013+ upload.deedPreview = new mw.UploadWizardDeedPreview( upload );
 2014+ upload.deedChooser = _this.deedChooser;
 2015+
 2016+ // set up details
19792017 upload.details = new mw.UploadWizardDetails( upload, $j( '#mwe-upwiz-macro-files' ));
1980 -
1981 - // by default, new uploads use the wizard's deed selector.
1982 - upload.deedChooser = _this.deedChooser;
1983 - $j( _this.deedChooser ).bind( 'chooseNullDeed', function(e) {
1984 - mw.log("upload received chooseNullDeed");
1985 - upload.details.div.mask();
1986 - e.stopPropagation();
1987 - } );
1988 - $j( _this.deedChooser ).bind( 'chooseDeed', function(e) {
1989 - mw.log("upload received choose");
1990 - upload.details.div.unmask();
1991 - e.stopPropagation();
1992 - } );
1993 -
1994 -
1995 - upload.details.div.mask();
19962018 },
19972019
19982020
@@ -2108,7 +2130,6 @@
21092131 */
21102132 startUploads: function() {
21112133 var _this = this;
2112 - _this.removeEmptyUploads();
21132134 // remove the upload button, and the add file button
21142135 $j( '#mwe-upwiz-upload-ctrl' ).hide();
21152136 $j( '#mwe-upwiz-add-file' ).hide();
@@ -2132,14 +2153,15 @@
21332154 },
21342155 function() {
21352156 $j.each( _this.uploads, function(i, upload) {
2136 - upload.state = 'details';
 2157+ upload.state = 'deeds';
21372158 } );
2138 - _this.moveToTab( 'details' );
 2159+ _this.moveToTab( 'deeds' );
21392160 }
21402161 );
21412162 },
21422163
21432164
 2165+
21442166 /**
21452167 * Occurs whenever we need to update the interface based on how many files there are
21462168 * Thhere is an uncounted upload, waiting to be used, which has a fileInput which covers the
@@ -2226,28 +2248,11 @@
22272249
22282250 $j.each( _this.uploads, function(i, upload) {
22292251 var thanksDiv = $j( '<div class="mwe-upwiz-thanks ui-helper-clearfix" />' );
 2252+
22302253 var thumbnailDiv = $j( '<div></div>' ).addClass( 'mwe-upwiz-thumbnail' );
22312254 thanksDiv.append( thumbnailDiv );
 2255+ upload.setThumbnail( thumbnailDiv );
22322256
2233 - /* XXX this is copied code, evil */
2234 - var callback = function( thumbnail ) {
2235 - // side effect: will replace thumbnail's loadingSpinner
2236 - thumbnailDiv.html(
2237 - $j('<a>')
2238 - .attr( { 'href': upload.imageinfo.descriptionurl,
2239 - 'target': '_new' } )
2240 - .append(
2241 - $j( '<img/>' )
2242 - .addClass( "mwe-upwiz-thumbnail" )
2243 - .attr( 'width', thumbnail.width )
2244 - .attr( 'height', thumbnail.height )
2245 - .attr( 'src', thumbnail.url ) ) );
2246 - };
2247 -
2248 - thumbnailDiv.loadingSpinner();
2249 - upload.getThumbnail( width, callback );
2250 - /* end evil copied code */
2251 -
22522257 var thumbTitle = upload.title.replace(/^File/, 'Image'); // XXX is this really necessary?
22532258 var thumbWikiText = "[[" + thumbTitle + "|thumb]]";
22542259
@@ -2300,6 +2305,21 @@
23012306 }
23022307 };
23032308
 2309+
 2310+mw.UploadWizardDeedPreview = function(upload) {
 2311+ this.upload = upload;
 2312+};
 2313+
 2314+mw.UploadWizardDeedPreview.prototype = {
 2315+ setup: function() {
 2316+ var _this = this;
 2317+ // add a preview on the deeds page
 2318+ var thumbnailDiv = $j( '<div></div>' ).addClass( 'mwe-upwiz-thumbnail' );
 2319+ $j( '#mwe-upwiz-deeds-thumbnails' ).append( thumbnailDiv );
 2320+ _this.upload.setThumbnail( thumbnailDiv, mw.getConfig( 'smallThumbnailWidth' ), 'mwe-upwiz-smallthumbnail' );
 2321+ }
 2322+};
 2323+
23042324 mw.UploadWizardNullDeed = $j.extend( new mw.UploadWizardDeed(), {
23052325 isReady: function() {
23062326 return false;
Index: branches/js2-work/phase3/js/mwEmbed/modules/UploadWizard/css/uploadWizard.css
@@ -268,6 +268,16 @@
269269 margin-right: 12px;
270270 }
271271
 272+#mwe-upwiz-deeds-thumbnails {
 273+ text-align: center;
 274+ vertical-align: middle;
 275+}
 276+
 277+.mwe-upwiz-smallthumbnail {
 278+ width: 60px; /* XXX should be same as configured small thumbnail width in uploadWizard.js */
 279+ margin: 6px;
 280+}
 281+
272282 .mwe-upwiz-data {
273283 float: left;
274284 }
Index: branches/js2-work/phase3/js/specialUploadWizardPage.js
@@ -14,6 +14,7 @@
1515 mw.setConfig( 'fileExtensions', wgFileExtensions );
1616 mw.setConfig( 'token', wgEditToken );
1717 mw.setConfig( 'thumbnailWidth', 120 );
 18+ mw.setConfig( 'smallThumbnailWidth', 60 );
1819
1920 // not for use with all wikis.
2021 // The ISO 639 code for the language tagalog is "tl".

Status & tagging log