mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-17 04:43:18 +00:00
Merge "Show custom Attribution line instead of Author/Credit when available"
This commit is contained in:
commit
af4f85a326
|
@ -78,16 +78,21 @@
|
||||||
* Byline construction
|
* Byline construction
|
||||||
* @param {string} [author] author name (can contain HTML)
|
* @param {string} [author] author name (can contain HTML)
|
||||||
* @param {string} [source] source name (can contain HTML)
|
* @param {string} [source] source name (can contain HTML)
|
||||||
|
* @param {string} [attribution] custom attribution line (can contain HTML)
|
||||||
* @param {Function} [formatterFunction] Format function for the text - defaults to whitelisting HTML links, but all else sanitized.
|
* @param {Function} [formatterFunction] Format function for the text - defaults to whitelisting HTML links, but all else sanitized.
|
||||||
* @return {string} Byline (can contain HTML)
|
* @return {string} Byline (can contain HTML)
|
||||||
*/
|
*/
|
||||||
EFFP.getByline = function ( author, source, formatterFunction ) {
|
EFFP.getByline = function ( author, source, attribution, formatterFunction ) {
|
||||||
var formatter = this;
|
var formatter = this;
|
||||||
|
|
||||||
formatterFunction = formatterFunction || function ( txt ) {
|
formatterFunction = formatterFunction || function ( txt ) {
|
||||||
return formatter.htmlUtils.htmlToTextWithLinks( txt );
|
return formatter.htmlUtils.htmlToTextWithLinks( txt );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if ( attribution ) {
|
||||||
|
attribution = attribution && formatterFunction( attribution );
|
||||||
|
return attribution;
|
||||||
|
} else {
|
||||||
author = author && formatterFunction( author );
|
author = author && formatterFunction( author );
|
||||||
source = source && formatterFunction( source );
|
source = source && formatterFunction( source );
|
||||||
|
|
||||||
|
@ -100,6 +105,7 @@
|
||||||
} else {
|
} else {
|
||||||
return author || source;
|
return author || source;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,7 +118,7 @@
|
||||||
formatter = this,
|
formatter = this,
|
||||||
titleText = info.imageInfo.title.getNameText(),
|
titleText = info.imageInfo.title.getNameText(),
|
||||||
titleUrl = this.getLinkUrl( info ),
|
titleUrl = this.getLinkUrl( info ),
|
||||||
byline = this.getByline( info.imageInfo.author, info.imageInfo.source, function ( txt ) {
|
byline = this.getByline( info.imageInfo.author, info.imageInfo.source, info.imageInfo.attribution, function ( txt ) {
|
||||||
return formatter.htmlUtils.htmlToText( txt );
|
return formatter.htmlUtils.htmlToText( txt );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
@ -152,7 +158,7 @@
|
||||||
titleText = info.imageInfo.title.getNameText(),
|
titleText = info.imageInfo.title.getNameText(),
|
||||||
titleUrl = this.getLinkUrl( info ),
|
titleUrl = this.getLinkUrl( info ),
|
||||||
$title = $( '<a>' ).text( titleText ).prop( 'href', titleUrl ),
|
$title = $( '<a>' ).text( titleText ).prop( 'href', titleUrl ),
|
||||||
byline = this.getByline( info.imageInfo.author, info.imageInfo.source );
|
byline = this.getByline( info.imageInfo.author, info.imageInfo.source, info.imageInfo.attribution );
|
||||||
|
|
||||||
creditParams = [
|
creditParams = [
|
||||||
'multimediaviewer-html-embed-credit-text-t',
|
'multimediaviewer-html-embed-credit-text-t',
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
* @param {number} authorCount
|
* @param {number} authorCount
|
||||||
* @param {mw.mmv.model.License} license
|
* @param {mw.mmv.model.License} license
|
||||||
* @param {string} permission
|
* @param {string} permission
|
||||||
|
* @param {string} attribution Custom attribution string that replaces credit line when set
|
||||||
* @param {number} latitude
|
* @param {number} latitude
|
||||||
* @param {number} longitude
|
* @param {number} longitude
|
||||||
*/
|
*/
|
||||||
|
@ -64,6 +65,7 @@
|
||||||
authorCount,
|
authorCount,
|
||||||
license,
|
license,
|
||||||
permission,
|
permission,
|
||||||
|
attribution,
|
||||||
latitude,
|
latitude,
|
||||||
longitude
|
longitude
|
||||||
) {
|
) {
|
||||||
|
@ -125,6 +127,9 @@
|
||||||
/** @property {string} additional license conditions by the author (note that this is usually a big ugly HTML blob) */
|
/** @property {string} additional license conditions by the author (note that this is usually a big ugly HTML blob) */
|
||||||
this.permission = permission;
|
this.permission = permission;
|
||||||
|
|
||||||
|
/** @property {string} attribution custom attribution string set by uploader that replaces credit line */
|
||||||
|
this.attribution = attribution;
|
||||||
|
|
||||||
/** @property {number} latitude The latitude of the place where the image was created */
|
/** @property {number} latitude The latitude of the place where the image was created */
|
||||||
this.latitude = latitude;
|
this.latitude = latitude;
|
||||||
|
|
||||||
|
@ -150,7 +155,7 @@
|
||||||
*/
|
*/
|
||||||
Image.newFromImageInfo = function ( title, imageInfo ) {
|
Image.newFromImageInfo = function ( title, imageInfo ) {
|
||||||
var name, uploadDateTime, anonymizedUploadDateTime, creationDateTime, imageData,
|
var name, uploadDateTime, anonymizedUploadDateTime, creationDateTime, imageData,
|
||||||
description, source, author, authorCount, license, permission,
|
description, source, author, authorCount, license, permission, attribution,
|
||||||
latitude, longitude,
|
latitude, longitude,
|
||||||
innerInfo = imageInfo.imageinfo[0],
|
innerInfo = imageInfo.imageinfo[0],
|
||||||
extmeta = innerInfo.extmetadata;
|
extmeta = innerInfo.extmetadata;
|
||||||
|
@ -176,6 +181,7 @@
|
||||||
|
|
||||||
license = this.newLicenseFromImageInfo( extmeta );
|
license = this.newLicenseFromImageInfo( extmeta );
|
||||||
permission = this.parseExtmeta( extmeta.Permission, 'string' );
|
permission = this.parseExtmeta( extmeta.Permission, 'string' );
|
||||||
|
attribution = this.parseExtmeta( extmeta.Attribution, 'string' );
|
||||||
|
|
||||||
latitude = this.parseExtmeta( extmeta.GPSLatitude, 'float' );
|
latitude = this.parseExtmeta( extmeta.GPSLatitude, 'float' );
|
||||||
longitude = this.parseExtmeta( extmeta.GPSLongitude, 'float' );
|
longitude = this.parseExtmeta( extmeta.GPSLongitude, 'float' );
|
||||||
|
@ -206,6 +212,7 @@
|
||||||
authorCount,
|
authorCount,
|
||||||
license,
|
license,
|
||||||
permission,
|
permission,
|
||||||
|
attribution,
|
||||||
latitude,
|
latitude,
|
||||||
longitude
|
longitude
|
||||||
);
|
);
|
||||||
|
|
|
@ -71,6 +71,7 @@
|
||||||
'GPSLatitude',
|
'GPSLatitude',
|
||||||
'GPSLongitude',
|
'GPSLongitude',
|
||||||
'Permission',
|
'Permission',
|
||||||
|
'Attribution',
|
||||||
'AttributionRequired',
|
'AttributionRequired',
|
||||||
'NonFree'
|
'NonFree'
|
||||||
].join('|');
|
].join('|');
|
||||||
|
|
|
@ -475,14 +475,17 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set source and author.
|
* Set source and author.
|
||||||
|
* @param {string} attribution Custom attribution string
|
||||||
* @param {string} source With unsafe HTML
|
* @param {string} source With unsafe HTML
|
||||||
* @param {string} author With unsafe HTML
|
* @param {string} author With unsafe HTML
|
||||||
* @param {number} authorCount
|
* @param {number} authorCount
|
||||||
* @param {string} filepageUrl URL of the file page (used when other data is not available)
|
* @param {string} filepageUrl URL of the file page (used when other data is not available)
|
||||||
*/
|
*/
|
||||||
MPP.setCredit = function ( source, author, authorCount, filepageUrl ) {
|
MPP.setCredit = function ( attribution, source, author, authorCount, filepageUrl ) {
|
||||||
// sanitization will be done by TruncatableTextField.set()
|
// sanitization will be done by TruncatableTextField.set()
|
||||||
if ( author && source ) {
|
if ( attribution && ( authorCount <= 1 || !authorCount ) ) {
|
||||||
|
this.creditField.set( this.wrapAttribution( attribution ) );
|
||||||
|
} else if ( author && source ) {
|
||||||
this.creditField.set(
|
this.creditField.set(
|
||||||
mw.message(
|
mw.message(
|
||||||
'multimediaviewer-credit',
|
'multimediaviewer-credit',
|
||||||
|
@ -546,6 +549,19 @@
|
||||||
return $wrapper.get( 0 ).outerHTML;
|
return $wrapper.get( 0 ).outerHTML;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wraps an attribution string with MediaViewer styles
|
||||||
|
* @param {string} attribution Warning - unsafe HTML sometimes goes here
|
||||||
|
* @return {string} unsafe HTML
|
||||||
|
*/
|
||||||
|
MPP.wrapAttribution = function ( attribution ) {
|
||||||
|
return $( '<span>' )
|
||||||
|
.addClass( 'mw-mmv-author' )
|
||||||
|
.addClass( 'mw-mmv-source' )
|
||||||
|
.append( $.parseHTML( attribution ) )
|
||||||
|
.get( 0 ).outerHTML;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the license display in the panel
|
* Sets the license display in the panel
|
||||||
* @param {mw.mmv.model.License|null} license license data (could be missing)
|
* @param {mw.mmv.model.License|null} license license data (could be missing)
|
||||||
|
@ -693,7 +709,7 @@
|
||||||
// these handle text truncation and should be called when everything that can push text down
|
// these handle text truncation and should be called when everything that can push text down
|
||||||
// (e.g. floated buttons) has already been laid out
|
// (e.g. floated buttons) has already been laid out
|
||||||
this.setTitle( image, imageData );
|
this.setTitle( image, imageData );
|
||||||
this.setCredit( imageData.source, imageData.author, imageData.authorCount, imageData.descriptionUrl );
|
this.setCredit( imageData.attribution, imageData.source, imageData.author, imageData.authorCount, imageData.descriptionUrl );
|
||||||
|
|
||||||
if ( imageData.permission ) {
|
if ( imageData.permission ) {
|
||||||
this.setPermission( imageData.permission );
|
this.setPermission( imageData.permission );
|
||||||
|
|
|
@ -18,16 +18,22 @@
|
||||||
assert.ok( formatter, 'constructor with no argument works');
|
assert.ok( formatter, 'constructor with no argument works');
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( 'getByline():', 4, function ( assert ) {
|
QUnit.test( 'getByline():', 5, function ( assert ) {
|
||||||
var formatter = new mw.mmv.EmbedFileFormatter(),
|
var formatter = new mw.mmv.EmbedFileFormatter(),
|
||||||
author = '<span class="mw-mmv-author">Homer</span>',
|
author = '<span class="mw-mmv-author">Homer</span>',
|
||||||
source = '<span class="mw-mmv-source">Iliad</span>',
|
source = '<span class="mw-mmv-source">Iliad</span>',
|
||||||
|
attribution = '<span class="mw-mmv-attr">Cat</span>',
|
||||||
byline;
|
byline;
|
||||||
|
|
||||||
// Works with no arguments
|
// Works with no arguments
|
||||||
byline = formatter.getByline();
|
byline = formatter.getByline();
|
||||||
assert.strictEqual( byline, undefined, 'No argument case handled correctly.' );
|
assert.strictEqual( byline, undefined, 'No argument case handled correctly.' );
|
||||||
|
|
||||||
|
|
||||||
|
// Attribution present
|
||||||
|
byline = formatter.getByline( author, source, attribution );
|
||||||
|
assert.ok( byline.match ( /Cat/ ), 'Attribution found in bylines' );
|
||||||
|
|
||||||
// Author and source present
|
// Author and source present
|
||||||
byline = formatter.getByline( author, source );
|
byline = formatter.getByline( author, source );
|
||||||
assert.ok( byline.match ( /Homer|Iliad/ ), 'Author and source found in bylines' );
|
assert.ok( byline.match ( /Homer|Iliad/ ), 'Author and source found in bylines' );
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
( function( mw ) {
|
( function( mw ) {
|
||||||
QUnit.module( 'mmv.model.Image', QUnit.newMwEnvironment() );
|
QUnit.module( 'mmv.model.Image', QUnit.newMwEnvironment() );
|
||||||
|
|
||||||
QUnit.test( 'Image model constructor sanity check', 22, function ( assert ) {
|
QUnit.test( 'Image model constructor sanity check', 23, function ( assert ) {
|
||||||
var
|
var
|
||||||
title = mw.Title.newFromText( 'File:Foobar.jpg' ),
|
title = mw.Title.newFromText( 'File:Foobar.jpg' ),
|
||||||
name = 'Foo bar',
|
name = 'Foo bar',
|
||||||
|
@ -39,12 +39,13 @@
|
||||||
authorCount = 1,
|
authorCount = 1,
|
||||||
permission = 'only use for good, not evil',
|
permission = 'only use for good, not evil',
|
||||||
license = new mw.mmv.model.License( 'cc0' ),
|
license = new mw.mmv.model.License( 'cc0' ),
|
||||||
|
attribution = 'Created by my cats on a winter morning',
|
||||||
latitude = 39.12381283,
|
latitude = 39.12381283,
|
||||||
longitude = 100.983829,
|
longitude = 100.983829,
|
||||||
imageData = new mw.mmv.model.Image(
|
imageData = new mw.mmv.model.Image(
|
||||||
title, name, size, width, height, mime, url,
|
title, name, size, width, height, mime, url,
|
||||||
descurl, repo, user, datetime, anondatetime, origdatetime,
|
descurl, repo, user, datetime, anondatetime, origdatetime,
|
||||||
description, source, author, authorCount, license, permission,
|
description, source, author, authorCount, license, permission, attribution,
|
||||||
latitude, longitude );
|
latitude, longitude );
|
||||||
|
|
||||||
assert.strictEqual( imageData.title, title, 'Title is set correctly' );
|
assert.strictEqual( imageData.title, title, 'Title is set correctly' );
|
||||||
|
@ -66,6 +67,7 @@
|
||||||
assert.strictEqual( imageData.authorCount, authorCount, 'Author is set correctly' );
|
assert.strictEqual( imageData.authorCount, authorCount, 'Author is set correctly' );
|
||||||
assert.strictEqual( imageData.license, license, 'License is set correctly' );
|
assert.strictEqual( imageData.license, license, 'License is set correctly' );
|
||||||
assert.strictEqual( imageData.permission, permission, 'Permission is set correctly' );
|
assert.strictEqual( imageData.permission, permission, 'Permission is set correctly' );
|
||||||
|
assert.strictEqual( imageData.attribution, attribution, 'Attribution is set correctly' );
|
||||||
assert.strictEqual( imageData.latitude, latitude, 'Latitude is set correctly' );
|
assert.strictEqual( imageData.latitude, latitude, 'Latitude is set correctly' );
|
||||||
assert.strictEqual( imageData.longitude, longitude, 'Longitude is set correctly' );
|
assert.strictEqual( imageData.longitude, longitude, 'Longitude is set correctly' );
|
||||||
assert.ok( imageData.thumbUrls, 'Thumb URL cache is set up properly' );
|
assert.ok( imageData.thumbUrls, 'Thumb URL cache is set up properly' );
|
||||||
|
@ -77,13 +79,13 @@
|
||||||
mw.Title.newFromText( 'File:Foobar.pdf.jpg' ), 'Foo bar',
|
mw.Title.newFromText( 'File:Foobar.pdf.jpg' ), 'Foo bar',
|
||||||
10, 10, 10, 'image/jpeg', 'http://example.org', 'http://example.com',
|
10, 10, 10, 'image/jpeg', 'http://example.org', 'http://example.com',
|
||||||
'example', 'tester', '2013-11-10', '20131110', '2013-11-09', 'Blah blah blah',
|
'example', 'tester', '2013-11-10', '20131110', '2013-11-09', 'Blah blah blah',
|
||||||
'A person', 'Another person', 1, 'CC-BY-SA-3.0', 'Permitted'
|
'A person', 'Another person', 1, 'CC-BY-SA-3.0', 'Permitted', 'My cat'
|
||||||
),
|
),
|
||||||
secondImageData = new mw.mmv.model.Image(
|
secondImageData = new mw.mmv.model.Image(
|
||||||
mw.Title.newFromText( 'File:Foobar.pdf.jpg' ), 'Foo bar',
|
mw.Title.newFromText( 'File:Foobar.pdf.jpg' ), 'Foo bar',
|
||||||
10, 10, 10, 'image/jpeg', 'http://example.org', 'http://example.com',
|
10, 10, 10, 'image/jpeg', 'http://example.org', 'http://example.com',
|
||||||
'example', 'tester', '2013-11-10', '20131110', '2013-11-09', 'Blah blah blah',
|
'example', 'tester', '2013-11-10', '20131110', '2013-11-09', 'Blah blah blah',
|
||||||
'A person', 'Another person', 1, 'CC-BY-SA-3.0', 'Permitted',
|
'A person', 'Another person', 1, 'CC-BY-SA-3.0', 'Permitted', 'My cat',
|
||||||
'39.91820938', '78.09812938'
|
'39.91820938', '78.09812938'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue