jenkins-bot has submitted this change and it was merged. Change subject: Text changes for better handling of PD and nonfree licenses ......................................................................
Text changes for better handling of PD and nonfree licenses Bug: T70687 Change-Id: I84e0094559e5b438fcb33b8511dc0184435c1a37 Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/1004 Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/631 --- M MultimediaViewer.php M i18n/en.json M i18n/qqq.json M resources/mmv/mmv.EmbedFileFormatter.js M resources/mmv/model/mmv.model.Image.js M resources/mmv/model/mmv.model.License.js M resources/mmv/provider/mmv.provider.ImageInfo.js M resources/mmv/ui/mmv.ui.download.pane.js M tests/qunit/mmv/mmv.EmbedFileFormatter.test.js M tests/qunit/mmv/model/mmv.model.Image.test.js M tests/qunit/mmv/model/mmv.model.License.test.js M tests/qunit/mmv/provider/mmv.provider.ImageInfo.test.js M tests/qunit/mmv/ui/mmv.ui.reuse.utils.test.js 13 files changed, 184 insertions(+), 39 deletions(-) Approvals: MarkTraceur: Looks good to me, approved jenkins-bot: Verified diff --git a/MultimediaViewer.php b/MultimediaViewer.php index 7a47510..2ca3ad0 100644 --- a/MultimediaViewer.php +++ b/MultimediaViewer.php @@ -453,6 +453,7 @@ 'multimediaviewer-embed-dimensions', 'multimediaviewer-embed-dimensions-with-file-format', 'multimediaviewer-download-attribution-cta-header', + 'multimediaviewer-download-optional-attribution-cta-header', 'multimediaviewer-download-attribution-cta', 'multimediaviewer-attr-plain', 'multimediaviewer-attr-html', @@ -637,20 +638,28 @@ 'multimediaviewer-credit', 'multimediaviewer-text-embed-credit-text-tbls', + 'multimediaviewer-text-embed-credit-text-tbls-nonfree', 'multimediaviewer-text-embed-credit-text-tls', + 'multimediaviewer-text-embed-credit-text-tls-nonfree', 'multimediaviewer-text-embed-credit-text-tbs', 'multimediaviewer-text-embed-credit-text-tbl', + 'multimediaviewer-text-embed-credit-text-tbl-nonfree', 'multimediaviewer-text-embed-credit-text-tb', 'multimediaviewer-text-embed-credit-text-ts', 'multimediaviewer-text-embed-credit-text-tl', + 'multimediaviewer-text-embed-credit-text-tl-nonfree', 'multimediaviewer-html-embed-credit-text-tbls', + 'multimediaviewer-html-embed-credit-text-tbls-nonfree', 'multimediaviewer-html-embed-credit-text-tls', + 'multimediaviewer-html-embed-credit-text-tls-nonfree', 'multimediaviewer-html-embed-credit-text-tbs', 'multimediaviewer-html-embed-credit-text-tbl', + 'multimediaviewer-html-embed-credit-text-tbl-nonfree', 'multimediaviewer-html-embed-credit-text-tb', 'multimediaviewer-html-embed-credit-text-ts', 'multimediaviewer-html-embed-credit-text-tl', + 'multimediaviewer-html-embed-credit-text-tl-nonfree', ), ), diff --git a/i18n/en.json b/i18n/en.json index 8154f9f..4df2ba8 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -70,23 +70,32 @@ "multimediaviewer-embed-html": "HTML", "multimediaviewer-embed-explanation": "Use this code to embed the file", "multimediaviewer-text-embed-credit-text-tbls": "\"$1\" by $2. Licensed under $3 via $4", + "multimediaviewer-text-embed-credit-text-tbls-nonfree": "\"$1\" by $2. $3 via $4", "multimediaviewer-text-embed-credit-text-tls": "\"$1\". Licensed under $2 via $3", + "multimediaviewer-text-embed-credit-text-tls-nonfree": "\"$1\". $2 via $3", "multimediaviewer-text-embed-credit-text-tbs": "\"$1\" by $2. Via $3", "multimediaviewer-text-embed-credit-text-tbl": "\"$1\" by $2. Licensed under $3", + "multimediaviewer-text-embed-credit-text-tbl-nonfree": "\"$1\" by $2. $3", "multimediaviewer-text-embed-credit-text-tb": "\"$1\" by $2", "multimediaviewer-text-embed-credit-text-ts": "\"$1\". Via $2", "multimediaviewer-text-embed-credit-text-tl": "\"$1\". Licensed under $2", + "multimediaviewer-text-embed-credit-text-tl-nonfree": "\"$1\". $2", "multimediaviewer-text-embed-credit-text-t": "\"$1\"", "multimediaviewer-html-embed-credit-text-tbls": "\"$1\" by $2. Licensed under $3 via $4.", + "multimediaviewer-html-embed-credit-text-tbls-nonfree": "\"$1\" by $2. $3 via $4.", "multimediaviewer-html-embed-credit-text-tls": "\"$1\". Licensed under $2 via $3.", + "multimediaviewer-html-embed-credit-text-tls-nonfree": "\"$1\". $2 via $3.", "multimediaviewer-html-embed-credit-text-tbs": "\"$1\" by $2. Via $3.", "multimediaviewer-html-embed-credit-text-tbl": "\"$1\" by $2. Licensed under $3.", + "multimediaviewer-html-embed-credit-text-tbl-nonfree": "\"$1\" by $2. $3.", "multimediaviewer-html-embed-credit-text-tb": "\"$1\" by $2.", "multimediaviewer-html-embed-credit-text-ts": "\"$1\". Via $2.", "multimediaviewer-html-embed-credit-text-tl": "\"$1\". Licensed under $2.", + "multimediaviewer-html-embed-credit-text-tl-nonfree": "\"$1\". $2.", "multimediaviewer-html-embed-credit-text-t": "\"$1\".", "multimediaviewer-embed-byline": "By $1", "multimediaviewer-embed-license": "Licensed under $1.", + "multimediaviewer-embed-license-nonfree": "$1.", "multimediaviewer-embed-via": "Via $1.", "multimediaviewer-default-embed-dimensions": "Default thumbnail size", "multimediaviewer-original-embed-dimensions": "Original file $1", @@ -109,6 +118,7 @@ "multimediaviewer-title-popup-text-more": "View full description", "multimediaviewer-credit-popup-text-more": "View full author and source", "multimediaviewer-download-attribution-cta-header": "You need to attribute the author", + "multimediaviewer-download-optional-attribution-cta-header": "You can attribute the author", "multimediaviewer-download-attribution-cta": "Show me how", "multimediaviewer-attr-plain": "Plain", "multimediaviewer-attr-html": "HTML", diff --git a/i18n/qqq.json b/i18n/qqq.json index db805c2..fbd5200 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -76,23 +76,32 @@ "multimediaviewer-embed-html": "Used to represent a choice for embedding a file in an HTML document, as HTML.\n{{Identical|HTML}}", "multimediaviewer-embed-explanation": "Used below the embed textarea to explain what we expect the user to do.", "multimediaviewer-text-embed-credit-text-tbls": "Credit text, used when generating plain text for attributing an image.\n\nWhich one of the multimediaviewer-text-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the author\n* $3 - name of the license\n* $4 - name of the website/institution which was the direct source for this image. This parameter is usually an URL.\n{{Related|Multimediaviewer-embed-credit-text}}", + "multimediaviewer-text-embed-credit-text-tbls-nonfree": "Like {{msg-mw|multimediaviewer-text-embed-credit-text-tbls}}, but for non-free images (where $3 is typically not a license name but something like \"Fair use\").", "multimediaviewer-text-embed-credit-text-tls": "Credit text, used when generating plain text to attribute an image.\n\nWhich one of the multimediaviewer-text-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the license\n* $3 - name of the website/institution which was the direct source for this image. This parameter is usually an URL.\n{{Related|Multimediaviewer-embed-credit-text}}", + "multimediaviewer-text-embed-credit-text-tls-nonfree": "Like {{msg-mw|multimediaviewer-text-embed-credit-text-tls}}, but for non-free images (where $2 is typically not a license name but something like \"Fair use\").", "multimediaviewer-text-embed-credit-text-tbs": "Credit text, used when generating plain text to attribute an image.\n\nWhich one of the multimediaviewer-text-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the author\n* $3 - name of the website/institution which was the direct source for this image. This parameter is usually an URL.\n{{Related|Multimediaviewer-embed-credit-text}}", "multimediaviewer-text-embed-credit-text-tbl": "Credit text, used when generating plain text to attribute an image.\n\nWhich one of the multimediaviewer-text-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the author\n* $3 - name of the license\n{{Related|Multimediaviewer-embed-credit-text}}", + "multimediaviewer-text-embed-credit-text-tbl-nonfree": "Like {{msg-mw|multimediaviewer-text-embed-credit-text-tbl}}, but for non-free images (where $3 is typically not a license name but something like \"Fair use\").", "multimediaviewer-text-embed-credit-text-tb": "Credit text, used when generating plain text to attribute an image.\n\nWhich one of the multimediaviewer-text-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the author\n{{Related|Multimediaviewer-embed-credit-text}}", "multimediaviewer-text-embed-credit-text-ts": "Credit text, used when generating plain text to attribute an image.\n\nWhich one of the multimediaviewer-text-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the website/institution which was the direct source for this image. This parameter is usually an URL.\n{{Related|Multimediaviewer-embed-credit-text}}", "multimediaviewer-text-embed-credit-text-tl": "Credit text, used when generating plain text to attribute an image.\n\nWhich one of the multimediaviewer-text-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the license\n{{Related|Multimediaviewer-embed-credit-text}}", + "multimediaviewer-text-embed-credit-text-tl-nonfree": "Like {{msg-mw|multimediaviewer-text-embed-credit-text-tl}}, but for non-free images (where $2 is typically not a license name but something like \"Fair use\").", "multimediaviewer-text-embed-credit-text-t": "Credit text, used when generating plain text to attribute an image.\n\nWhich one of the multimediaviewer-text-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n{{Related|Multimediaviewer-embed-credit-text}}", "multimediaviewer-html-embed-credit-text-tbls": "Credit text, used when generating HTML to reuse an image.\n\nWhich one of the multimediaviewer-html-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the author\n* $3 - name of the license\n* $4 - name of the website/institution which was the direct source for this image\nEach of the parameters could be either plain text or a link.\n{{Related|Multimediaviewer-embed-credit-text}}", + "multimediaviewer-html-embed-credit-text-tbls-nonfree": "Like {{msg-mw|multimediaviewer-html-embed-credit-text-tbls}}, but for non-free images (where $3 is typically not a license name but something like \"Fair use\").", "multimediaviewer-html-embed-credit-text-tls": "Credit text, used when generating HTML to reuse an image.\n\nWhich one of the multimediaviewer-html-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the license\n* $3 - name of the website/institution which was the direct source for this image\nEach of the parameters could be either plain text or a link.\n{{Related|Multimediaviewer-embed-credit-text}}", + "multimediaviewer-html-embed-credit-text-tls-nonfree": "Like {{msg-mw|multimediaviewer-html-embed-credit-text-tls}}, but for non-free images (where $2 is typically not a license name but something like \"Fair use\").", "multimediaviewer-html-embed-credit-text-tbs": "Credit text, used when generating HTML to reuse an image.\n\nWhich one of the multimediaviewer-html-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the author\n* $3 - name of the website/institution which was the direct source for this image\nEach of the parameters could be either plain text or a link.\n{{Related|Multimediaviewer-embed-credit-text}}", "multimediaviewer-html-embed-credit-text-tbl": "Credit text, used when generating HTML to reuse an image.\n\nWhich one of the multimediaviewer-html-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the author\n* $3 - name of the license\nEach of the parameters could be either plain text or a link.\n{{Related|Multimediaviewer-embed-credit-text}}", + "multimediaviewer-html-embed-credit-text-tbl-nonfree": "Like {{msg-mw|multimediaviewer-html-embed-credit-text-tbl}}, but for non-free images (where $3 is typically not a license name but something like \"Fair use\").", "multimediaviewer-html-embed-credit-text-tb": "Credit text, used when generating HTML to reuse an image.\n\nWhich one of the multimediaviewer-html-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the author\nEach of the parameters could be either plain text or a link.\n{{Related|Multimediaviewer-embed-credit-text}}", "multimediaviewer-html-embed-credit-text-ts": "Credit text, used when generating HTML to reuse an image.\n\nWhich one of the multimediaviewer-html-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the website/institution which was the direct source for this image\nEach of the parameters could be either plain text or a link.\n{{Related|Multimediaviewer-embed-credit-text}}", "multimediaviewer-html-embed-credit-text-tl": "Credit text, used when generating HTML to reuse an image.\n\nWhich one of the multimediaviewer-html-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the license\nEach of the parameters could be either plain text or a link.\n{{Related|Multimediaviewer-embed-credit-text}}", + "multimediaviewer-html-embed-credit-text-tl-nonfree": "Like {{msg-mw|multimediaviewer-html-embed-credit-text-tl}}, but for non-free images (where $2 is typically not a license name but something like \"Fair use\").", "multimediaviewer-html-embed-credit-text-t": "Credit text, used when generating HTML to reuse an image.\n\nWhich one of the multimediaviewer-html-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\nEach of the parameters could be either plain text or a link.\n{{Related|Multimediaviewer-embed-credit-text}}", "multimediaviewer-embed-byline": "Byline (author credit) text, used when generating wikitext/HTML to reuse the image. $1 is author name.\n{{Identical|By}}", "multimediaviewer-embed-license": "License information, used when generating wikitext/HTML to reuse the image. $1 is the license name.", + "multimediaviewer-embed-license-nonfree": "Like {{msg-mw|multimediaviewer-embed-license}}, but for non-free images (where $1 is typically not a license name but something like \"Fair use\").", "multimediaviewer-embed-via": "Source information (e.g. \"via Flickr\"), used when generating wikitext/HTML to reuse the image.\n\nParameters:\n* $1 - source (probably a website or institution name)", "multimediaviewer-default-embed-dimensions": "Text of size selector option which will generate wikitext for a thumbnail without explicit size.", "multimediaviewer-original-embed-dimensions": "Text of size selector option which will generate wikitext for a thumbnail with the original (full) size.\n* $1 - thumbnail dimensions, defined by the following message:\n** {{msg-mw|Multimediaviewer-embed-dimensions}}", @@ -114,7 +123,8 @@ "multimediaviewer-credit-popup-text": "Tooltip that identifies the author and source field of a file in the media viewer. If the author name or the source is very long, {{msg-mw|multimediaviewer-credit-popup-text-more}} will be shown instead.", "multimediaviewer-title-popup-text-more": "Tooltip that identifies the description of a file in the media viewer. Used instead of {{msg-mw|multimediaviewer-title-popup-text}} when the name is too long and has to be truncated (and will be untruncated on click).", "multimediaviewer-credit-popup-text-more": "Tooltip that identifies the author and source of a file in the media viewer. Used instead of {{msg-mw|multimediaviewer-credit-popup-text}} when one or both of the author and source is too long and has to be truncated (and will be untruncated on click).", - "multimediaviewer-download-attribution-cta-header": "Header for telling the user that the author of an image must be attributed, during a download action.", + "multimediaviewer-download-attribution-cta-header": "Header for telling the user that the author of an image must be attributed, during a download action. See also {{msg-mw|multimediaviewer-download-optional-attribution-cta-header}}.", + "multimediaviewer-download-optional-attribution-cta-header": "Header for inviting the user to attribute author of the image during a download action. This is used for images where attribution is not a legal requirement. See also {{msg-mw|multimediaviewer-download-attribution-cta-header}}.", "multimediaviewer-download-attribution-cta": "Call to action for a user to find out how to attribute the author of an image.", "multimediaviewer-attr-plain": "Label for a button that lets the user pick plain text as an output format.", "multimediaviewer-attr-html": "Label for a button that lets the user pick HTML as an output format.", diff --git a/resources/mmv/mmv.EmbedFileFormatter.js b/resources/mmv/mmv.EmbedFileFormatter.js index 4db4bcf..e815d79 100644 --- a/resources/mmv/mmv.EmbedFileFormatter.js +++ b/resources/mmv/mmv.EmbedFileFormatter.js @@ -127,11 +127,15 @@ } if ( info.imageInfo.license ) { creditParams[0] += 'l'; - creditParams.push( this.htmlUtils.htmlToText( info.imageInfo.license.longName ) ); + creditParams.push( this.htmlUtils.htmlToText( info.imageInfo.license.longName || '' ) ); } creditParams[0] += 's'; creditParams.push( info.repoInfo.displayName + ' - ' + titleUrl ); + + if ( info.imageInfo.license && !info.imageInfo.license.isFree() ) { + creditParams[0] += '-nonfree'; + } creditText = mw.message.apply( mw, creditParams ).plain(); @@ -167,6 +171,10 @@ creditParams[0] += 's'; creditParams.push( this.getSiteLink( info ) ); + if ( info.imageInfo.license && !info.imageInfo.license.isFree() ) { + creditParams[0] += '-nonfree'; + } + creditText = mw.message.apply( mw, creditParams ).plain(); return creditText; diff --git a/resources/mmv/model/mmv.model.Image.js b/resources/mmv/model/mmv.model.Image.js index 8781aa5..304702c 100644 --- a/resources/mmv/model/mmv.model.Image.js +++ b/resources/mmv/model/mmv.model.Image.js @@ -153,15 +153,7 @@ source = this.parseExtmeta( extmeta.Credit, 'string' ); author = this.parseExtmeta( extmeta.Artist, 'string' ); - if ( extmeta.LicenseShortName ) { - license = new mw.mmv.model.License( - this.parseExtmeta( extmeta.LicenseShortName, 'string' ), - this.parseExtmeta( extmeta.License, 'string' ), - this.parseExtmeta( extmeta.UsageTerms, 'string' ), - this.parseExtmeta( extmeta.LicenseUrl, 'string' ) - ); - } - + license = this.newLicenseFromImageInfo( extmeta ); permission = this.parseExtmeta( extmeta.Permission, 'string' ); latitude = this.parseExtmeta( extmeta.GPSLatitude, 'float' ); @@ -205,10 +197,34 @@ }; /** + * Constructs a new License object out of an object containing + * imageinfo data from an API response. + * @static + * @param {Object} extmeta the extmeta array of the imageinfo data + * @returns {mw.mmv.model.License|undefined} + */ + Image.newLicenseFromImageInfo = function ( extmeta ) { + var license; + + if ( extmeta.LicenseShortName ) { + license = new mw.mmv.model.License( + this.parseExtmeta( extmeta.LicenseShortName, 'string' ), + this.parseExtmeta( extmeta.License, 'string' ), + this.parseExtmeta( extmeta.UsageTerms, 'string' ), + this.parseExtmeta( extmeta.LicenseUrl, 'string' ), + this.parseExtmeta( extmeta.AttributionRequired, 'boolean' ), + this.parseExtmeta( extmeta.NonFree, 'boolean' ) + ); + } + + return license; + }; + + /** * Reads and parses a value from the imageinfo API extmetadata field. * @param {Array} data - * @param {string} type one of 'plaintext', 'string', 'float', 'list' - * @return {string|number|Array} value or undefined if it is missing + * @param {string} type one of 'plaintext', 'string', 'float', 'boolean', 'list' + * @return {string|number|boolean|Array} value or undefined if it is missing */ Image.parseExtmeta = function ( data, type ) { var value = data && data.value; @@ -220,6 +236,15 @@ return value.toString(); } else if ( type === 'float' ) { return parseFloat( value ); + } else if ( type === 'boolean' ) { + value = value.toString().toLowerCase().replace( /^\s+|\s+$/g, '' ); + if ( value in { '1': null, 'yes': null, 'true': null } ) { + return true; + } else if ( value in { '0': null, 'no': null, 'false': null } ) { + return false; + } else { + return undefined; + } } else if ( type === 'list' ) { return value === '' ? [] : value.split( '|' ); } else { diff --git a/resources/mmv/model/mmv.model.License.js b/resources/mmv/model/mmv.model.License.js index 8e076e8..df04b47 100644 --- a/resources/mmv/model/mmv.model.License.js +++ b/resources/mmv/model/mmv.model.License.js @@ -26,13 +26,17 @@ * @param {string} [internalName] see {@link #internalName} * @param {string} [longName] see {@link #longName} * @param {string} [deedUrl] see {@link #deedUrl} + * @param {boolean} [attributionRequired] see {@link #attributionRequired} + * @param {boolean} [nonFree] see {@link #nonFree} * @constructor */ function License( shortName, internalName, longName, - deedUrl + deedUrl, + attributionRequired, + nonFree ) { if ( !shortName ) { throw 'mw.mmv.model.License: shortName is required'; @@ -49,6 +53,12 @@ /** @property {string} deedUrl URL to the description of the license (e.g. the CC deed) */ this.deedUrl = deedUrl; + + /** @property {boolean} attributionRequired does the author need to be attributed on reuse? */ + this.attributionRequired = attributionRequired; + + /** @property {boolean} nonFree is this a non-free license? */ + this.nonFree = nonFree; /** @property {mw.mmv.HtmlUtils} htmlUtils - */ this.htmlUtils = new mw.mmv.HtmlUtils(); @@ -72,6 +82,24 @@ }; /** + * Check whether this is a free license. + * @return {boolean} + */ + LP.isFree = function () { + // licenses with missing nonfree information are assumed free + return !this.nonFree; + }; + + /** + * Check whether reusers need to attribute the author + * @return {boolean} + */ + LP.needsAttribution = function () { + // to be on the safe side, if the attribution required flag is not set, it is assumed to be true + return !this.isPd() && this.attributionRequired !== false; + }; + + /** * Returns the short name of the license: * - if we have interface messages for this license (basically just CC and PD), use those * - otherwise use the short name from the license template (might or might not be translated diff --git a/resources/mmv/provider/mmv.provider.ImageInfo.js b/resources/mmv/provider/mmv.provider.ImageInfo.js index 294db0a..fc05b21 100644 --- a/resources/mmv/provider/mmv.provider.ImageInfo.js +++ b/resources/mmv/provider/mmv.provider.ImageInfo.js @@ -69,7 +69,9 @@ 'Artist', 'GPSLatitude', 'GPSLongitude', - 'Permission' + 'Permission', + 'AttributionRequired', + 'NonFree' ].join('|'); /** diff --git a/resources/mmv/ui/mmv.ui.download.pane.js b/resources/mmv/ui/mmv.ui.download.pane.js index 7d635d1..44d45b5 100644 --- a/resources/mmv/ui/mmv.ui.download.pane.js +++ b/resources/mmv/ui/mmv.ui.download.pane.js @@ -180,34 +180,36 @@ } } ); + this.$attributionCtaHeader = $( '<p>' ) + .addClass( 'mw-mmv-download-attribution-cta-header' ) + .text( mw.message( 'multimediaviewer-download-attribution-cta-header' ).text() ); this.$attributionCta = $( '<div>' ) .addClass( 'mw-mmv-download-attribution-cta' ) .append( - $( '<p>' ) - .addClass( 'mw-mmv-download-attribution-cta-header' ) - .text( mw.message( 'multimediaviewer-download-attribution-cta-header' ).text() ), - $( '<p>' ) + this.$attributionCtaHeader, + $( '<p>' ) .addClass( 'mw-mmv-download-attribution-cta-invite' ) .text( mw.message( 'multimediaviewer-download-attribution-cta' ).text() ) - ) - .appendTo( this.$attributionSection ); + ) + .appendTo( this.$attributionSection ); + this.$attributionHowHeader = $( '<p>' ) + .addClass( 'mw-mmv-download-attribution-how-header' ) + .text( mw.message( 'multimediaviewer-download-attribution-cta-header' ).text() ); this.$attributionHow = $( '<div>' ) .addClass( 'mw-mmv-download-attribution-how' ) .append( - $( '<p>' ) - .addClass( 'mw-mmv-download-attribution-how-header' ) - .text( mw.message( 'multimediaviewer-download-attribution-cta-header' ).text() ), - attributionInput.$element, - attributionSwitch.$element, - $( '<p>' ) - .addClass( 'mw-mmv-download-attribution-close-button' ) - .click( function ( e ) { - dl.$attributionSection.addClass( 'mw-mmv-download-attribution-collapsed' ); - e.stopPropagation(); - } ) - .text( ' ' ) - ) + this.$attributionHowHeader, + attributionInput.$element, + attributionSwitch.$element, + $( '<p>' ) + .addClass( 'mw-mmv-download-attribution-close-button' ) + .click( function ( e ) { + dl.$attributionSection.addClass( 'mw-mmv-download-attribution-collapsed' ); + e.stopPropagation(); + } ) + .text( ' ' ) + ) .appendTo( this.$attributionSection ); this.attributionInput = attributionInput; @@ -346,7 +348,9 @@ * @param {mw.mmv.model.Repo} repo */ DP.set = function ( image, repo ) { - var sizeOptions = this.downloadSizeMenu.getMenu().getItems(), + var attributionCtaMessage, + license = image && image.license, + sizeOptions = this.downloadSizeMenu.getMenu().getItems(), sizes = this.utils.getPossibleImageSizesForHtml( image.width, image.height ); this.image = image; @@ -364,6 +368,12 @@ if ( image && repo ) { this.setAttributionText( new mw.mmv.model.EmbedFileInfo( image, repo ) ); } + + attributionCtaMessage = ( license && license.needsAttribution() ) ? + 'multimediaviewer-download-attribution-cta-header' + : 'multimediaviewer-download-optional-attribution-cta-header'; + this.$attributionCtaHeader.text( mw.message( attributionCtaMessage ).text() ); + this.$attributionHowHeader.text( mw.message( attributionCtaMessage ).text() ); }; /** diff --git a/tests/qunit/mmv/mmv.EmbedFileFormatter.test.js b/tests/qunit/mmv/mmv.EmbedFileFormatter.test.js index 6ea9a4c..61e342e 100644 --- a/tests/qunit/mmv/mmv.EmbedFileFormatter.test.js +++ b/tests/qunit/mmv/mmv.EmbedFileFormatter.test.js @@ -212,7 +212,8 @@ getNameText: function () { return 'Image Title'; } }, license: { - longName: 'Do What the Fuck You Want Public License' + longName: 'Do What the Fuck You Want Public License', + isFree: this.sandbox.stub().returns( true ) } } } ); diff --git a/tests/qunit/mmv/model/mmv.model.Image.test.js b/tests/qunit/mmv/model/mmv.model.Image.test.js index 163c0b1..e9a4f1e 100644 --- a/tests/qunit/mmv/model/mmv.model.Image.test.js +++ b/tests/qunit/mmv/model/mmv.model.Image.test.js @@ -87,12 +87,14 @@ assert.strictEqual( secondImageData.hasCoords(), true, 'Coordinates present means hasCoords returns true.' ); } ); - QUnit.test( 'parseExtmeta()', 9, function ( assert ) { + QUnit.test( 'parseExtmeta()', 11, function ( assert ) { var Image = mw.mmv.model.Image, stringData = { value: 'foo' }, plaintextData = { value: 'fo<b>o</b>' }, floatData = { value: 1.23 }, floatStringData = { value: '1.23' }, + booleanData = { value: 'yes' }, + wrongBooleanData = { value: 'blah' }, listDataEmpty = {value: '' }, listDataSingle = {value: 'foo' }, listDataMultiple = {value: 'foo|bar|baz' }, @@ -106,6 +108,10 @@ 'Extmeta float parsed correctly.' ); assert.strictEqual( Image.parseExtmeta( floatStringData, 'float' ), 1.23, 'Extmeta float string parsed correctly.' ); + assert.strictEqual( Image.parseExtmeta( booleanData, 'boolean' ), true, + 'Extmeta boolean string parsed correctly.' ); + assert.strictEqual( Image.parseExtmeta( wrongBooleanData, 'boolean' ), undefined, + 'Extmeta boolean string with error ignored.' ); assert.deepEqual( Image.parseExtmeta( listDataEmpty, 'list' ), [], 'Extmeta empty list parsed correctly.' ); assert.deepEqual( Image.parseExtmeta( listDataSingle, 'list' ), ['foo'], diff --git a/tests/qunit/mmv/model/mmv.model.License.test.js b/tests/qunit/mmv/model/mmv.model.License.test.js index 8f3393e..074bbed 100644 --- a/tests/qunit/mmv/model/mmv.model.License.test.js +++ b/tests/qunit/mmv/model/mmv.model.License.test.js @@ -132,4 +132,30 @@ license = new mw.mmv.model.License( 'MIT' ); assert.strictEqual( license.isPd(), false, 'Non-PD license with no internal name not recognized' ); } ); + + QUnit.test( 'isFree()', 2, function( assert ) { + var license; + + license = new mw.mmv.model.License( 'CC-BY-SA-2.0', 'cc-by-sa-2.0', + 'Creative Commons Attribution - ShareAlike 2.0', + 'http://creativecommons.org/licenses/by-sa/2.0/' ); + assert.strictEqual( license.isFree(), true, 'Licenses default to free' ); + + license = new mw.mmv.model.License( 'Fair use', 'fairuse', + 'Fair use', undefined, undefined, true ); + assert.strictEqual( license.isFree(), false, 'Non-free flag handled correctly' ); + } ); + + QUnit.test( 'needsAttribution()', 2, function( assert ) { + var license; + + license = new mw.mmv.model.License( 'CC-BY-SA-2.0', 'cc-by-sa-2.0', + 'Creative Commons Attribution - ShareAlike 2.0', + 'http://creativecommons.org/licenses/by-sa/2.0/' ); + assert.strictEqual( license.needsAttribution(), true, 'Licenses assumed to need attribution by default' ); + + license = new mw.mmv.model.License( 'Public Domain', 'pd', + 'Public Domain for lack of originality', false ); + assert.strictEqual( license.needsAttribution(), false, 'Attribution required flag handled correctly' ); + } ); }( mediaWiki, jQuery ) ); diff --git a/tests/qunit/mmv/provider/mmv.provider.ImageInfo.test.js b/tests/qunit/mmv/provider/mmv.provider.ImageInfo.test.js index 346b277..dfb8e16 100644 --- a/tests/qunit/mmv/provider/mmv.provider.ImageInfo.test.js +++ b/tests/qunit/mmv/provider/mmv.provider.ImageInfo.test.js @@ -25,7 +25,7 @@ assert.ok( imageInfoProvider ); } ); - QUnit.asyncTest( 'ImageInfo get test', 23, function ( assert ) { + QUnit.asyncTest( 'ImageInfo get test', 25, function ( assert ) { var apiCallCount = 0, api = { get: function() { apiCallCount++; @@ -104,6 +104,14 @@ Permission: { value: 'Do not use. Ever.', source: 'commons-desc-page' + }, + AttributionRequired: { + value: 'no', + source: 'commons-desc-page' + }, + NonFree: { + value: 'yes', + source: 'commons-desc-page' } }, mime: 'image/jpeg', @@ -138,6 +146,8 @@ assert.strictEqual( image.license.internalName, 'cc0', 'license internal name is set correctly' ); assert.strictEqual( image.license.longName, 'Creative Commons Public Domain Dedication', 'license long name is set correctly' ); assert.strictEqual( image.license.deedUrl, 'http://creativecommons.org/publicdomain/zero/1.0/', 'license URL is set correctly' ); + assert.strictEqual( image.license.attributionRequired, false, 'Attribution required flag is honored' ); + assert.strictEqual( image.license.nonFree, true, 'Non-free flag is honored' ); assert.strictEqual( image.permission, 'Do not use. Ever.', 'permission is set correctly' ); assert.strictEqual( image.latitude, 90, 'latitude is set correctly' ); assert.strictEqual( image.longitude, 180, 'longitude is set correctly' ); diff --git a/tests/qunit/mmv/ui/mmv.ui.reuse.utils.test.js b/tests/qunit/mmv/ui/mmv.ui.reuse.utils.test.js index b1968cf..e0d1608 100644 --- a/tests/qunit/mmv/ui/mmv.ui.reuse.utils.test.js +++ b/tests/qunit/mmv/ui/mmv.ui.reuse.utils.test.js @@ -16,7 +16,7 @@ */ ( function ( mw, $ ) { - QUnit.module( 'mw.mmv.ui.utils', QUnit.newMwEnvironment() ); + QUnit.module( 'mw.mmv.ui.reuse.utils', QUnit.newMwEnvironment() ); QUnit.test( 'Sanity test, object creation and UI construction', 1, function ( assert ) { var utils = new mw.mmv.ui.Utils(); -- To view, visit https://gerrit.wikimedia.org/r/175573 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I84e0094559e5b438fcb33b8511dc0184435c1a37 Gerrit-PatchSet: 6 Gerrit-Project: mediawiki/extensions/MultimediaViewer Gerrit-Branch: master Gerrit-Owner: Gergő Tisza <gti...@wikimedia.org> Gerrit-Reviewer: Gergő Tisza <gti...@wikimedia.org> Gerrit-Reviewer: Gilles <gdu...@wikimedia.org> Gerrit-Reviewer: MarkTraceur <mtrac...@member.fsf.org> Gerrit-Reviewer: Siebrand <siebr...@kitano.nl> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits