diff --git a/resources/mmv/model/mmv.model.Image.js b/resources/mmv/model/mmv.model.Image.js index 1e26c6d81..32ffa0826 100644 --- a/resources/mmv/model/mmv.model.Image.js +++ b/resources/mmv/model/mmv.model.Image.js @@ -251,15 +251,6 @@ return this.thumbUrls[width]; }; - /** - * Check whether the image is CC-licensed. - * @returns {boolean} - */ - IP.isCcLicensed = function () { - return this.license && this.license.internalName && - this.license.internalName.substr( 0, 2 ) === 'cc'; - }; - /** * Check whether the image has geolocation data. * @returns {boolean} diff --git a/resources/mmv/model/mmv.model.License.js b/resources/mmv/model/mmv.model.License.js index 85517f7cd..09b9b8341 100644 --- a/resources/mmv/model/mmv.model.License.js +++ b/resources/mmv/model/mmv.model.License.js @@ -55,6 +55,14 @@ } LP = License.prototype; + /** + * Check whether this is a Creative Commons license. + * @returns {boolean} + */ + LP.isCc = function () { + return this.internalName && this.internalName.substr( 0, 2 ) === 'cc'; + }; + /** * Returns the short name of the license: * - if we have interface messages for this license (basically just CC and PD), use those diff --git a/resources/mmv/ui/mmv.ui.metadataPanel.js b/resources/mmv/ui/mmv.ui.metadataPanel.js index 53b9ed2eb..d13a9830d 100644 --- a/resources/mmv/ui/mmv.ui.metadataPanel.js +++ b/resources/mmv/ui/mmv.ui.metadataPanel.js @@ -540,23 +540,25 @@ this.setCredit( this.source, author ); }; - /** - * Sets the license data in the DOM - * @param {string} license The license this file has. - */ - MPP.setLicenseData = function ( license ) { - this.$license.data( 'license', license ); - }; - /** * Sets the license display in the panel - * @param {string} license The human-readable name of the license - * @param {string} url The URL to the license deed. - * @param {boolean} isCc Whether this is a CC license + * @param {mw.mmv.model.License|null} license license data (could be missing) + * @param {string} filePageUrl URL of the file description page */ - MPP.setLicense = function ( license, url, isCc ) { + MPP.setLicense = function ( license, filePageUrl ) { + var message, shortName, url, isCc; + + message = 'multimediaviewer-license-' + ( license.internalName || '' ); + if ( mw.messages.exists( message ) ) { + shortName = mw.message( message ).text(); + } else { + shortName = mw.message( 'multimediaviewer-license-default' ).text(); + } + url = license.deedUrl || filePageUrl; + isCc = license.isCc(); + this.$license - .text( license ) + .text( shortName ) .toggleClass( 'cc-license', isCc ) .prop( 'href', url ); @@ -654,8 +656,7 @@ * @param {mw.mmv.model.User} user */ MPP.setImageInfo = function ( image, imageData, repoData, localUsage, globalUsage, user ) { - var msgname, - panel = this, + var panel = this, fileTitle = image.filePageTitle; this.setFileTitle( fileTitle.getNameText() ); @@ -690,22 +691,8 @@ this.description.set( imageData.description, image.caption ); this.categories.set( repoData.getArticlePath(), imageData.categories ); - msgname = 'multimediaviewer-license-' + ( imageData.license && imageData.license.internalName || '' ); - - if ( !mw.messages.exists( msgname ) ) { - // Cannot display, fallback or fail - msgname = 'multimediaviewer-license-default'; - } else { - // License found, store the license data - this.setLicenseData( mw.message( msgname ).text() ); - } - if ( imageData.license ) { - this.setLicense( - mw.message( msgname ).text(), - imageData.license.deedUrl || imageData.descriptionUrl, - imageData.isCcLicensed() - ); + this.setLicense( imageData.license, imageData.descriptionUrl ); } if ( imageData.permission ) { diff --git a/tests/qunit/mmv/ui/mmv.ui.metadataPanel.test.js b/tests/qunit/mmv/ui/mmv.ui.metadataPanel.test.js index 994d0ea8f..dcc72b0d9 100644 --- a/tests/qunit/mmv/ui/mmv.ui.metadataPanel.test.js +++ b/tests/qunit/mmv/ui/mmv.ui.metadataPanel.test.js @@ -161,7 +161,6 @@ imageData.uploadDateTime = '2013-08-25T14:41:02Z'; imageData.source = 'LostBar'; imageData.author = 'Bob'; - imageData.isCcLicensed = function() { return true; }; imageData.license = new mw.mmv.model.License( 'CC-BY-2.0', 'cc-by-2.0' ); gender = 'female'; imageData.lastUploader = 'Ursula';