[MediaWiki-commits] [Gerrit] Use promises instead of triggers for Flickr - change (mediawiki...UploadWizard)
jenkins-bot has submitted this change and it was merged. Change subject: Use promises instead of triggers for Flickr .. Use promises instead of triggers for Flickr This is some bad bloody code. Also moved static stuff out of the prototype and cached more intelligently. Change-Id: I9ee2479697f62132510af65255eca2b4a04e0906 --- M resources/mw.FlickrChecker.js M resources/mw.UploadWizard.js 2 files changed, 42 insertions(+), 26 deletions(-) Approvals: Bartosz DziewoĆski: Looks good to me, approved jenkins-bot: Verified diff --git a/resources/mw.FlickrChecker.js b/resources/mw.FlickrChecker.js index 0bf46f8..a4276bb 100644 --- a/resources/mw.FlickrChecker.js +++ b/resources/mw.FlickrChecker.js @@ -34,25 +34,35 @@ */ mw.FlickrChecker.blacklist = null; - mw.FlickrChecker.prototype = { - licenseList: [], - // Map each Flickr license name to the equivalent templates. - // These are the current Flickr license names as of April 26, 2011. - // Live list at http://api.flickr.com/services/rest/?=flickr.photos.licenses.getInfo_key=... - licenseMaps: { - 'All Rights Reserved': 'invalid', - 'Attribution License': '{{FlickrVerifiedByUploadWizard|cc-by-2.0}}{{cc-by-2.0}}', - 'Attribution-NoDerivs License': 'invalid', - 'Attribution-NonCommercial-NoDerivs License': 'invalid', - 'Attribution-NonCommercial License': 'invalid', - 'Attribution-NonCommercial-ShareAlike License': 'invalid', - 'Attribution-ShareAlike License': '{{FlickrVerifiedByUploadWizard|cc-by-sa-2.0}}{{cc-by-sa-2.0}}', - 'No known copyright restrictions': '{{FlickrVerifiedByUploadWizard|Flickr-no known copyright restrictions}}{{Flickr-no known copyright restrictions}}', - 'United States Government Work': '{{FlickrVerifiedByUploadWizard|PD-USGov}}{{PD-USGov}}', - 'Public Domain Dedication (CC0)': '{{FlickrVerifiedByUploadWizard|cc-zero}}{{cc-zero}}', - 'Public Domain Mark': '{{FlickrVerifiedByUploadWizard|Public Domain Mark}}' // T105629 - }, + /** +* Cache for Flickr license lookups. +* @type {jQuery.Promise} +*/ + mw.FlickrChecker.licensePromise = null; + /** +* Flickr licenses. +*/ + mw.FlickrChecker.licenseList = []; + + // Map each Flickr license name to the equivalent templates. + // These are the current Flickr license names as of April 26, 2011. + // Live list at http://api.flickr.com/services/rest/?=flickr.photos.licenses.getInfo_key=... + mw.FlickrChecker.licenseMaps = { + 'All Rights Reserved': 'invalid', + 'Attribution License': '{{FlickrVerifiedByUploadWizard|cc-by-2.0}}{{cc-by-2.0}}', + 'Attribution-NoDerivs License': 'invalid', + 'Attribution-NonCommercial-NoDerivs License': 'invalid', + 'Attribution-NonCommercial License': 'invalid', + 'Attribution-NonCommercial-ShareAlike License': 'invalid', + 'Attribution-ShareAlike License': '{{FlickrVerifiedByUploadWizard|cc-by-sa-2.0}}{{cc-by-sa-2.0}}', + 'No known copyright restrictions': '{{FlickrVerifiedByUploadWizard|Flickr-no known copyright restrictions}}{{Flickr-no known copyright restrictions}}', + 'United States Government Work': '{{FlickrVerifiedByUploadWizard|PD-USGov}}{{PD-USGov}}', + 'Public Domain Dedication (CC0)': '{{FlickrVerifiedByUploadWizard|cc-zero}}{{cc-zero}}', + 'Public Domain Mark': '{{FlickrVerifiedByUploadWizard|Public Domain Mark}}' // T105629 + }; + + mw.FlickrChecker.prototype = { /** * If a photo is from Flickr, retrieve its license. If the license is valid, display the license * to the user, hide the normal license selection interface, and set it as the deed for the upload. @@ -576,20 +586,27 @@ /** * Retrieve the list of all current Flickr licenses and store it in an array (`mw.FlickrChecker.licenseList`) +* +* @return {jQuery.Promise} */ getLicenses: function () { + if ( mw.FlickrChecker.licensePromise ) { + return mw.FlickrChecker.licensePromise; + } + // Workaround for http://bugs.jquery.com/ticket/8283 jQuery.support.cors = true; - this.flickrRequest( { + mw.FlickrChecker.licensePromise = this.flickrRequest( { method:
[MediaWiki-commits] [Gerrit] Use promises instead of triggers for Flickr - change (mediawiki...UploadWizard)
MarkTraceur has uploaded a new change for review. https://gerrit.wikimedia.org/r/256434 Change subject: Use promises instead of triggers for Flickr .. Use promises instead of triggers for Flickr This is some bad bloody code. Also moved static stuff out of the prototype and cached more intelligently. Change-Id: I9ee2479697f62132510af65255eca2b4a04e0906 --- M resources/mw.FlickrChecker.js M resources/mw.UploadWizard.js 2 files changed, 42 insertions(+), 26 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard refs/changes/34/256434/1 diff --git a/resources/mw.FlickrChecker.js b/resources/mw.FlickrChecker.js index 0bf46f8..a4276bb 100644 --- a/resources/mw.FlickrChecker.js +++ b/resources/mw.FlickrChecker.js @@ -34,25 +34,35 @@ */ mw.FlickrChecker.blacklist = null; - mw.FlickrChecker.prototype = { - licenseList: [], - // Map each Flickr license name to the equivalent templates. - // These are the current Flickr license names as of April 26, 2011. - // Live list at http://api.flickr.com/services/rest/?=flickr.photos.licenses.getInfo_key=... - licenseMaps: { - 'All Rights Reserved': 'invalid', - 'Attribution License': '{{FlickrVerifiedByUploadWizard|cc-by-2.0}}{{cc-by-2.0}}', - 'Attribution-NoDerivs License': 'invalid', - 'Attribution-NonCommercial-NoDerivs License': 'invalid', - 'Attribution-NonCommercial License': 'invalid', - 'Attribution-NonCommercial-ShareAlike License': 'invalid', - 'Attribution-ShareAlike License': '{{FlickrVerifiedByUploadWizard|cc-by-sa-2.0}}{{cc-by-sa-2.0}}', - 'No known copyright restrictions': '{{FlickrVerifiedByUploadWizard|Flickr-no known copyright restrictions}}{{Flickr-no known copyright restrictions}}', - 'United States Government Work': '{{FlickrVerifiedByUploadWizard|PD-USGov}}{{PD-USGov}}', - 'Public Domain Dedication (CC0)': '{{FlickrVerifiedByUploadWizard|cc-zero}}{{cc-zero}}', - 'Public Domain Mark': '{{FlickrVerifiedByUploadWizard|Public Domain Mark}}' // T105629 - }, + /** +* Cache for Flickr license lookups. +* @type {jQuery.Promise} +*/ + mw.FlickrChecker.licensePromise = null; + /** +* Flickr licenses. +*/ + mw.FlickrChecker.licenseList = []; + + // Map each Flickr license name to the equivalent templates. + // These are the current Flickr license names as of April 26, 2011. + // Live list at http://api.flickr.com/services/rest/?=flickr.photos.licenses.getInfo_key=... + mw.FlickrChecker.licenseMaps = { + 'All Rights Reserved': 'invalid', + 'Attribution License': '{{FlickrVerifiedByUploadWizard|cc-by-2.0}}{{cc-by-2.0}}', + 'Attribution-NoDerivs License': 'invalid', + 'Attribution-NonCommercial-NoDerivs License': 'invalid', + 'Attribution-NonCommercial License': 'invalid', + 'Attribution-NonCommercial-ShareAlike License': 'invalid', + 'Attribution-ShareAlike License': '{{FlickrVerifiedByUploadWizard|cc-by-sa-2.0}}{{cc-by-sa-2.0}}', + 'No known copyright restrictions': '{{FlickrVerifiedByUploadWizard|Flickr-no known copyright restrictions}}{{Flickr-no known copyright restrictions}}', + 'United States Government Work': '{{FlickrVerifiedByUploadWizard|PD-USGov}}{{PD-USGov}}', + 'Public Domain Dedication (CC0)': '{{FlickrVerifiedByUploadWizard|cc-zero}}{{cc-zero}}', + 'Public Domain Mark': '{{FlickrVerifiedByUploadWizard|Public Domain Mark}}' // T105629 + }; + + mw.FlickrChecker.prototype = { /** * If a photo is from Flickr, retrieve its license. If the license is valid, display the license * to the user, hide the normal license selection interface, and set it as the deed for the upload. @@ -576,20 +586,27 @@ /** * Retrieve the list of all current Flickr licenses and store it in an array (`mw.FlickrChecker.licenseList`) +* +* @return {jQuery.Promise} */ getLicenses: function () { + if ( mw.FlickrChecker.licensePromise ) { + return mw.FlickrChecker.licensePromise; + } + // Workaround for http://bugs.jquery.com/ticket/8283 jQuery.support.cors = true; - this.flickrRequest( { + mw.FlickrChecker.licensePromise = this.flickrRequest( {