Matthias Mullie has uploaded a new change for review. (
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, 71 insertions(+), 58 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard
refs/changes/13/397813/1
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..128f253 100644
--- a/resources/deed/uw.deed.Abstract.js
+++ b/resources/deed/uw.deed.Abstract.js
@@ -59,19 +59,21 @@
/* eslint-disable valid-jsdoc */
/**
+ * @param {mw.UploadWizardUpload} upload
* @return {string}
*/
/* eslint-enable valid-jsdoc */
- uw.deed.Abstract.prototype.getSourceWikiText = function () {
+ uw.deed.Abstract.prototype.getSourceWikiText = function ( upload ) {
throw new Error( 'Not implemented.' );
};
/* eslint-disable valid-jsdoc */
/**
+ * @param {mw.UploadWizardUpload} upload
* @return {string}
*/
/* eslint-enable valid-jsdoc */
- uw.deed.Abstract.prototype.getAuthorWikiText = function () {
+ uw.deed.Abstract.prototype.getAuthorWikiText = function ( upload ) {
throw new Error( 'Not implemented.' );
};
@@ -79,10 +81,11 @@
/**
* 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 () {
+ uw.deed.Abstract.prototype.getLicenseWikiText = function ( upload ) {
throw new Error( 'Not implemented.' );
};
@@ -105,20 +108,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..b905003 100644
--- a/resources/deed/uw.deed.Custom.js
+++ b/resources/deed/uw.deed.Custom.js
@@ -31,9 +31,9 @@
OO.inheritClass( uw.deed.Custom, uw.deed.Abstract );
/**
- * @return {string}
+ * @inheritdoc
*/
- uw.deed.Custom.prototype.getSourceWikiText = function () {
+ uw.deed.Custom.prototype.getSourceWikiText = function ( upload ) {
if ( typeof this.upload.file.sourceURL !== 'undefined' ) {
return this.upload.file.sourceURL;
} else {
@@ -42,16 +42,16 @@
};
/**
- * @return {string}
+ * @inheritdoc
*/
- uw.deed.Custom.prototype.getAuthorWikiText = function () {
+ uw.deed.Custom.prototype.getAuthorWikiText = function ( upload ) {
return this.upload.file.author;
};
/**
- * @return {string}
+ * @inheritdoc
*/
- uw.deed.Custom.prototype.getLicenseWikiText = function () {
+ uw.deed.Custom.prototype.getLicenseWikiText = function ( upload ) {
return this.upload.file.licenseValue;
};
}( mediaWiki, mediaWiki.uploadWizard, jQuery, OO ) );
diff --git a/resources/deed/uw.deed.External.js
b/resources/deed/uw.deed.External.js
index 1464eab..af81eed 100644
--- a/resources/deed/uw.deed.External.js
+++ b/resources/deed/uw.deed.External.js
@@ -46,9 +46,9 @@
};
/**
- * @return {uw.FieldLayout[]} Fields that need validation
+ * @inheritdoc
*/
- uw.deed.External.prototype.getLicenseWikiText = function () {
+ uw.deed.External.prototype.getLicenseWikiText = function ( upload ) {
if ( this.upload.file.licenseValue ) {
return this.upload.file.licenseValue +
this.licenseInput.getWikiText();
} else {
diff --git a/resources/deed/uw.deed.OwnWork.js
b/resources/deed/uw.deed.OwnWork.js
index e046800..0b9ef85 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,13 +229,20 @@
} );
};
- uw.deed.OwnWork.prototype.getSourceWikiText = function () {
+ /**
+ * @inheritdoc
+ */
+ uw.deed.OwnWork.prototype.getSourceWikiText = function ( upload ) {
return '{{own}}';
};
- // XXX do we need to escape authorInput, or is wikitext a feature here?
- // what about scripts?
- uw.deed.OwnWork.prototype.getAuthorWikiText = function () {
+ /**
+ * @inheritdoc
+ *
+ * TODO do we need to escape authorInput, or is wikitext a feature here?
+ * what about scripts?
+ */
+ uw.deed.OwnWork.prototype.getAuthorWikiText = function ( upload ) {
var author = this.authorInput.getValue();
if ( author.indexOf( '[' ) >= 0 || author.indexOf( '{' ) >= 0 )
{
@@ -245,16 +252,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 +
'}}';
+ }
+
+ return wikitext;
};
/**
diff --git a/resources/deed/uw.deed.ThirdParty.js
b/resources/deed/uw.deed.ThirdParty.js
index 09b3b66..bcef9de 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 () {
+ uw.deed.Abstract.prototype.getSourceWikiText = function ( upload ) {
return this.sourceInput.getValue();
};
/**
- * @return {string}
+ * @inheritdoc
*/
- uw.deed.Abstract.prototype.getAuthorWikiText = function () {
+ uw.deed.Abstract.prototype.getAuthorWikiText = function ( upload ) {
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 a375c1b..2fc1008 100644
--- a/resources/mw.UploadWizardDetails.js
+++ b/resources/mw.UploadWizardDetails.js
@@ -731,9 +731,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 = '';
@@ -754,7 +754,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: newchange
Gerrit-Change-Id: Ia62368219d5e695c3dfbffcc2158e115a70c3927
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