Gergő Tisza has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/178141

Change subject: Display warnings for licence/attribution problems
......................................................................

Display warnings for licence/attribution problems

Bug: T76030
Bug: T71389
Bug: T71557
Change-Id: I38c1548a0de6cfd3a48db7efd7502a99f168d4a5
---
M MultimediaViewer.php
M i18n/en.json
M i18n/qqq.json
M resources/mmv/model/mmv.model.Image.js
M resources/mmv/provider/mmv.provider.ImageInfo.js
M resources/mmv/ui/mmv.ui.dialog.js
M resources/mmv/ui/mmv.ui.download.dialog.js
M resources/mmv/ui/mmv.ui.reuse.dialog.js
M tests/qunit/mmv/mmv.EmbedFileFormatter.test.js
M tests/qunit/mmv/model/mmv.model.Image.test.js
M tests/qunit/mmv/provider/mmv.provider.ImageInfo.test.js
11 files changed, 100 insertions(+), 15 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MultimediaViewer 
refs/changes/41/178141/1

diff --git a/MultimediaViewer.php b/MultimediaViewer.php
index e8f8628..aa81e45 100644
--- a/MultimediaViewer.php
+++ b/MultimediaViewer.php
@@ -389,6 +389,14 @@
                        'mmv/ui/mmv.ui.dialog.less',
                ),
 
+               'messages' => array(
+                       'multimediaviewer-reuse-warning-deletion',
+                       'multimediaviewer-reuse-warning-nonfree',
+                       'multimediaviewer-reuse-warning-noattribution',
+                       'multimediaviewer-reuse-warning-link',
+                       'multimediaviewer-reuse-warning-generic',
+               ),
+
                'dependencies' => array(
                        'mmv.ui',
                        'oojs',
diff --git a/i18n/en.json b/i18n/en.json
index 74d3c4e..454fe6d 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -121,6 +121,11 @@
        "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-reuse-warning-deletion": "This file is considered for 
deletion.",
+       "multimediaviewer-reuse-warning-nonfree": "This file is not under a 
free license.",
+       "multimediaviewer-reuse-warning-noattribution": "This file is has no 
attribution information.",
+       "multimediaviewer-reuse-warning-link": "its details",
+       "multimediaviewer-reuse-warning-generic": "Check $1 before using it.",
        "multimediaviewer-attr-plain": "Plain",
        "multimediaviewer-attr-html": "HTML",
        "multimediaviewer-options-tooltip": "Enable or disable Media Viewer",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 172e8cf..59379a0 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -127,6 +127,11 @@
        "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-reuse-warning-deletion": "Warning message shown in 
the share/embed/download panels for files tagged with a deletion template. 
Followed by {{msg-mw|multimediaviewer-reuse-warning-generic}}.",
+       "multimediaviewer-reuse-warning-nonfree": "Warning message shown in the 
share/embed/download panels for files under a nonfree license / copyright tag. 
Followed by {{msg-mw|multimediaviewer-reuse-warning-generic}}.",
+       "multimediaviewer-reuse-warning-noattribution": "Warning message shown 
in the share/embed/download panels for files which have no machine-readable 
author or source. Followed by 
{{msg-mw|multimediaviewer-reuse-warning-generic}}.",
+       "multimediaviewer-reuse-warning-link": "Text of the link to the file 
page in dialog warning messages.",
+       "multimediaviewer-reuse-warning-generic": "Generic message at the end 
of every warning. $1 is {{msg-mw|multimediaviewer-reuse-warning-link}}.",
        "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.",
        "multimediaviewer-options-tooltip": "Tooltip for a button that opens a 
panel for enabling or disabling the media viewer.",
diff --git a/resources/mmv/model/mmv.model.Image.js 
b/resources/mmv/model/mmv.model.Image.js
index c5c3b06..218b494 100644
--- a/resources/mmv/model/mmv.model.Image.js
+++ b/resources/mmv/model/mmv.model.Image.js
@@ -39,8 +39,10 @@
         * @param {string} source
         * @param {string} author
         * @param {number} authorCount
+        * @param {string} attribution
         * @param {mw.mmv.model.License} license
         * @param {string} permission
+        * @param {string} deletionReason
         * @param {number} latitude
         * @param {number} longitude
         */
@@ -62,8 +64,10 @@
                        source,
                        author,
                        authorCount,
+                       attribution,
                        license,
                        permission,
+                       deletionReason,
                        latitude,
                        longitude
        ) {
@@ -119,11 +123,17 @@
                 *   number of templates with author fields, so might be less 
than the number of actual authors. */
                this.authorCount = authorCount;
 
+               /** @property {string} attribution custom attribution text, if 
any */
+               this.attribution = attribution;
+
                /** @property {mw.mmv.model.License} license The license under 
which the image is distributed */
                this.license = license;
 
                /** @property {string} additional license conditions by the 
author (note that this is usually a big ugly HTML blob) */
                this.permission = permission;
+
+               /** @property {string|null} reason for pending deletion, null 
if image is not about to be deleted */
+               this.deletionReason = deletionReason;
 
                /** @property {number} latitude The latitude of the place where 
the image was created */
                this.latitude = latitude;
@@ -150,7 +160,7 @@
         */
        Image.newFromImageInfo = function ( title, imageInfo ) {
                var name, uploadDateTime, anonymizedUploadDateTime, 
creationDateTime, imageData,
-                       description, source, author, authorCount, license, 
permission,
+                       description, source, author, authorCount, attribution, 
license, permission, deletionReason,
                        latitude, longitude,
                        innerInfo = imageInfo.imageinfo[0],
                        extmeta = innerInfo.extmetadata;
@@ -172,10 +182,11 @@
                        source = this.parseExtmeta( extmeta.Credit, 'string' );
                        author = this.parseExtmeta( extmeta.Artist, 'string' );
                        authorCount = this.parseExtmeta( extmeta.AuthorCount, 
'integer' );
-
+                       attribution = this.parseExtmeta( extmeta.Attribution, 
'string' );
 
                        license = this.newLicenseFromImageInfo( extmeta );
                        permission = this.parseExtmeta( extmeta.Permission, 
'string' );
+                       deletionReason = this.parseExtmeta( 
extmeta.DeletionReason, 'string' );
 
                        latitude = this.parseExtmeta( extmeta.GPSLatitude, 
'float' );
                        longitude = this.parseExtmeta( extmeta.GPSLongitude, 
'float' );
@@ -204,8 +215,10 @@
                        source,
                        author,
                        authorCount,
+                       attribution,
                        license,
                        permission,
+                       deletionReason,
                        latitude,
                        longitude
                );
diff --git a/resources/mmv/provider/mmv.provider.ImageInfo.js 
b/resources/mmv/provider/mmv.provider.ImageInfo.js
index 44f6a58..38962b0 100644
--- a/resources/mmv/provider/mmv.provider.ImageInfo.js
+++ b/resources/mmv/provider/mmv.provider.ImageInfo.js
@@ -68,11 +68,13 @@
                'Credit',
                'Artist',
                'AuthorCount',
+               'Attribution',
                'GPSLatitude',
                'GPSLongitude',
                'Permission',
                'AttributionRequired',
-               'NonFree'
+               'NonFree',
+               'DeletionReason'
        ].join('|');
 
        /**
diff --git a/resources/mmv/ui/mmv.ui.dialog.js 
b/resources/mmv/ui/mmv.ui.dialog.js
index ef928a9..b065f16 100644
--- a/resources/mmv/ui/mmv.ui.dialog.js
+++ b/resources/mmv/ui/mmv.ui.dialog.js
@@ -75,6 +75,10 @@
                this.$warning = $( '<div>' )
                        .addClass( 'mw-mmv-dialog-warning' )
                        .hide()
+                       .click( function( e ) {
+                               // prevent other click handlers such as the 
download CTA from intercepting clicks at the warning
+                               e.stopPropagation();
+                       } )
                        .appendTo( this.$dialog );
        };
 
@@ -204,5 +208,39 @@
                this.$dialog.removeClass( 'mw-mmv-warning-visible' );
        };
 
+       /**
+        * @private
+        * @param {string} key
+        * @param {string} filePageUrl
+        * @return {string[]}
+        */
+       DP.composeWarning = function ( key, filePageUrl ) {
+               var link = $( '<a>' )
+                       .attr( 'href', filePageUrl )
+                       .text( mw.message( 
'multimediaviewer-reuse-warning-link' ).plain() )
+                       .get( 0 ).outerHTML;
+
+               return [
+                       mw.message( 'multimediaviewer-reuse-warning-' + key 
).plain(),
+                       '<br />',
+                       mw.message( 'multimediaviewer-reuse-warning-generic', 
link ).plain()
+               ];
+       };
+
+       /**
+        * @param {mw.mmv.model.Image} image
+        */
+       DP.setWarning = function ( image ) {
+               if ( image.deletionReason ) {
+                       this.addWarning( this.composeWarning( 'deletion', 
image.descriptionUrl ) );
+               } else if ( !image.license || image.license.needsAttribution() 
&& !image.author && ! image.attribution ) {
+                       this.addWarning( this.composeWarning( 'noattribution', 
image.descriptionUrl ) );
+               } else if ( !image.license.isFree() ) {
+                       this.addWarning( this.composeWarning( 'nonfree', 
image.descriptionUrl ) );
+               } else {
+                       this.clearWarning();
+               }
+       };
+
        mw.mmv.ui.Dialog = Dialog;
 }( mediaWiki, jQuery, OO ) );
diff --git a/resources/mmv/ui/mmv.ui.download.dialog.js 
b/resources/mmv/ui/mmv.ui.download.dialog.js
index 0f26f0a..5675134 100644
--- a/resources/mmv/ui/mmv.ui.download.dialog.js
+++ b/resources/mmv/ui/mmv.ui.download.dialog.js
@@ -73,7 +73,7 @@
        DP.set = function ( image, repo ) {
                if ( this.download ) {
                        this.download.set( image, repo );
-                       this.clearWarning();
+                       this.setWarning( image );
                } else {
                        this.setValues = {
                                image: image,
@@ -98,7 +98,7 @@
 
                if ( this.setValues ) {
                        this.download.set( this.setValues.image, 
this.setValues.repo );
-                       this.clearWarning();
+                       this.setWarning( this.setValues.image );
                        this.setValues = undefined;
                }
 
diff --git a/resources/mmv/ui/mmv.ui.reuse.dialog.js 
b/resources/mmv/ui/mmv.ui.reuse.dialog.js
index 343bd8e..d960019 100644
--- a/resources/mmv/ui/mmv.ui.reuse.dialog.js
+++ b/resources/mmv/ui/mmv.ui.reuse.dialog.js
@@ -100,8 +100,8 @@
                        // This is a delayed set() for the elements we've just 
created on demand
                        this.tabs.share.set.apply( this.tabs.share, 
this.tabsSetValues.share );
                        this.tabs.embed.set.apply( this.tabs.embed, 
this.tabsSetValues.embed );
+                       this.setWarning( this.tabsSetValues.share[0] );
                        this.tabsSetValues = undefined;
-                       this.clearWarning();
                }
        };
 
@@ -201,7 +201,7 @@
                if ( this.tabs !== null ) {
                        this.tabs.share.set( image );
                        this.tabs.embed.set( image, repo, caption );
-                       this.clearWarning();
+                       this.setWarning( image );
                } else {
                        this.tabsSetValues = {
                                share : [ image ],
diff --git a/tests/qunit/mmv/mmv.EmbedFileFormatter.test.js 
b/tests/qunit/mmv/mmv.EmbedFileFormatter.test.js
index b7875a0..e8fedc6 100644
--- a/tests/qunit/mmv/mmv.EmbedFileFormatter.test.js
+++ b/tests/qunit/mmv/mmv.EmbedFileFormatter.test.js
@@ -6,7 +6,7 @@
                                options.licenseInternalName, 
options.licenseLongName, options.licenseUrl ) : undefined,
                        imageInfo = new mw.mmv.model.Image( options.title, 
options.title.getNameText(), undefined,
                                undefined, undefined, undefined, 
options.imgUrl, options.filePageUrl, 'repo', undefined,
-                               undefined, undefined, undefined, undefined, 
options.source, options.author, options.authorCount, license ),
+                               undefined, undefined, undefined, undefined, 
options.source, options.author, options.authorCount, undefined, license ),
                        repoInfo = { displayName: options.siteName, getSiteLink:
                                function () { return options.siteUrl; } };
 
diff --git a/tests/qunit/mmv/model/mmv.model.Image.test.js 
b/tests/qunit/mmv/model/mmv.model.Image.test.js
index 7686ffd..aee6680 100644
--- a/tests/qunit/mmv/model/mmv.model.Image.test.js
+++ b/tests/qunit/mmv/model/mmv.model.Image.test.js
@@ -18,7 +18,7 @@
 ( function( mw ) {
        QUnit.module( 'mmv.model.Image', QUnit.newMwEnvironment() );
 
-       QUnit.test( 'Image model constructor sanity check', 22, function ( 
assert ) {
+       QUnit.test( 'Image model constructor sanity check', 24, function ( 
assert ) {
                var
                        title = mw.Title.newFromText( 'File:Foobar.jpg' ),
                        name = 'Foo bar',
@@ -37,14 +37,16 @@
                        source = 'WMF',
                        author = 'Ryan Kaldari',
                        authorCount = 1,
+                       attribution = '(C) R.K.',
                        permission = 'only use for good, not evil',
+                       deletionReason = 'poor quality',
                        license = new mw.mmv.model.License( 'cc0' ),
                        latitude = 39.12381283,
                        longitude = 100.983829,
                        imageData = new mw.mmv.model.Image(
                                title, name, size, width, height, mime, url,
                                descurl, repo, user, datetime, anondatetime, 
origdatetime,
-                               description, source, author, authorCount, 
license, permission,
+                               description, source, author, authorCount, 
attribution, license, permission, deletionReason,
                                latitude, longitude );
 
                assert.strictEqual( imageData.title, title, 'Title is set 
correctly' );
@@ -64,8 +66,10 @@
                assert.strictEqual( imageData.source, source, 'Source is set 
correctly' );
                assert.strictEqual( imageData.author, author, 'Author is set 
correctly' );
                assert.strictEqual( imageData.authorCount, authorCount, 'Author 
is set correctly' );
+               assert.strictEqual( imageData.attribution, attribution, 
'Attribution is set correctly' );
                assert.strictEqual( imageData.license, license, 'License is set 
correctly' );
                assert.strictEqual( imageData.permission, permission, 
'Permission is set correctly' );
+               assert.strictEqual( imageData.deletionReason, deletionReason, 
'Deletion reason is set correctly' );
                assert.strictEqual( imageData.latitude, latitude, 'Latitude is 
set correctly' );
                assert.strictEqual( imageData.longitude, longitude, 'Longitude 
is set correctly' );
                assert.ok( imageData.thumbUrls, 'Thumb URL cache is set up 
properly' );
@@ -77,13 +81,13 @@
                                mw.Title.newFromText( 'File:Foobar.pdf.jpg' ), 
'Foo bar',
                                10, 10, 10, 'image/jpeg', 'http://example.org', 
'http://example.com',
                                'example', 'tester', '2013-11-10', '20131110', 
'2013-11-09', 'Blah blah blah',
-                               'A person', 'Another person', 1, 
'CC-BY-SA-3.0', 'Permitted'
+                               'A person', 'Another person', 1, undefined, 
'CC-BY-SA-3.0', 'Permitted'
                        ),
                        secondImageData = new mw.mmv.model.Image(
                                mw.Title.newFromText( 'File:Foobar.pdf.jpg' ), 
'Foo bar',
                                10, 10, 10, 'image/jpeg', 'http://example.org', 
'http://example.com',
                                'example', 'tester', '2013-11-10', '20131110', 
'2013-11-09', 'Blah blah blah',
-                               'A person', 'Another person', 1, 
'CC-BY-SA-3.0', 'Permitted',
+                               'A person', 'Another person', 1, undefined, 
'CC-BY-SA-3.0', 'Permitted', undefined,
                                '39.91820938', '78.09812938'
                        );
 
diff --git a/tests/qunit/mmv/provider/mmv.provider.ImageInfo.test.js 
b/tests/qunit/mmv/provider/mmv.provider.ImageInfo.test.js
index 6dd3d74..45e3693 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', 27, function ( assert ) {
+       QUnit.asyncTest( 'ImageInfo get test', 29, function ( assert ) {
                var apiCallCount = 0,
                        api = { get: function() {
                                apiCallCount++;
@@ -98,11 +98,15 @@
                                                                                
                hidden: ''
                                                                                
        },
                                                                                
        Artist: {
-                                                                               
                value: 'Wikimeda',
+                                                                               
                value: 'John Smith',
                                                                                
                source: 'commons-desc-page'
                                                                                
        },
                                                                                
        AuthorCount: {
                                                                                
                value: '2',
+                                                                               
                source: 'commons-desc-page'
+                                                                               
        },
+                                                                               
        Attribution: {
+                                                                               
                value: 'By John Smith',
                                                                                
                source: 'commons-desc-page'
                                                                                
        },
                                                                                
        Permission: {
@@ -115,6 +119,10 @@
                                                                                
        },
                                                                                
        NonFree: {
                                                                                
                value: 'yes',
+                                                                               
                source: 'commons-desc-page'
+                                                                               
        },
+                                                                               
        DeletionReason: {
+                                                                               
                value: 'copyvio',
                                                                                
                source: 'commons-desc-page'
                                                                                
        }
                                                                                
},
@@ -146,8 +154,9 @@
                        assert.strictEqual( image.creationDateTime, '18 
February 2009\u00a0(according to EXIF data)', 'creationDateTime is set 
correctly' );
                        assert.strictEqual( image.description, 'Wikis stuff', 
'description is set correctly' );
                        assert.strictEqual( image.source, 'Wikipedia', 'source 
is set correctly' );
-                       assert.strictEqual( image.author, 'Wikimeda', 'author 
is set correctly' );
+                       assert.strictEqual( image.author, 'John Smith', 'author 
is set correctly' );
                        assert.strictEqual( image.authorCount, 2, 'author count 
is set correctly' );
+                       assert.strictEqual( image.attribution, 'By John Smith', 
'attribution is set correctly' );
                        assert.strictEqual( image.license.shortName, 'CC0', 
'license short name is set correctly' );
                        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' );
@@ -155,6 +164,7 @@
                        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.deletionReason, 'copyvio', 
'permission is set correctly' );
                        assert.strictEqual( image.latitude, 90, 'latitude is 
set correctly' );
                        assert.strictEqual( image.longitude, 180, 'longitude is 
set correctly' );
                } ).then( function() {

-- 
To view, visit https://gerrit.wikimedia.org/r/178141
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I38c1548a0de6cfd3a48db7efd7502a99f168d4a5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MultimediaViewer
Gerrit-Branch: master
Gerrit-Owner: GergÅ‘ Tisza <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to