jenkins-bot has submitted this change and it was merged.

Change subject: Warn/error when date is (likely) incompatible with license
......................................................................


Warn/error when date is (likely) incompatible with license

Bug: T140902
Change-Id: I640e5005819e5663f2ee19d0c04d608efec7e203
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M resources/details/uw.DateDetailsWidget.js
M resources/mw.UploadWizardDetails.js
M resources/mw.UploadWizardLicenseInput.js
6 files changed, 88 insertions(+), 7 deletions(-)

Approvals:
  Bartosz Dziewoński: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/extension.json b/extension.json
index b4b1682..5f15af7 100644
--- a/extension.json
+++ b/extension.json
@@ -454,6 +454,8 @@
                                "mwe-upwiz-error-signature-too-long",
                                "mwe-upwiz-error-signature-too-short",
                                "mwe-upwiz-error-blank",
+                               "mwe-upwiz-error-date-license-mismatch",
+                               "mwe-upwiz-error-date-license-unlikely",
                                "mwe-upwiz-error-too-long",
                                "mwe-upwiz-error-too-short",
                                "mwe-upwiz-error-bad-descriptions",
diff --git a/i18n/en.json b/i18n/en.json
index 2c1af6c..961a3d7 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -208,6 +208,8 @@
        "mwe-upwiz-error-heading": "The heading must be a number between 0 and 
360.",
        "mwe-upwiz-error-signature-too-long": "Your signature is too 
long.\nMake it shorter than $1 {{PLURAL:$1|character|characters}}.",
        "mwe-upwiz-error-signature-too-short": "Your signature is too 
short.\nMake it longer than $1 {{PLURAL:$1|character|characters}}.",
+       "mwe-upwiz-error-date-license-mismatch": "The selected date doesn't 
match the license ($1).",
+       "mwe-upwiz-error-date-license-unlikely": "The selected date likely 
isn't correct, given the license ($1).",
        "mwe-upwiz-error-blank": "This field is required.",
        "mwe-upwiz-error-too-long": "This entry is too long.\nPlease make sure 
this entry is at most $1 {{PLURAL:$1|character|characters}}.",
        "mwe-upwiz-error-too-short": "This entry is too short.\nPlease make 
sure this entry is at least $1 {{PLURAL:$1|character|characters}}.",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 8c6f2c5..bbf4e56 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -232,6 +232,8 @@
        "mwe-upwiz-error-heading": "Error message shown when an invalid heading 
(the direction the camera was pointing) is entered.",
        "mwe-upwiz-error-signature-too-long": "Used as error message. 
Parameters:\n* $1 - maximum number of characters for the 
signature\n{{Related|Mwe-upwiz-error-signature}}",
        "mwe-upwiz-error-signature-too-short": "Used as error message. 
Parameters:\n* $1 - minimum number of characters for the 
signature\n{{Related|Mwe-upwiz-error-signature}}",
+       "mwe-upwiz-error-date-license-mismatch": "Error message when the 
selected date is incompatible with the selected license. Parameters:\n* $1 - 
The selected license\nSee also:\n* 
{{msg-mw|Mwe-upwiz-error-date-license-unlikely}}",
+       "mwe-upwiz-error-date-license-unlikely": "Error message when the 
selected date is likely incompatible with the selected license. Parameters:\n* 
$1 - The selected license\nSee also:\n* 
{{msg-mw|Mwe-upwiz-error-date-license-mismatch}}",
        "mwe-upwiz-error-blank": "{{Identical|Required}}",
        "mwe-upwiz-error-too-long": "Used as error message. Parameters:\n* $1 - 
maximum number of characters\nSee also:\n* 
{{msg-mw|Mwe-upwiz-error-too-short}}",
        "mwe-upwiz-error-too-short": "Used as error message. Parameters:\n* $1 
- minimum number of characters\nSee also:\n* 
{{msg-mw|Mwe-upwiz-error-too-long}}",
diff --git a/resources/details/uw.DateDetailsWidget.js 
b/resources/details/uw.DateDetailsWidget.js
index dc3842a..893a65c 100644
--- a/resources/details/uw.DateDetailsWidget.js
+++ b/resources/details/uw.DateDetailsWidget.js
@@ -4,10 +4,14 @@
         * A date field in UploadWizard's "Details" step form.
         *
         * @extends uw.DetailsWidget
+        * @constructor
+        * @param {Object} config Configuration options
+        * @cfg {mw.UploadWizardUpload} upload
         */
-       uw.DateDetailsWidget = function UWDateDetailsWidget() {
+       uw.DateDetailsWidget = function UWDateDetailsWidget( config ) {
                uw.DateDetailsWidget.parent.call( this );
 
+               this.upload = config.upload;
                this.dateInputWidgetMode = null; // or: 'calendar', 'arbitrary'
                this.dateInputWidgetToggler = new OO.ui.ButtonSelectWidget( {
                        classes: [ 'mwe-upwiz-dateDetailsWidget-toggler' ],
@@ -93,19 +97,56 @@
        };
 
        /**
+        * Gets the selected license(s). The returned value will be a license
+        * key => license props map, as defined in UploadWizard.config.php.
+        *
+        * @return {Object}
+        */
+       uw.DateDetailsWidget.prototype.getLicenses = function () {
+               if ( this.upload.deedChooser.deed && 
this.upload.deedChooser.deed.licenseInput ) {
+                       return 
this.upload.deedChooser.deed.licenseInput.getLicenses();
+               }
+
+               // no license has been selected yet
+               // this could happen when uploading multiple files and 
selecting to
+               // provide copyright information for each file individually
+               return {};
+       };
+
+       /**
         * @inheritdoc
         */
        uw.DateDetailsWidget.prototype.getWarnings = function () {
-               var warnings = [],
-                       dateVal = Date.parse( 
this.dateInputWidget.getValue().trim() );
+               var i,
+                       warnings = [],
+                       dateVal = Date.parse( 
this.dateInputWidget.getValue().trim() ),
+                       licenses = this.getLicenses(),
+                       // licenses that likely mean the image date is some 
time in the past
+                       warnLicenses = [ 'pd-usgov', 'pd-usgov-nasa', 'pd-art' 
],
+                       now = new Date(),
+                       date = new Date( this.dateInputWidget.getValue() );
+
                // We don't really know what timezone this datetime is in. It 
could be the user's timezone, or
                // it could be the camera's timezone for data imported from 
EXIF, and we don't know what
                // timezone that is. UTC+14 is the highest timezone that 
currently exists, so assume that to
                // avoid giving false warnings.
                if ( this.dateInputWidgetMode === 'calendar' &&
-                       dateVal > ( new Date() ).getTime() + 14 * 60 * 60 ) {
+                       dateVal > now.getTime() + 14 * 60 * 60 ) {
                        warnings.push( mw.message( 'mwe-upwiz-warning-postdate' 
) );
                }
+
+               // doublecheck that we've actually selected a valid date
+               if ( !isNaN( date.getTime() ) ) {
+                       // it's unlikely for public domain images to have been 
published today
+                       if ( now.toISOString().slice( 0, 10 ) === 
date.toISOString().slice( 0, 10 ) ) {
+                               for ( i in warnLicenses ) {
+                                       if ( warnLicenses[ i ] in licenses ) {
+                                               warnings.push( mw.message( 
'mwe-upwiz-error-date-license-unlikely', mw.message( licenses[ warnLicenses[ i 
] ].msg ).parse() ) );
+                                       }
+                               }
+                       }
+               }
+
                return $.Deferred().resolve( warnings ).promise();
        };
 
@@ -113,10 +154,27 @@
         * @inheritdoc
         */
        uw.DateDetailsWidget.prototype.getErrors = function () {
-               var errors = [];
+               var errors = [],
+                       licenses = this.getLicenses(),
+                       now = new Date(),
+                       old = new Date( now.getFullYear() - 70, now.getMonth(), 
now.getDate() ),
+                       old100 = new Date( now.getFullYear() - 100, 
now.getMonth(), now.getDate() ),
+                       date = new Date( this.dateInputWidget.getValue() );
+
                if ( this.dateInputWidget.getValue().trim() === '' ) {
                        errors.push( mw.message( 'mwe-upwiz-error-blank' ) );
+               } else if ( 'pd-us' in licenses && date.getFullYear() >= 1923 ) 
{
+                       // if the license stated the work is public domain, it 
must've been
+                       // created a really long time ago
+                       errors.push( mw.message( 
'mwe-upwiz-error-date-license-mismatch', mw.message( licenses[ 'pd-us' ].msg 
).parse() ) );
+               } else if ( 'pd-old' in licenses && date > old ) {
+                       // if the author died 70 years ago, the timestamp 
should reflect that
+                       errors.push( mw.message( 
'mwe-upwiz-error-date-license-mismatch', mw.message( licenses[ 'pd-old' ].msg 
).parse() ) );
+               } else if ( 'pd-old-100' in licenses && date > old100 ) {
+                       // if the author died 100 years ago, the timestamp 
should reflect that
+                       errors.push( mw.message( 
'mwe-upwiz-error-date-license-mismatch', mw.message( licenses[ 'pd-old-100' 
].msg ).parse() ) );
                }
+
                return $.Deferred().resolve( errors ).promise();
        };
 
diff --git a/resources/mw.UploadWizardDetails.js 
b/resources/mw.UploadWizardDetails.js
index efc62f8..6158624 100644
--- a/resources/mw.UploadWizardDetails.js
+++ b/resources/mw.UploadWizardDetails.js
@@ -76,7 +76,7 @@
                } );
                this.mainFields.push( this.categoriesDetailsField );
 
-               this.dateDetails = new uw.DateDetailsWidget();
+               this.dateDetails = new uw.DateDetailsWidget( { upload: 
this.upload } );
                this.dateDetailsField = new uw.FieldLayout( this.dateDetails, {
                        label: mw.message( 'mwe-upwiz-date-created' ).text(),
                        help: mw.message( 'mwe-upwiz-tooltip-date' ).text(),
diff --git a/resources/mw.UploadWizardLicenseInput.js 
b/resources/mw.UploadWizardLicenseInput.js
index 075b093..20cf615 100644
--- a/resources/mw.UploadWizardLicenseInput.js
+++ b/resources/mw.UploadWizardLicenseInput.js
@@ -274,7 +274,7 @@
                                languageCode = mw.config.get( 'wgUserLanguage' 
),
 
                                // The URL is optional, but if the message 
includes it as $2, we surface the fact
-                               // that it's misisng.
+                               // that it's missing.
                                licenseURL = license.props.url === undefined ? 
'#missing license URL' : license.props.url,
 
                                licenseLink = $( '<a>' ).attr( { target: 
'_blank', href: licenseURL } ),
@@ -436,6 +436,23 @@
                },
 
                /**
+                * Gets the selected license(s). The returned value will be a 
license
+                * key => license props map, as defined in 
UploadWizard.config.php.
+                *
+                * @return {Object}
+                */
+               getLicenses: function () {
+                       var licenses = {};
+
+                       this.getSelectedInputs().each( function () {
+                               var licenseName = this.data( 'licenseName' );
+                               licenses[ licenseName ] = 
mw.UploadWizard.config.licenses[ licenseName ] || {};
+                       } );
+
+                       return licenses;
+               },
+
+               /**
                 * Gets the wikitext associated with all selected inputs. Some 
inputs also have associated textareas so we append their contents too.
                 *
                 * @return {string} of wikitext (empty string if no inputs set)

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I640e5005819e5663f2ee19d0c04d608efec7e203
Gerrit-PatchSet: 11
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <mmul...@wikimedia.org>
Gerrit-Reviewer: Bartosz Dziewoński <matma....@gmail.com>
Gerrit-Reviewer: MarkTraceur <mholmqu...@wikimedia.org>
Gerrit-Reviewer: Matthias Mullie <mmul...@wikimedia.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

Reply via email to