2014-03-20 01:19:54 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the MediaWiki extension MediaViewer.
|
|
|
|
*
|
|
|
|
* MediaViewer is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MediaViewer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with MediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-05-19 20:26:45 +00:00
|
|
|
const { HtmlUtils } = require( 'mmv.bootstrap' );
|
|
|
|
|
2018-11-12 16:33:24 +00:00
|
|
|
( function () {
|
2014-03-20 01:19:54 +00:00
|
|
|
var LP;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class for storing license information about an image. For available fields, see
|
|
|
|
* TemplateParser::$licenseFieldClasses in the CommonsMetadata extension.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-03-20 01:19:54 +00:00
|
|
|
* @class mw.mmv.model.License
|
2014-04-29 18:31:16 +00:00
|
|
|
* @param {string} shortName see {@link #shortName}
|
|
|
|
* @param {string} [internalName] see {@link #internalName}
|
|
|
|
* @param {string} [longName] see {@link #longName}
|
|
|
|
* @param {string} [deedUrl] see {@link #deedUrl}
|
2014-11-24 22:09:03 +00:00
|
|
|
* @param {boolean} [attributionRequired] see {@link #attributionRequired}
|
|
|
|
* @param {boolean} [nonFree] see {@link #nonFree}
|
2014-03-20 01:19:54 +00:00
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function License(
|
|
|
|
shortName,
|
|
|
|
internalName,
|
|
|
|
longName,
|
2014-11-24 22:09:03 +00:00
|
|
|
deedUrl,
|
|
|
|
attributionRequired,
|
|
|
|
nonFree
|
2014-03-20 01:19:54 +00:00
|
|
|
) {
|
|
|
|
if ( !shortName ) {
|
2017-05-03 09:15:05 +00:00
|
|
|
throw new Error( 'mw.mmv.model.License: shortName is required' );
|
2014-03-20 01:19:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @property {string} shortName short (abbreviated) name of the license (e.g. CC-BY-SA-3.0) */
|
|
|
|
this.shortName = shortName;
|
|
|
|
|
|
|
|
/** @property {string} internalName internal name of the license, used for localization (e.g. cc-by-sa ) */
|
|
|
|
this.internalName = internalName;
|
|
|
|
|
|
|
|
/** @property {string} longName full name of the license (e.g. Creative Commons etc. etc.) */
|
|
|
|
this.longName = longName;
|
|
|
|
|
|
|
|
/** @property {string} deedUrl URL to the description of the license (e.g. the CC deed) */
|
|
|
|
this.deedUrl = deedUrl;
|
2014-03-26 23:59:04 +00:00
|
|
|
|
2014-11-24 22:09:03 +00:00
|
|
|
/** @property {boolean} attributionRequired does the author need to be attributed on reuse? */
|
|
|
|
this.attributionRequired = attributionRequired;
|
|
|
|
|
|
|
|
/** @property {boolean} nonFree is this a non-free license? */
|
|
|
|
this.nonFree = nonFree;
|
|
|
|
|
2023-05-19 20:26:45 +00:00
|
|
|
/** @property {HtmlUtils} htmlUtils - */
|
|
|
|
this.htmlUtils = new HtmlUtils();
|
2014-03-20 01:19:54 +00:00
|
|
|
}
|
|
|
|
LP = License.prototype;
|
|
|
|
|
2014-04-19 00:25:12 +00:00
|
|
|
/**
|
|
|
|
* Check whether this is a Creative Commons license.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
|
|
|
* @return {boolean}
|
2014-04-19 00:25:12 +00:00
|
|
|
*/
|
|
|
|
LP.isCc = function () {
|
2022-05-19 23:05:49 +00:00
|
|
|
return this.internalName ? this.internalName.slice( 0, 2 ) === 'cc' : false;
|
2014-04-19 00:25:12 +00:00
|
|
|
};
|
|
|
|
|
2014-10-29 12:05:29 +00:00
|
|
|
/**
|
|
|
|
* Check whether this is a public domain "license".
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
|
|
|
* @return {boolean}
|
2014-10-29 12:05:29 +00:00
|
|
|
*/
|
|
|
|
LP.isPd = function () {
|
|
|
|
return this.internalName === 'pd';
|
|
|
|
};
|
|
|
|
|
2014-11-24 22:09:03 +00:00
|
|
|
/**
|
|
|
|
* Check whether this is a free license.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-11-24 22:09:03 +00:00
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
LP.isFree = function () {
|
|
|
|
// licenses with missing nonfree information are assumed free
|
|
|
|
return !this.nonFree;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether reusers need to attribute the author
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-11-24 22:09:03 +00:00
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
LP.needsAttribution = function () {
|
|
|
|
// to be on the safe side, if the attribution required flag is not set, it is assumed to be true
|
|
|
|
return !this.isPd() && this.attributionRequired !== false;
|
|
|
|
};
|
|
|
|
|
2014-03-21 20:29:55 +00:00
|
|
|
/**
|
|
|
|
* Returns the short name of the license:
|
|
|
|
* - if we have interface messages for this license (basically just CC and PD), use those
|
|
|
|
* - otherwise use the short name from the license template (might or might not be translated
|
|
|
|
* still, depending on how the template is set up)
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-03-21 20:29:55 +00:00
|
|
|
* @return {string}
|
|
|
|
* FIXME a model should not depend on an i18n class. We should probably use view models.
|
|
|
|
*/
|
2015-01-23 12:48:27 +00:00
|
|
|
LP.getShortName = function () {
|
2014-03-21 20:29:55 +00:00
|
|
|
var message = 'multimediaviewer-license-' + ( this.internalName || '' );
|
|
|
|
if ( mw.messages.exists( message ) ) {
|
2020-06-26 10:45:20 +00:00
|
|
|
// The following messages are used here:
|
|
|
|
// * multimediaviewer-license-cc-by-1.0
|
|
|
|
// * multimediaviewer-license-cc-sa-1.0
|
|
|
|
// * multimediaviewer-license-cc-by-sa-1.0
|
|
|
|
// * multimediaviewer-license-cc-by-2.0
|
|
|
|
// * multimediaviewer-license-cc-by-sa-2.0
|
|
|
|
// * multimediaviewer-license-cc-by-2.1
|
|
|
|
// * multimediaviewer-license-cc-by-sa-2.1
|
|
|
|
// * multimediaviewer-license-cc-by-2.5
|
|
|
|
// * multimediaviewer-license-cc-by-sa-2.5
|
|
|
|
// * multimediaviewer-license-cc-by-3.0
|
|
|
|
// * multimediaviewer-license-cc-by-sa-3.0
|
|
|
|
// * multimediaviewer-license-cc-by-4.0
|
|
|
|
// * multimediaviewer-license-cc-by-sa-4.0
|
|
|
|
// * multimediaviewer-license-cc-pd
|
|
|
|
// * multimediaviewer-license-cc-zero
|
|
|
|
// * multimediaviewer-license-pd
|
|
|
|
// * multimediaviewer-license-default
|
2014-03-21 20:29:55 +00:00
|
|
|
return mw.message( message ).text();
|
|
|
|
} else {
|
|
|
|
return this.shortName;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-20 01:19:54 +00:00
|
|
|
/**
|
|
|
|
* Returns a short HTML representation of the license.
|
2016-07-18 13:49:27 +00:00
|
|
|
*
|
2014-03-20 01:19:54 +00:00
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
LP.getShortLink = function () {
|
2014-12-01 20:15:17 +00:00
|
|
|
var shortName = this.getShortName();
|
|
|
|
|
2014-03-20 01:19:54 +00:00
|
|
|
if ( this.deedUrl ) {
|
2016-06-19 11:46:00 +00:00
|
|
|
return this.htmlUtils.makeLinkText( shortName, {
|
|
|
|
href: this.deedUrl,
|
|
|
|
title: this.longName || shortName
|
|
|
|
} );
|
2014-03-20 01:19:54 +00:00
|
|
|
} else {
|
2014-12-01 20:15:17 +00:00
|
|
|
return shortName;
|
2014-03-20 01:19:54 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-05-19 20:26:45 +00:00
|
|
|
module.exports = License;
|
2018-11-12 16:33:24 +00:00
|
|
|
}() );
|