jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/397813 )

Change subject: Add patent template for 3D uploads
......................................................................


Add patent template for 3D uploads

Bug: T182681
Change-Id: Ia62368219d5e695c3dfbffcc2158e115a70c3927
---
M UploadWizard.config.php
M resources/deed/uw.deed.Abstract.js
M resources/deed/uw.deed.Custom.js
M resources/deed/uw.deed.External.js
M resources/deed/uw.deed.OwnWork.js
M resources/deed/uw.deed.ThirdParty.js
M resources/mw.UploadWizardDetails.js
M resources/mw.UploadWizardLicenseInput.js
M resources/ui/steps/uw.ui.Details.js
9 files changed, 66 insertions(+), 50 deletions(-)

Approvals:
  jenkins-bot: Verified
  Cparle: Looks good to me, approved



diff --git a/UploadWizard.config.php b/UploadWizard.config.php
index dec4e69..25723e9 100644
--- a/UploadWizard.config.php
+++ b/UploadWizard.config.php
@@ -525,6 +525,7 @@
 
        'patents' => [
                'extensions' => [ 'stl' ],
+               'template' => '3dpatent',
                'url' => [
                        'legalcode' => 
'//wikimediafoundation.org/wiki/Wikimedia_3D_file_patent_license',
                        'warranty' => 
'//meta.wikimedia.org/wiki/Wikilegal/3D_files_and_3D_printing',
diff --git a/resources/deed/uw.deed.Abstract.js 
b/resources/deed/uw.deed.Abstract.js
index 10dced8..f8c3e93 100644
--- a/resources/deed/uw.deed.Abstract.js
+++ b/resources/deed/uw.deed.Abstract.js
@@ -59,32 +59,41 @@
 
        /* eslint-disable valid-jsdoc */
        /**
+        * @param {mw.UploadWizardUpload} upload
         * @return {string}
         */
        /* eslint-enable valid-jsdoc */
-       uw.deed.Abstract.prototype.getSourceWikiText = function () {
+       /* eslint-disable no-unused-vars */
+       uw.deed.Abstract.prototype.getSourceWikiText = function ( upload ) {
                throw new Error( 'Not implemented.' );
        };
+       /* eslint-enable no-unused-vars */
 
        /* eslint-disable valid-jsdoc */
        /**
+        * @param {mw.UploadWizardUpload} upload
         * @return {string}
         */
        /* eslint-enable valid-jsdoc */
-       uw.deed.Abstract.prototype.getAuthorWikiText = function () {
+       /* eslint-disable no-unused-vars */
+       uw.deed.Abstract.prototype.getAuthorWikiText = function ( upload ) {
                throw new Error( 'Not implemented.' );
        };
+       /* eslint-enableno-unused-vars */
 
        /* eslint-disable valid-jsdoc */
        /**
         * Get wikitext representing the licenses selected in the license object
         *
+        * @param {mw.UploadWizardUpload} upload
         * @return {string} wikitext of all applicable license templates.
         */
        /* eslint-enable valid-jsdoc */
-       uw.deed.Abstract.prototype.getLicenseWikiText = function () {
+       /* eslint-disable no-unused-vars */
+       uw.deed.Abstract.prototype.getLicenseWikiText = function ( upload ) {
                throw new Error( 'Not implemented.' );
        };
+       /* eslint-enableno-unused-vars */
 
        /**
         * @return {Object}
@@ -105,20 +114,13 @@
        };
 
        /**
-        * @param {mw.UploadWizardUpload[]} uploads Array of uploads
-        * @return {number}
+        * @param {mw.UploadWizardUpload} upload
+        * @returns {boolean}
         */
-       uw.deed.Abstract.prototype.get3DCount = function ( uploads ) {
-               var extensions = this.config.patents ? 
this.config.patents.extensions : [],
-                       threeDCount = 0;
+       uw.deed.Abstract.prototype.needsPatentAgreement = function ( upload ) {
+               var extensions = this.config.patents ? 
this.config.patents.extensions : [];
 
-               $.each( uploads, function ( i, upload ) {
-                       if ( $.inArray( 
upload.title.getExtension().toLowerCase(), extensions ) >= 0 ) {
-                               threeDCount++;
-                       }
-               } );
-
-               return threeDCount;
+               return $.inArray( upload.title.getExtension().toLowerCase(), 
extensions ) >= 0;
        };
 
        /**
diff --git a/resources/deed/uw.deed.Custom.js b/resources/deed/uw.deed.Custom.js
index 8fbe936..7c90c67 100644
--- a/resources/deed/uw.deed.Custom.js
+++ b/resources/deed/uw.deed.Custom.js
@@ -31,7 +31,7 @@
        OO.inheritClass( uw.deed.Custom, uw.deed.Abstract );
 
        /**
-        * @return {string}
+        * @inheritdoc
         */
        uw.deed.Custom.prototype.getSourceWikiText = function () {
                if ( typeof this.upload.file.sourceURL !== 'undefined' ) {
@@ -42,14 +42,14 @@
        };
 
        /**
-        * @return {string}
+        * @inheritdoc
         */
        uw.deed.Custom.prototype.getAuthorWikiText = function () {
                return this.upload.file.author;
        };
 
        /**
-        * @return {string}
+        * @inheritdoc
         */
        uw.deed.Custom.prototype.getLicenseWikiText = function () {
                return this.upload.file.licenseValue;
diff --git a/resources/deed/uw.deed.External.js 
b/resources/deed/uw.deed.External.js
index 1464eab..3387e20 100644
--- a/resources/deed/uw.deed.External.js
+++ b/resources/deed/uw.deed.External.js
@@ -46,7 +46,7 @@
        };
 
        /**
-        * @return {uw.FieldLayout[]} Fields that need validation
+        * @inheritdoc
         */
        uw.deed.External.prototype.getLicenseWikiText = function () {
                if ( this.upload.file.licenseValue ) {
diff --git a/resources/deed/uw.deed.OwnWork.js 
b/resources/deed/uw.deed.OwnWork.js
index e046800..a1e9059 100644
--- a/resources/deed/uw.deed.OwnWork.js
+++ b/resources/deed/uw.deed.OwnWork.js
@@ -32,7 +32,7 @@
                uw.deed.Abstract.call( this, 'ownwork', config );
 
                this.uploadCount = uploads.length;
-               this.threeDCount = this.get3DCount( uploads );
+               this.threeDCount = uploads.filter( 
this.needsPatentAgreement.bind( this ) ).length;
 
                if ( !prefAuthName ) {
                        prefAuthName = mw.config.get( 'wgUserName' );
@@ -229,12 +229,16 @@
                } );
        };
 
+       /**
+        * @inheritdoc
+        */
        uw.deed.OwnWork.prototype.getSourceWikiText = function () {
                return '{{own}}';
        };
 
-       // XXX do we need to escape authorInput, or is wikitext a feature here?
-       // what about scripts?
+       /**
+        * @inheritdoc
+        */
        uw.deed.OwnWork.prototype.getAuthorWikiText = function () {
                var author = this.authorInput.getValue();
 
@@ -245,16 +249,27 @@
                return '[[User:' + mw.config.get( 'wgUserName' ) + '|' + author 
+ ']]';
        };
 
-       uw.deed.OwnWork.prototype.getLicenseWikiText = function () {
+       /**
+        * @inheritdoc
+        */
+       uw.deed.OwnWork.prototype.getLicenseWikiText = function ( upload ) {
+               var wikitext = '';
+
                if ( this.showCustomDiv && this.licenseInput.getWikiText() !== 
'' ) {
-                       return this.licenseInput.getWikiText();
+                       wikitext += this.licenseInput.getWikiText();
                } else {
-                       return '{{' +
+                       wikitext += '{{' +
                                this.config.licensing.ownWork.template +
                                '|' +
                                this.getDefaultLicense() +
                                '}}';
                }
+
+               if ( this.needsPatentAgreement( upload ) ) {
+                       wikitext += '\n{{' + this.config.patents.template + 
'|ownwork}}';
+               }
+
+               return wikitext;
        };
 
        /**
diff --git a/resources/deed/uw.deed.ThirdParty.js 
b/resources/deed/uw.deed.ThirdParty.js
index 09b3b66..41a286d 100644
--- a/resources/deed/uw.deed.ThirdParty.js
+++ b/resources/deed/uw.deed.ThirdParty.js
@@ -31,7 +31,7 @@
                uw.deed.Abstract.call( this, 'thirdparty', config );
 
                this.uploadCount = uploads.length;
-               this.threeDCount = this.get3DCount( uploads );
+               this.threeDCount = uploads.filter( 
this.needsPatentAgreement.bind( this ) ).length;
 
                this.sourceInput = new OO.ui.MultilineTextInputWidget( {
                        autosize: true,
@@ -180,26 +180,30 @@
        };
 
        /**
-        * @return {string}
+        * @inheritdoc
         */
        uw.deed.Abstract.prototype.getSourceWikiText = function () {
                return this.sourceInput.getValue();
        };
 
        /**
-        * @return {string}
+        * @inheritdoc
         */
        uw.deed.Abstract.prototype.getAuthorWikiText = function () {
                return this.authorInput.getValue();
        };
 
        /**
-        * Get wikitext representing the licenses selected in the license object
-        *
-        * @return {string} wikitext of all applicable license templates.
+        * @inheritdoc
         */
-       uw.deed.Abstract.prototype.getLicenseWikiText = function () {
-               return this.licenseInput.getWikiText();
+       uw.deed.Abstract.prototype.getLicenseWikiText = function ( upload ) {
+               var wikitext = this.licenseInput.getWikiText();
+
+               if ( this.needsPatentAgreement( upload ) ) {
+                       wikitext += '\n{{' + this.config.patents.template + 
'}}';
+               }
+
+               return wikitext;
        };
 
        /**
diff --git a/resources/mw.UploadWizardDetails.js 
b/resources/mw.UploadWizardDetails.js
index 90c7d4c..c49056d 100644
--- a/resources/mw.UploadWizardDetails.js
+++ b/resources/mw.UploadWizardDetails.js
@@ -730,9 +730,9 @@
 
                        deed = this.upload.deedChooser.deed;
 
-                       information.source = deed.getSourceWikiText();
+                       information.source = deed.getSourceWikiText( 
this.upload );
 
-                       information.author = deed.getAuthorWikiText();
+                       information.author = deed.getAuthorWikiText( 
this.upload );
 
                        info = '';
 
@@ -753,7 +753,7 @@
 
                        // add licensing information
                        wikiText += '\n=={{int:license-header}}==\n';
-                       wikiText += deed.getLicenseWikiText() + '\n\n';
+                       wikiText += deed.getLicenseWikiText( this.upload ) + 
'\n\n';
 
                        if ( mw.UploadWizard.config.autoAdd.wikitext !== 
undefined ) {
                                wikiText += 
mw.UploadWizard.config.autoAdd.wikitext + '\n';
diff --git a/resources/mw.UploadWizardLicenseInput.js 
b/resources/mw.UploadWizardLicenseInput.js
index 5862147..37f8bab 100644
--- a/resources/mw.UploadWizardLicenseInput.js
+++ b/resources/mw.UploadWizardLicenseInput.js
@@ -464,8 +464,9 @@
                                                return input.getInputWikiText( 
this );
                                        }
                                );
+
                        // need to use makeArray because a jQuery-returned set 
of things won't have .join
-                       return $.makeArray( wikiTexts ).join( '' );
+                       return $.makeArray( wikiTexts ).join( '' ).trim();
                },
 
                /**
diff --git a/resources/ui/steps/uw.ui.Details.js 
b/resources/ui/steps/uw.ui.Details.js
index 582ef80..c7a1171 100644
--- a/resources/ui/steps/uw.ui.Details.js
+++ b/resources/ui/steps/uw.ui.Details.js
@@ -72,7 +72,7 @@
        uw.ui.Details.prototype.load = function ( uploads ) {
                uw.ui.Step.prototype.load.call( this, uploads );
 
-               if ( this.get3DCount( uploads ) > 0 ) {
+               if ( uploads.filter( this.needsPatentAgreement.bind( this ) 
).length > 0 ) {
                        this.$div.prepend(
                                $( '<div>' )
                                        .addClass( 
'mwe-upwiz-patent-weapon-policy ui-corner-all' )
@@ -240,20 +240,13 @@
        };
 
        /**
-        * @param {mw.UploadWizardUpload[]} uploads Array of uploads
-        * @return {number}
+        * @param {mw.UploadWizardUpload} upload
+        * @returns {boolean}
         */
-       uw.ui.Details.prototype.get3DCount = function ( uploads ) {
-               var extensions = mw.UploadWizard.config.patents.extensions,
-                       threeDCount = 0;
+       uw.ui.Details.prototype.needsPatentAgreement = function ( upload ) {
+               var extensions = mw.UploadWizard.config.patents.extensions;
 
-               $.each( uploads, function ( i, upload ) {
-                       if ( $.inArray( 
upload.title.getExtension().toLowerCase(), extensions ) >= 0 ) {
-                               threeDCount++;
-                       }
-               } );
-
-               return threeDCount;
+               return $.inArray( upload.title.getExtension().toLowerCase(), 
extensions ) >= 0;
        };
 
 }( mediaWiki, jQuery, mediaWiki.uploadWizard, OO ) );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia62368219d5e695c3dfbffcc2158e115a70c3927
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
Gerrit-Reviewer: Cparle <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to