Matthias Mullie has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/386413 )

Change subject: [WIP] Add patent license agreement
......................................................................

[WIP] Add patent license agreement

Bug: T178513
Change-Id: I5194beef2378c636f06f0a61cc3daf9a7cec99bd
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M resources/controller/uw.controller.Deed.js
M resources/controller/uw.controller.Details.js
M resources/deed/uw.deed.OwnWork.js
M resources/uw.ValidationMessageElement.js
7 files changed, 170 insertions(+), 52 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard 
refs/changes/13/386413/1

diff --git a/extension.json b/extension.json
index 3beab2b..d0e0f82 100644
--- a/extension.json
+++ b/extension.json
@@ -774,6 +774,7 @@
                        ],
                        "messages": [
                                "mwe-upwiz-tooltip-sign",
+                               "mwe-upwiz-source-ownwork-patent",
                                "mwe-upwiz-source-ownwork-assert-any-license",
                                "mwe-upwiz-source-ownwork-assert",
                                "mwe-upwiz-source-ownwork-assert-custom",
diff --git a/i18n/en.json b/i18n/en.json
index 7c21010..edc6e76 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -78,6 +78,7 @@
        "mwe-upwiz-finished": "Finished!",
        "mwe-upwiz-deeds-macro-prompt": "This site requires {{GENDER:$2|you}} 
to provide copyright information for {{PLURAL:$1|this work|these works}}, to 
make sure everyone can legally reuse {{PLURAL:$1|it|them}}.",
        "mwe-upwiz-source-ownwork": "{{PLURAL:$1|This file is|These files are}} 
my own work.",
+       "mwe-upwiz-source-ownwork-patent": "I, $2, would like to grant a 
permanent patent license to any users of {{PLURAL:$1|the file|the files}} and 
related 3D objects ([$3 legal code]).",
        "mwe-upwiz-source-ownwork-assert-any-license": "I, $2, {{GENDER:$4|the 
copyright holder}} of {{PLURAL:$1|this work|these works}}, hereby irrevocably 
grant anyone the right to use, modify and redistribute {{PLURAL:$1|this 
work|these works}} for any purpose, and I therefore publish 
{{PLURAL:$1|it|them}} under the following terms:",
        "mwe-upwiz-source-ownwork-assert": "I, $2, {{GENDER:$4|the copyright 
holder}} of {{PLURAL:$1|this work|these works}}, hereby irrevocably grant 
anyone the right to use {{PLURAL:$1|this work|these works}} for any purpose, as 
long as they credit me and share derivative work under the same terms.",
        "mwe-upwiz-source-ownwork-assert-cc-by-sa-4.0": "I, $2, {{GENDER:$4|the 
copyright holder}} of {{PLURAL:$1|this work|these works}}, irrevocably grant 
anyone the right to use {{PLURAL:$1|this work|these works}} under the Creative 
Commons Attribution ShareAlike 4.0 license ([$3 legal code]).",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index eb8405a..0cab4b0 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -105,6 +105,7 @@
        "mwe-upwiz-finished": "Used as success message.\n\nRelated messages:\n* 
{{msg-mw|mwe-upwiz-secs-remaining}}\n* 
{{msg-mw|mwe-upwiz-mins-secs-remaining}}\n* 
{{msg-mw|mwe-upwiz-hrs-mins-secs-remaining}}\n{{Identical|Finished}}",
        "mwe-upwiz-deeds-macro-prompt": "An explanation below the thumbnail and 
above the following radio buttons:\n* {{msg-mw|Mwe-upwiz-source-ownwork}}\n* 
{{msg-mw|Mwe-upwiz-source-thirdparty}}.\nParameters:\n* $1 - the number of 
files\n* $2 - username, for GENDER support",
        "mwe-upwiz-source-ownwork": "Parameters:\n* $1 - number of 
files\n{{Related|Mwe-upwiz-source-ownwork}}",
+       "mwe-upwiz-source-ownwork-patent": "Parameters:\n* $1 - number of works 
(number of 3D uploads)\n* $2 - author name\n* $3 - full URL\n* $4 - a user 
object, which can be used for GENDER",
        "mwe-upwiz-source-ownwork-assert-any-license": "Parameters:\n* $1 - 
number of works (number of uploads)\n* $2 - the \"Author name\" input 
box\n{{Related|Mwe-upwiz-source-ownwork-assert}}",
        "mwe-upwiz-source-ownwork-assert": 
"{{doc-singularthey}}\nParameters:\n* $1 - number of works\n* $2 - author 
name\n* $3 - full URL, unused\n* $4 - a user object, which can be used for 
GENDER\n{{Related|Mwe-upwiz-source-ownwork}}",
        "mwe-upwiz-source-ownwork-assert-cc-by-sa-4.0": "Used as license 
message. Parameters:\n* $1 - number of the works\n* $2 - the \"Author name\" 
input box\n* $3 - full URL, //creativecommons.org/licenses/by-sa/4.0/\n* $4 - a 
user object, which can be used for 
GENDER\n{{Related|Mwe-upwiz-source-ownwork-assert}}",
diff --git a/resources/controller/uw.controller.Deed.js 
b/resources/controller/uw.controller.Deed.js
index 8e8d144..a367352 100644
--- a/resources/controller/uw.controller.Deed.js
+++ b/resources/controller/uw.controller.Deed.js
@@ -53,25 +53,26 @@
                if ( valid ) {
                        fields = this.deedChooser.deed.getFields();
 
-                       // Update any error/warning messages
-                       fields.forEach( function ( fieldLayout ) {
-                               fieldLayout.checkValidity();
-                       } );
-
-                       // TODO Handle warnings with a confirmation dialog
                        $.when.apply( $, fields.map( function ( fieldLayout ) {
-                               return fieldLayout.fieldWidget.getErrors();
+                               // Update any error/warning messages
+                               return fieldLayout.checkValidity( true );
                        } ) ).done( function () {
+                               // `arguments` will be an array of all fields, 
with their warnings & errors
+                               // e.g. `[[something], []], [[], [something]]` 
for 2 fields, where the first one has
+                               // a warning and the last one an error
+
+                               // TODO Handle warnings with a confirmation 
dialog
+
                                var i;
                                for ( i = 0; i < arguments.length; i++ ) {
-                                       if ( arguments[ i ].length ) {
-                                               // One of the fields has errors
+                                       if ( arguments[ i ][ 1 ].length ) {
+                                               // One of the fields has 
errors; refuse to proceed!
                                                return;
                                        }
                                }
 
                                uw.controller.Step.prototype.moveNext.call( 
deedController );
-                       } );
+                       }) ;
                }
        };
 
diff --git a/resources/controller/uw.controller.Details.js 
b/resources/controller/uw.controller.Details.js
index 99355d5..dde6ae4 100644
--- a/resources/controller/uw.controller.Details.js
+++ b/resources/controller/uw.controller.Details.js
@@ -172,6 +172,7 @@
 
                $.each( this.uploads, function ( i, upload ) {
                        // Update any error/warning messages about all 
DetailsWidgets
+                       // @todo turn this into a 'thorough' check on submit
                        upload.details.checkValidity();
 
                        warningValidityPromises.push( 
upload.details.getWarnings().then( function () {
diff --git a/resources/deed/uw.deed.OwnWork.js 
b/resources/deed/uw.deed.OwnWork.js
index 880aba6..37ae998 100644
--- a/resources/deed/uw.deed.OwnWork.js
+++ b/resources/deed/uw.deed.OwnWork.js
@@ -32,6 +32,7 @@
 
                this.config = config;
                this.uploadCount = uploads.length;
+               this.threeDCount = this.get3DCount( uploads );
 
                // copyright holder
                this.authorInput = new OO.ui.TextInputWidget( {
@@ -61,6 +62,16 @@
                        this.licenseInput.$element.addClass( 
'mwe-upwiz-deed-license' );
                        this.licenseInputField = new uw.FieldLayout( 
this.licenseInput );
                }
+
+               // grant patent license
+               if ( this.threeDCount > 0 ) {
+                       this.patentAuthorInput = new OO.ui.TextInputWidget( {
+                               name: 'patent-author',
+                               title: mw.message( 'mwe-upwiz-tooltip-sign' 
).text(),
+                               value: mw.config.get( 'wgUserName' ),
+                               classes: [ 'mwe-upwiz-sign' ]
+                       } );
+               }
        };
 
        OO.inheritClass( uw.deed.OwnWork, uw.deed.Abstract );
@@ -73,13 +84,17 @@
                if ( this.showCustomDiv ) {
                        fields.push( this.licenseInputField );
                }
+               if ( this.threeDCount > 0 ) {
+                       fields.push( this.patentAuthorInputField );
+               }
                return fields;
        };
 
        uw.deed.OwnWork.prototype.setFormFields = function ( $selector ) {
                var $customDiv, $formFields, $toggler, crossfaderWidget, 
defaultLicense,
                        defaultLicenseURL, defaultLicenseMsg, 
defaultLicenseExplainMsg,
-                       defaultLicenseLink, $standardDiv, $crossfader, deed, 
languageCode;
+                       defaultLicenseLink, $standardDiv, $crossfader, deed, 
languageCode,
+                       patentURL, patentMsg, patentLink, $patentDiv, 
patentWidget;
 
                this.$selector = $selector;
                deed = this;
@@ -124,27 +139,9 @@
                crossfaderWidget = new OO.ui.Widget();
                crossfaderWidget.$element.append( $crossfader );
                // See uw.DetailsWidget
-               crossfaderWidget.getErrors = function () {
-                       var
-                               errors = [],
-                               minLength = deed.config.minAuthorLength,
-                               maxLength = deed.config.maxAuthorLength,
-                               text = deed.authorInput.getValue().trim();
+               crossfaderWidget.getErrors = this.getAuthorErrors.bind( this, 
this.authorInput );
+               crossfaderWidget.getWarnings = this.getAuthorWarnings.bind( 
this, this.authorInput );
 
-                       if ( text === '' ) {
-                               errors.push( mw.message( 
'mwe-upwiz-error-signature-blank' ) );
-                       } else if ( text.length < minLength ) {
-                               errors.push( mw.message( 
'mwe-upwiz-error-signature-too-short', minLength ) );
-                       } else if ( text.length > maxLength ) {
-                               errors.push( mw.message( 
'mwe-upwiz-error-signature-too-long', maxLength ) );
-                       }
-
-                       return $.Deferred().resolve( errors ).promise();
-               };
-               // See uw.DetailsWidget
-               crossfaderWidget.getWarnings = function () {
-                       return $.Deferred().resolve( [] ).promise();
-               };
                this.authorInputField = new uw.FieldLayout( crossfaderWidget );
                // Aggregate 'change' event
                this.authorInput.on( 'change', OO.ui.debounce( function () {
@@ -152,24 +149,52 @@
                }, 500 ) );
 
                $formFields = $( '<div class="mwe-upwiz-deed-form-internal" />' 
)
-                       .append(
-                               this.authorInputField.$element,
-                               this.showCustomDiv ? 
this.licenseInputField.$element.hide() : ''
-               );
-
-               $toggler = $( '<p class="mwe-more-options" style="text-align: 
right"></p>' )
-                       .append( $( '<a />' )
-                               .msg( 'mwe-upwiz-license-show-all' )
-                               .click( function () {
-                                       if ( $crossfader.data( 
'crossfadeDisplay' ).get( 0 ) === $customDiv.get( 0 ) ) {
-                                               deed.standardLicense();
-                                       } else {
-                                               deed.customLicense();
-                                       }
-                               } ) );
+                       .append( this.authorInputField.$element );
 
                if ( this.showCustomDiv ) {
-                       $formFields.append( $toggler );
+                       $toggler = $( '<p class="mwe-more-options" 
style="text-align: right"></p>' )
+                               .append( $( '<a />' )
+                                       .msg( 'mwe-upwiz-license-show-all' )
+                                       .click( function () {
+                                               if ( $crossfader.data( 
'crossfadeDisplay' ).get( 0 ) === $customDiv.get( 0 ) ) {
+                                                       deed.standardLicense();
+                                               } else {
+                                                       deed.customLicense();
+                                               }
+                                       } ) );
+
+                       $formFields.append( 
this.licenseInputField.$element.hide(), $toggler );
+               }
+
+               if ( this.threeDCount > 0 ) {
+                       // @todo url?
+                       patentURL = 'todo';
+                       patentMsg = 'mwe-upwiz-source-ownwork-patent';
+                       patentLink = $( '<a>' ).attr( { target: '_blank', href: 
patentURL } );
+
+                       $patentDiv = $( '<div class="mwe-upwiz-patent" />' 
).append(
+                               $( '<p>' ).msg(
+                                       patentMsg,
+                                       this.threeDCount,
+                                       this.patentAuthorInput.$element,
+                                       patentLink,
+                                       mw.user
+                               )
+                       );
+
+                       patentWidget = new OO.ui.Widget();
+                       patentWidget.$element.append( $patentDiv );
+
+                       // See uw.DetailsWidget
+                       patentWidget.getErrors = 
this.getPatentAuthorErrors.bind( this, this.patentAuthorInput );
+                       patentWidget.getWarnings = this.getAuthorWarnings.bind( 
this, this.patentAuthorInput );
+
+                       this.patentAuthorInputField = new uw.FieldLayout( 
patentWidget );
+                       deed.patentAuthorInput.on( 'change', OO.ui.debounce( 
function () {
+                               patentWidget.emit( 'change' );
+                       }, 500 ) );
+
+                       $formFields.append( 
this.patentAuthorInputField.$element );
                }
 
                this.$form.append( $formFields ).appendTo( $selector );
@@ -230,6 +255,10 @@
                        serialized.license = this.licenseInput.getSerialized();
                }
 
+               if ( this.threeDCount > 0 ) {
+                       serialized.patentAuthor = 
this.patentAuthorInput.getValue();
+               }
+
                return serialized;
        };
 
@@ -250,6 +279,10 @@
                                this.customLicense();
                                this.licenseInput.setSerialized( 
serialized.license );
                        }
+               }
+
+               if ( this.threeDCount > 0 && serialized.patentAuthor ) {
+                       this.patentAuthorInput.setValue( 
serialized.patentAuthor );
                }
        };
 
@@ -311,4 +344,76 @@
 
                $toggler.msg( 'mwe-upwiz-license-show-recommended' );
        };
+
+       uw.deed.OwnWork.prototype.getPatentAuthorErrors = function ( input, 
thorough ) {
+               var promise = this.getAuthorErrors( input, thorough );
+
+               if ( thorough ) {
+                       promise = promise.then( function ( errors ) {
+                               // If there are existing errors, there is no 
need to ask for additional confirmation (yet)
+                               if ( errors.length > 0 ) {
+                                       return errors;
+                               }
+
+                               if ( !confirm( 'This will be a neat popup 
widget at some point' ) ) {
+                                       // @todo: there probably doesn't even 
have to be an error message with the modal, we just won't enable the "next" 
button to close it until the checkbox has been ticked
+                                       errors.push( mw.message( 'just a test' 
) ); // @todo i18n message
+                               }
+
+                               return errors;
+                       } );
+               }
+
+               return promise;
+       };
+
+       /**
+        * @param {OO.ui.InputWidget} input
+        * @returns {jQuery.Promise}
+        */
+       uw.deed.OwnWork.prototype.getAuthorErrors = function ( input ) {
+               var
+                       errors = [],
+                       minLength = this.config.minAuthorLength,
+                       maxLength = this.config.maxAuthorLength,
+                       text = input.getValue().trim();
+
+               if ( text === '' ) {
+                       errors.push( mw.message( 
'mwe-upwiz-error-signature-blank' ) );
+               } else if ( text.length < minLength ) {
+                       errors.push( mw.message( 
'mwe-upwiz-error-signature-too-short', minLength ) );
+               } else if ( text.length > maxLength ) {
+                       errors.push( mw.message( 
'mwe-upwiz-error-signature-too-long', maxLength ) );
+               }
+
+               // @todo shove popup widget in here, somehow? (but it needs to 
be able to tell when it was submitted instead of just random change event)
+
+               return $.Deferred().resolve( errors ).promise();
+       };
+
+       /**
+        * @param {OO.ui.Widget} input
+        * @returns {jQuery.Promise}
+        */
+       uw.deed.OwnWork.prototype.getAuthorWarnings = function ( input ) {
+               return $.Deferred().resolve( [] ).promise()
+       };
+
+       /**
+        * @param {mw.UploadWizardUpload[]} uploads Array of uploads
+        * @return {number}
+        */
+       uw.deed.OwnWork.prototype.get3DCount = function ( uploads ) {
+               // @todo make 'stl' configurable'
+               var extensions = [ 'stl' ],
+                       threeDCount = 0;
+
+               $.each( uploads, function ( i, upload ) {
+                       if ( $.inArray( 
upload.title.getExtension().toLowerCase(), extensions ) >= 0 ) {
+                               threeDCount++;
+                       }
+               } );
+
+               return threeDCount;
+       };
 }( mediaWiki, mediaWiki.uploadWizard, jQuery, OO ) );
diff --git a/resources/uw.ValidationMessageElement.js 
b/resources/uw.ValidationMessageElement.js
index 2f941c0..0075651 100644
--- a/resources/uw.ValidationMessageElement.js
+++ b/resources/uw.ValidationMessageElement.js
@@ -36,9 +36,14 @@
 
        /**
         * Check the field's widget for errors and warnings and display them in 
the UI.
+        *
+        * @param {bool} thorough True to perform a thorough validity check. 
Defaults to false for a fast on-change check.
+        * @return {jQuery.Promise}
         */
-       uw.ValidationMessageElement.prototype.checkValidity = function () {
+       uw.ValidationMessageElement.prototype.checkValidity = function ( 
thorough ) {
                var element = this;
+               thorough = thorough || false;
+
                if ( !this.validatedWidget.getWarnings || 
!this.validatedWidget.getErrors ) {
                        // Don't do anything for non-Details widgets
                        return;
@@ -46,13 +51,16 @@
                if ( this.validatedWidget.pushPending ) {
                        this.validatedWidget.pushPending();
                }
-               $.when(
-                       this.validatedWidget.getWarnings(),
-                       this.validatedWidget.getErrors()
-               ).done( function ( warnings, errors ) {
+
+               return $.when(
+                       this.validatedWidget.getWarnings( thorough ),
+                       this.validatedWidget.getErrors( thorough )
+               ).then( function ( warnings, errors ) {
                        // this.notices and this.errors are arrays of 
mw.Messages and not strings in this subclass
                        element.setNotices( warnings );
                        element.setErrors( errors );
+
+                       return $.Deferred().resolve( warnings, errors 
).promise();
                } ).always( function () {
                        if ( element.validatedWidget.popPending ) {
                                element.validatedWidget.popPending();

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5194beef2378c636f06f0a61cc3daf9a7cec99bd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>

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

Reply via email to