Shorten MediaViewer credit lines

Drop the title and site name. Use a shortened URL
created using the pageID for the curid query parameter.

Add pageID property to mmv.model.Image, using value already
fetched from an existing API request.

Bug: T119686
Depends-On: I0f00b986e6095bdb9b8d6af6fbc5b01995227e02
Change-Id: I9189f00bfbf7639974d66cf1921773855a77a865
This commit is contained in:
Andrew H 2015-12-24 20:35:52 +00:00
parent f937b1f20d
commit 1b2866df0d
7 changed files with 84 additions and 124 deletions

View file

@ -234,28 +234,12 @@
], ],
"messages": [ "messages": [
"multimediaviewer-credit", "multimediaviewer-credit",
"multimediaviewer-text-embed-credit-text-tbls", "multimediaviewer-text-embed-credit-text-bl",
"multimediaviewer-text-embed-credit-text-tbls-nonfree", "multimediaviewer-text-embed-credit-text-b",
"multimediaviewer-text-embed-credit-text-tls", "multimediaviewer-text-embed-credit-text-l",
"multimediaviewer-text-embed-credit-text-tls-nonfree", "multimediaviewer-html-embed-credit-text-bl",
"multimediaviewer-text-embed-credit-text-tbs", "multimediaviewer-html-embed-credit-text-b",
"multimediaviewer-text-embed-credit-text-tbl", "multimediaviewer-html-embed-credit-text-l"
"multimediaviewer-text-embed-credit-text-tbl-nonfree",
"multimediaviewer-text-embed-credit-text-tb",
"multimediaviewer-text-embed-credit-text-ts",
"multimediaviewer-text-embed-credit-text-tl",
"multimediaviewer-text-embed-credit-text-tl-nonfree",
"multimediaviewer-html-embed-credit-text-tbls",
"multimediaviewer-html-embed-credit-text-tbls-nonfree",
"multimediaviewer-html-embed-credit-text-tls",
"multimediaviewer-html-embed-credit-text-tls-nonfree",
"multimediaviewer-html-embed-credit-text-tbs",
"multimediaviewer-html-embed-credit-text-tbl",
"multimediaviewer-html-embed-credit-text-tbl-nonfree",
"multimediaviewer-html-embed-credit-text-tb",
"multimediaviewer-html-embed-credit-text-ts",
"multimediaviewer-html-embed-credit-text-tl",
"multimediaviewer-html-embed-credit-text-tl-nonfree"
] ]
}, },
"mmv.ui.download.pane": { "mmv.ui.download.pane": {

View file

@ -90,30 +90,12 @@
"multimediaviewer-embed-wt": "Wikitext", "multimediaviewer-embed-wt": "Wikitext",
"multimediaviewer-embed-html": "HTML", "multimediaviewer-embed-html": "HTML",
"multimediaviewer-embed-explanation": "Use this code to embed the file", "multimediaviewer-embed-explanation": "Use this code to embed the file",
"multimediaviewer-text-embed-credit-text-tbls": "\"$1\" by $2. Licensed under $3 via $4", "multimediaviewer-text-embed-credit-text-bl": "By $1, $2, $3",
"multimediaviewer-text-embed-credit-text-tbls-nonfree": "\"$1\" by $2. $3 via $4", "multimediaviewer-text-embed-credit-text-b": "By $1, $2",
"multimediaviewer-text-embed-credit-text-tls": "\"$1\". Licensed under $2 via $3", "multimediaviewer-text-embed-credit-text-l": "$1, $2",
"multimediaviewer-text-embed-credit-text-tls-nonfree": "\"$1\". $2 via $3", "multimediaviewer-html-embed-credit-text-bl": "By $1, $2, $3",
"multimediaviewer-text-embed-credit-text-tbs": "\"$1\" by $2. Via $3", "multimediaviewer-html-embed-credit-text-b": "By $1, $2",
"multimediaviewer-text-embed-credit-text-tbl": "\"$1\" by $2. Licensed under $3", "multimediaviewer-html-embed-credit-text-l": "$1, $2",
"multimediaviewer-text-embed-credit-text-tbl-nonfree": "\"$1\" by $2. $3",
"multimediaviewer-text-embed-credit-text-tb": "\"$1\" by $2",
"multimediaviewer-text-embed-credit-text-ts": "\"$1\". Via $2",
"multimediaviewer-text-embed-credit-text-tl": "\"$1\". Licensed under $2",
"multimediaviewer-text-embed-credit-text-tl-nonfree": "\"$1\". $2",
"multimediaviewer-text-embed-credit-text-t": "\"$1\"",
"multimediaviewer-html-embed-credit-text-tbls": "\"$1\" by $2. Licensed under $3 via $4.",
"multimediaviewer-html-embed-credit-text-tbls-nonfree": "\"$1\" by $2. $3 via $4.",
"multimediaviewer-html-embed-credit-text-tls": "\"$1\". Licensed under $2 via $3.",
"multimediaviewer-html-embed-credit-text-tls-nonfree": "\"$1\". $2 via $3.",
"multimediaviewer-html-embed-credit-text-tbs": "\"$1\" by $2. Via $3.",
"multimediaviewer-html-embed-credit-text-tbl": "\"$1\" by $2. Licensed under $3.",
"multimediaviewer-html-embed-credit-text-tbl-nonfree": "\"$1\" by $2. $3.",
"multimediaviewer-html-embed-credit-text-tb": "\"$1\" by $2.",
"multimediaviewer-html-embed-credit-text-ts": "\"$1\". Via $2.",
"multimediaviewer-html-embed-credit-text-tl": "\"$1\". Licensed under $2.",
"multimediaviewer-html-embed-credit-text-tl-nonfree": "\"$1\". $2.",
"multimediaviewer-html-embed-credit-text-t": "\"$1\".",
"multimediaviewer-embed-byline": "By $1", "multimediaviewer-embed-byline": "By $1",
"multimediaviewer-embed-license": "Licensed under $1.", "multimediaviewer-embed-license": "Licensed under $1.",
"multimediaviewer-embed-license-nonfree": "$1.", "multimediaviewer-embed-license-nonfree": "$1.",

View file

@ -99,30 +99,12 @@
"multimediaviewer-embed-wt": "Used to represent a choice for embedding a file in a wiki page, as wikitext.\n{{Identical|Wikitext}}", "multimediaviewer-embed-wt": "Used to represent a choice for embedding a file in a wiki page, as wikitext.\n{{Identical|Wikitext}}",
"multimediaviewer-embed-html": "Used to represent a choice for embedding a file in an HTML document, as HTML.\n{{Identical|HTML}}", "multimediaviewer-embed-html": "Used to represent a choice for embedding a file in an HTML document, as HTML.\n{{Identical|HTML}}",
"multimediaviewer-embed-explanation": "Used below the embed textarea to explain what we expect the user to do.", "multimediaviewer-embed-explanation": "Used below the embed textarea to explain what we expect the user to do.",
"multimediaviewer-text-embed-credit-text-tbls": "Credit text, used when generating plain text for attributing an image.\n\nWhich one of the multimediaviewer-text-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the author\n* $3 - name of the license\n* $4 - name of the website/institution which was the direct source for this image. This parameter is usually an URL.\n{{Related|Multimediaviewer-embed-credit-text}}", "multimediaviewer-text-embed-credit-text-bl": "Credit text, used when generating plain text for attributing an image - used as a caption, not in the middle of a sentence.\n\nWhich one of the multimediaviewer-text-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the author\n* $2 - copyright tag (usually a license)\n* $3 - URL to the image source.\n{{Related|Multimediaviewer-embed-credit-text}}",
"multimediaviewer-text-embed-credit-text-tbls-nonfree": "Like {{msg-mw|multimediaviewer-text-embed-credit-text-tbls}}, but for non-free images (where $3 is typically not a license name but something like \"Fair use\").\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the author\n* $3 - name of the license\n* $4 - name of the website/institution which was the direct source for this image. This parameter is usually an URL.", "multimediaviewer-text-embed-credit-text-b": "Credit text, used when generating plain text for attributing an image - used as a caption, not in the middle of a sentence.\n\nWhich one of the multimediaviewer-text-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the author\n* $2 - URL to the image source.\n{{Related|Multimediaviewer-embed-credit-text}}",
"multimediaviewer-text-embed-credit-text-tls": "Credit text, used when generating plain text to attribute an image.\n\nWhich one of the multimediaviewer-text-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the license\n* $3 - name of the website/institution which was the direct source for this image. This parameter is usually an URL.\n{{Related|Multimediaviewer-embed-credit-text}}", "multimediaviewer-text-embed-credit-text-l": "Credit text, used when generating plain text for attributing an image - used as a caption, not in the middle of a sentence.\n\nWhich one of the multimediaviewer-text-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - copyright tag (usually a license)\n* $2 - URL to the image source.\n{{Related|Multimediaviewer-embed-credit-text}}",
"multimediaviewer-text-embed-credit-text-tls-nonfree": "Like {{msg-mw|multimediaviewer-text-embed-credit-text-tls}}, but for non-free images, so $2 is typically not a real license name but something like \"Fair use\".\n{{Identical|Via}}\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the license, or something like \"Fair use\"\n* $3 - name of the website/institution which was the direct source for this image. This parameter is usually an URL.", "multimediaviewer-html-embed-credit-text-bl": "Credit text, used when generating HTML to reuse an image - used as a caption, not in the middle of a sentence.\n\nWhich one of the multimediaviewer-html-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the author\n* $2 - copyright tag (usually a license)\n* $3 - URL to the image source\nEach of the parameters could be either plain text or a link.\n{{Related|Multimediaviewer-embed-credit-text}}",
"multimediaviewer-text-embed-credit-text-tbs": "Credit text, used when generating plain text to attribute an image.\n\nWhich one of the multimediaviewer-text-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the author\n* $3 - name of the website/institution which was the direct source for this image. This parameter is usually an URL.\n{{Related|Multimediaviewer-embed-credit-text}}", "multimediaviewer-html-embed-credit-text-b": "Credit text, used when generating HTML to reuse an image - used as a caption, not in the middle of a sentence.\n\nWhich one of the multimediaviewer-html-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the author\n* $2 - URL to the image source\nEach of the parameters could be either plain text or a link.\n{{Related|Multimediaviewer-embed-credit-text}}",
"multimediaviewer-text-embed-credit-text-tbl": "Credit text, used when generating plain text to attribute an image.\n\nWhich one of the multimediaviewer-text-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the author\n* $3 - name of the license\n{{Related|Multimediaviewer-embed-credit-text}}", "multimediaviewer-html-embed-credit-text-l": "Credit text, used when generating HTML to reuse an image - used as a caption, not in the middle of a sentence.\n\nWhich one of the multimediaviewer-html-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - copyright tag (usually a license)\n* $2 - URL to the image source\nEach of the parameters could be either plain text or a link.\n{{Related|Multimediaviewer-embed-credit-text}}",
"multimediaviewer-text-embed-credit-text-tbl-nonfree": "Like {{msg-mw|multimediaviewer-text-embed-credit-text-tbl}}, but for non-free images, so $3 is typically not a license name but something like \"Fair use\".\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the author\n* $3 - name of the license or something like \"Fair use\".",
"multimediaviewer-text-embed-credit-text-tb": "Credit text, used when generating plain text to attribute an image.\n\nWhich one of the multimediaviewer-text-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the author\n{{Related|Multimediaviewer-embed-credit-text}}",
"multimediaviewer-text-embed-credit-text-ts": "Credit text, used when generating plain text to attribute an image.\n\nWhich one of the multimediaviewer-text-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the website/institution which was the direct source for this image. This parameter is usually an URL.\n{{Related|Multimediaviewer-embed-credit-text}}",
"multimediaviewer-text-embed-credit-text-tl": "Credit text, used when generating plain text to attribute an image.\n\nWhich one of the multimediaviewer-text-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the license\n{{Related|Multimediaviewer-embed-credit-text}}",
"multimediaviewer-text-embed-credit-text-tl-nonfree": "Like {{msg-mw|multimediaviewer-text-embed-credit-text-tl}}, but for non-free images (where $2 is typically not a license name but something like \"Fair use\").",
"multimediaviewer-text-embed-credit-text-t": "Credit text, used when generating plain text to attribute an image.\n\nWhich one of the multimediaviewer-text-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n{{Related|Multimediaviewer-embed-credit-text}}",
"multimediaviewer-html-embed-credit-text-tbls": "Credit text, used when generating HTML to reuse an image.\n\nWhich one of the multimediaviewer-html-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the author\n* $3 - name of the license\n* $4 - name of the website/institution which was the direct source for this image\nEach of the parameters could be either plain text or a link.\n{{Related|Multimediaviewer-embed-credit-text}}",
"multimediaviewer-html-embed-credit-text-tbls-nonfree": "Like {{msg-mw|multimediaviewer-html-embed-credit-text-tbls}}, but for non-free images, so $3 is typically not a license name but something like \"Fair use\".\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the author\n* $3 - name of the license or something like \"Fair use\"\n* $4 - name of the website/institution which was the direct source for this image\n\nEach of the parameters could be either plain text or a link.",
"multimediaviewer-html-embed-credit-text-tls": "Credit text, used when generating HTML to reuse an image.\n\nWhich one of the multimediaviewer-html-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the license\n* $3 - name of the website/institution which was the direct source for this image\nEach of the parameters could be either plain text or a link.\n{{Related|Multimediaviewer-embed-credit-text}}",
"multimediaviewer-html-embed-credit-text-tls-nonfree": "Like {{msg-mw|multimediaviewer-html-embed-credit-text-tls}}, but for non-free images, so $2 is typically not a license name but something like \"Fair use\".\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the license or something like \"Fair use\"\n* $3 - name of the website/institution which was the direct source for this image\nEach of the parameters could be either plain text or a link.\n\n\n{{Identical|Via}}",
"multimediaviewer-html-embed-credit-text-tbs": "Credit text, used when generating HTML to reuse an image.\n\nWhich one of the multimediaviewer-html-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the author\n* $3 - name of the website/institution which was the direct source for this image\nEach of the parameters could be either plain text or a link.\n{{Related|Multimediaviewer-embed-credit-text}}",
"multimediaviewer-html-embed-credit-text-tbl": "Credit text, used when generating HTML to reuse an image.\n\nWhich one of the multimediaviewer-html-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the author\n* $3 - name of the license\nEach of the parameters could be either plain text or a link.\n{{Related|Multimediaviewer-embed-credit-text}}",
"multimediaviewer-html-embed-credit-text-tbl-nonfree": "Like {{msg-mw|multimediaviewer-html-embed-credit-text-tbl}}, but for non-free images, so $3 is typically not a license name but something like \"Fair use\".\n\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the author\n* $3 - name of the license or something like \"Fair use\"\nEach of the parameters could be either plain text or a link.",
"multimediaviewer-html-embed-credit-text-tb": "Credit text, used when generating HTML to reuse an image.\n\nWhich one of the multimediaviewer-html-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the author\nEach of the parameters could be either plain text or a link.\n{{Related|Multimediaviewer-embed-credit-text}}",
"multimediaviewer-html-embed-credit-text-ts": "Credit text, used when generating HTML to reuse an image.\n\nWhich one of the multimediaviewer-html-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the website/institution which was the direct source for this image\nEach of the parameters could be either plain text or a link.\n{{Related|Multimediaviewer-embed-credit-text}}",
"multimediaviewer-html-embed-credit-text-tl": "Credit text, used when generating HTML to reuse an image.\n\nWhich one of the multimediaviewer-html-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\n* $2 - name of the license\nEach of the parameters could be either plain text or a link.\n{{Related|Multimediaviewer-embed-credit-text}}",
"multimediaviewer-html-embed-credit-text-tl-nonfree": "Like {{msg-mw|multimediaviewer-html-embed-credit-text-tl}}, but for non-free images (where $2 is typically not a license name but something like \"Fair use\").",
"multimediaviewer-html-embed-credit-text-t": "Credit text, used when generating HTML to reuse an image.\n\nWhich one of the multimediaviewer-html-embed-credit-text-* messages is used will depend on what information about the image is available.\n\nParameters:\n* $1 - name of the work (typically the filename without an extension)\nEach of the parameters could be either plain text or a link.\n{{Related|Multimediaviewer-embed-credit-text}}",
"multimediaviewer-embed-byline": "Byline (author credit) text, used when generating wikitext/HTML to reuse the image. $1 is author name.\n{{Identical|By}}", "multimediaviewer-embed-byline": "Byline (author credit) text, used when generating wikitext/HTML to reuse the image. $1 is author name.\n{{Identical|By}}",
"multimediaviewer-embed-license": "License information, used when generating wikitext/HTML to reuse the image. $1 is the license name.", "multimediaviewer-embed-license": "License information, used when generating wikitext/HTML to reuse the image. $1 is the license name.",
"multimediaviewer-embed-license-nonfree": "Like {{msg-mw|multimediaviewer-embed-license}}, but for non-free images (where $1 is typically not a license name but something like \"Fair use\").", "multimediaviewer-embed-license-nonfree": "Like {{msg-mw|multimediaviewer-embed-license}}, but for non-free images (where $1 is typically not a license name but something like \"Fair use\").",

View file

@ -118,33 +118,32 @@
EFFP.getCreditText = function ( info ) { EFFP.getCreditText = function ( info ) {
var creditText, creditParams, var creditText, creditParams,
formatter = this, formatter = this,
titleText = info.imageInfo.title.getNameText(), shortURL = info.imageInfo.descriptionShortUrl,
titleUrl = this.getLinkUrl( info ), license = info.imageInfo.license,
byline = this.getByline( info.imageInfo.author, info.imageInfo.source, info.imageInfo.attribution, 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 );
} ); } );
// If both the byline and licence are missing, the credit text is simply the URL
if ( !byline && !license ) {
return shortURL;
}
creditParams = [ creditParams = [
'multimediaviewer-text-embed-credit-text-t', 'multimediaviewer-text-embed-credit-text-'
titleText
]; ];
if ( byline ) { if ( byline ) {
creditParams[0] += 'b'; creditParams[0] += 'b';
creditParams.push( byline ); creditParams.push( byline );
} }
if ( info.imageInfo.license ) {
if ( license ) {
creditParams[0] += 'l'; creditParams[0] += 'l';
creditParams.push( this.htmlUtils.htmlToText( info.imageInfo.license.getShortName() ) ); creditParams.push( this.htmlUtils.htmlToText( license.getShortName() ) );
}
creditParams[0] += 's';
creditParams.push( info.repoInfo.displayName + ' - ' + titleUrl );
if ( info.imageInfo.license && !info.imageInfo.license.isFree() ) {
creditParams[0] += '-nonfree';
} }
creditParams.push( shortURL );
creditText = mw.message.apply( mw, creditParams ).plain(); creditText = mw.message.apply( mw, creditParams ).plain();
return creditText; return creditText;
@ -157,32 +156,28 @@
*/ */
EFFP.getCreditHtml = function ( info ) { EFFP.getCreditHtml = function ( info ) {
var creditText, creditParams, var creditText, creditParams,
titleText = info.imageInfo.title.getNameText(), shortURL = info.imageInfo.descriptionShortUrl,
titleUrl = this.getLinkUrl( info ), license = info.imageInfo.license,
$title = $( '<a>' ).text( titleText ).prop( 'href', titleUrl ),
byline = this.getByline( info.imageInfo.author, info.imageInfo.source, info.imageInfo.attribution ); byline = this.getByline( info.imageInfo.author, info.imageInfo.source, info.imageInfo.attribution );
if ( !byline && !license ) {
return shortURL;
}
creditParams = [ creditParams = [
'multimediaviewer-html-embed-credit-text-t', 'multimediaviewer-html-embed-credit-text-'
this.htmlUtils.jqueryToHtml( $title )
]; ];
if ( byline ) { if ( byline ) {
creditParams[0] += 'b'; creditParams[0] += 'b';
creditParams.push( byline ); creditParams.push( byline );
} }
if ( info.imageInfo.license ) { if ( license ) {
creditParams[0] += 'l'; creditParams[0] += 'l';
creditParams.push( info.imageInfo.license.getShortLink() ); creditParams.push( license.getShortLink() );
}
creditParams[0] += 's';
creditParams.push( this.getSiteLink( info ) );
if ( info.imageInfo.license && !info.imageInfo.license.isFree() ) {
creditParams[0] += '-nonfree';
} }
creditParams.push( shortURL );
creditText = mw.message.apply( mw, creditParams ).plain(); creditText = mw.message.apply( mw, creditParams ).plain();
return creditText; return creditText;

View file

@ -54,6 +54,8 @@
mimeType, mimeType,
url, url,
descriptionUrl, descriptionUrl,
descriptionShortUrl,
pageID,
repo, repo,
uploadDateTime, uploadDateTime,
anonymizedUploadDateTime, anonymizedUploadDateTime,
@ -93,6 +95,12 @@
/** @property {string} descriptionUrl The URL to the description page for the image */ /** @property {string} descriptionUrl The URL to the description page for the image */
this.descriptionUrl = descriptionUrl; this.descriptionUrl = descriptionUrl;
/** @property {string} descriptionShortUrl A short URL to the description page for the image, using curid=... */
this.descriptionShortUrl = descriptionShortUrl;
/** @property {number} pageId of the description page for the image */
this.pageID = pageID;
/** @property {string} repo The name of the repository where this image is stored */ /** @property {string} repo The name of the repository where this image is stored */
this.repo = repo; this.repo = repo;
@ -202,6 +210,8 @@
innerInfo.mime, innerInfo.mime,
innerInfo.url, innerInfo.url,
innerInfo.descriptionurl, innerInfo.descriptionurl,
innerInfo.descriptionshorturl,
imageInfo.pageid,
imageInfo.imagerepository, imageInfo.imagerepository,
uploadDateTime, uploadDateTime,
anonymizedUploadDateTime, anonymizedUploadDateTime,

View file

@ -14,6 +14,8 @@
undefined, undefined,
options.imgUrl, options.imgUrl,
options.filePageUrl, options.filePageUrl,
options.shortFilePageUrl,
42,
'repo', 'repo',
undefined, undefined,
undefined, undefined,
@ -81,6 +83,7 @@
title = mw.Title.newFromText( titleText ), title = mw.Title.newFromText( titleText ),
imgUrl = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg', imgUrl = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
filePageUrl = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg', filePageUrl = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg',
filePageShortUrl = 'https://commons.wikimedia.org/wiki/index.php?curid=42',
siteName = 'Site Name', siteName = 'Site Name',
siteUrl = '//site.url/', siteUrl = '//site.url/',
licenseShortName = 'Public License', licenseShortName = 'Public License',
@ -97,68 +100,69 @@
// Bylines, license and site // Bylines, license and site
info = createEmbedFileInfo( { title: title, imgUrl: imgUrl, filePageUrl: filePageUrl, info = createEmbedFileInfo( { title: title, imgUrl: imgUrl, filePageUrl: filePageUrl,
siteName: siteName, siteUrl: siteUrl, licenseShortName: licenseShortName, shortFilePageUrl: filePageShortUrl, siteName: siteName, siteUrl: siteUrl,
licenseInternalName: licenseInternalName, licenseLongName: licenseLongName, licenseShortName: licenseShortName, licenseInternalName: licenseInternalName,
licenseUrl: licenseUrl, author: author, source: source } ); licenseLongName: licenseLongName, licenseUrl: licenseUrl, author: author, source: source } );
generatedHtml = formatter.getThumbnailHtml( info, thumbUrl, width, height );
generatedHtml = formatter.getThumbnailHtml( info, thumbUrl, width, height );
assert.ok( generatedHtml.match( titleText ), 'Title appears in generated HTML.' ); assert.ok( generatedHtml.match( titleText ), 'Title appears in generated HTML.' );
assert.ok( generatedHtml.match( filePageUrl ), 'Page url appears in generated HTML.' ); assert.ok( generatedHtml.match( filePageUrl ), 'Page url appears in generated HTML.' );
assert.ok( generatedHtml.match( thumbUrl ), 'Thumbnail url appears in generated HTML' ); assert.ok( generatedHtml.match( thumbUrl ), 'Thumbnail url appears in generated HTML' );
assert.ok( generatedHtml.match( siteName ), 'Site name appears in generated HTML' );
assert.ok( generatedHtml.match( 'Public License' ), 'License appears in generated HTML' ); assert.ok( generatedHtml.match( 'Public License' ), 'License appears in generated HTML' );
assert.ok( generatedHtml.match( 'Homer' ), 'Author appears in generated HTML' ); assert.ok( generatedHtml.match( 'Homer' ), 'Author appears in generated HTML' );
assert.ok( generatedHtml.match( 'Iliad' ), 'Source appears in generated HTML' ); assert.ok( generatedHtml.match( 'Iliad' ), 'Source appears in generated HTML' );
assert.ok( generatedHtml.match( width ), 'Width appears in generated HTML' ); assert.ok( generatedHtml.match( width ), 'Width appears in generated HTML' );
assert.ok( generatedHtml.match( height ), 'Height appears in generated HTML' ); assert.ok( generatedHtml.match( height ), 'Height appears in generated HTML' );
// .includes() for checking the short url since it contains a ? (bad for regex). Could escape instead.
assert.ok( generatedHtml.includes( filePageShortUrl ), 'Short URL appears in generated HTML');
// Bylines, no license and site // Bylines, no license and site
info = createEmbedFileInfo( { title: title, imgUrl: imgUrl, filePageUrl: filePageUrl, info = createEmbedFileInfo( { title: title, imgUrl: imgUrl, filePageUrl: filePageUrl,
siteName: siteName, siteUrl: siteUrl, shortFilePageUrl: filePageShortUrl, siteName: siteName, siteUrl: siteUrl,
author: author, source: source } ); author: author, source: source } );
generatedHtml = formatter.getThumbnailHtml( info, thumbUrl, width, height ); generatedHtml = formatter.getThumbnailHtml( info, thumbUrl, width, height );
assert.ok( generatedHtml.match( titleText ), 'Title appears in generated HTML.' ); assert.ok( generatedHtml.match( titleText ), 'Title appears in generated HTML.' );
assert.ok( generatedHtml.match( filePageUrl ), 'Page url appears in generated HTML.' ); assert.ok( generatedHtml.match( filePageUrl ), 'Page url appears in generated HTML.' );
assert.ok( generatedHtml.match( thumbUrl ), 'Thumbnail url appears in generated HTML' ); assert.ok( generatedHtml.match( thumbUrl ), 'Thumbnail url appears in generated HTML' );
assert.ok( generatedHtml.match( siteName ), 'Site name appears in generated HTML' );
assert.ok( !generatedHtml.match( 'Public License' ), 'License should not appear in generated HTML' ); assert.ok( !generatedHtml.match( 'Public License' ), 'License should not appear in generated HTML' );
assert.ok( generatedHtml.match( 'Homer' ), 'Author appears in generated HTML' ); assert.ok( generatedHtml.match( 'Homer' ), 'Author appears in generated HTML' );
assert.ok( generatedHtml.match( 'Iliad' ), 'Source appears in generated HTML' ); assert.ok( generatedHtml.match( 'Iliad' ), 'Source appears in generated HTML' );
assert.ok( generatedHtml.match( width ), 'Width appears in generated HTML' ); assert.ok( generatedHtml.match( width ), 'Width appears in generated HTML' );
assert.ok( generatedHtml.match( height ), 'Height appears in generated HTML' ); assert.ok( generatedHtml.match( height ), 'Height appears in generated HTML' );
assert.ok( generatedHtml.includes( filePageShortUrl ), 'Short URL appears in generated HTML');
// No bylines, license and site // No bylines, license and site
info = createEmbedFileInfo( { title: title, imgUrl: imgUrl, filePageUrl: filePageUrl, info = createEmbedFileInfo( { title: title, imgUrl: imgUrl, filePageUrl: filePageUrl,
siteName: siteName, siteUrl: siteUrl, licenseShortName: licenseShortName, siteName: siteName, siteUrl: siteUrl, licenseShortName: licenseShortName,
licenseInternalName: licenseInternalName, licenseLongName: licenseLongName, licenseInternalName: licenseInternalName, licenseLongName: licenseLongName,
licenseUrl: licenseUrl } ); licenseUrl: licenseUrl, shortFilePageUrl: filePageShortUrl } );
generatedHtml = formatter.getThumbnailHtml( info, thumbUrl, width, height ); generatedHtml = formatter.getThumbnailHtml( info, thumbUrl, width, height );
assert.ok( generatedHtml.match( titleText ), 'Title appears in generated HTML.' ); assert.ok( generatedHtml.match( titleText ), 'Title appears in generated HTML.' );
assert.ok( generatedHtml.match( filePageUrl ), 'Page url appears in generated HTML.' ); assert.ok( generatedHtml.match( filePageUrl ), 'Page url appears in generated HTML.' );
assert.ok( generatedHtml.match( thumbUrl ), 'Thumbnail url appears in generated HTML' ); assert.ok( generatedHtml.match( thumbUrl ), 'Thumbnail url appears in generated HTML' );
assert.ok( generatedHtml.match( siteName ), 'Site name appears in generated HTML' );
assert.ok( generatedHtml.match( 'Public License' ), 'License appears in generated HTML' ); assert.ok( generatedHtml.match( 'Public License' ), 'License appears in generated HTML' );
assert.ok( !generatedHtml.match( 'Homer' ), 'Author should not appear in generated HTML' ); assert.ok( !generatedHtml.match( 'Homer' ), 'Author should not appear in generated HTML' );
assert.ok( !generatedHtml.match( 'Iliad' ), 'Source should not appear in generated HTML' ); assert.ok( !generatedHtml.match( 'Iliad' ), 'Source should not appear in generated HTML' );
assert.ok( generatedHtml.match( width ), 'Width appears in generated HTML' ); assert.ok( generatedHtml.match( width ), 'Width appears in generated HTML' );
assert.ok( generatedHtml.match( height ), 'Height appears in generated HTML' ); assert.ok( generatedHtml.match( height ), 'Height appears in generated HTML' );
assert.ok( generatedHtml.includes( filePageShortUrl ), 'Short URL appears in generated HTML');
// No bylines, no license and site // No bylines, no license and site
info = createEmbedFileInfo( { title: title, imgUrl: imgUrl, filePageUrl: filePageUrl, info = createEmbedFileInfo( { title: title, imgUrl: imgUrl, filePageUrl: filePageUrl,
siteName: siteName, siteUrl: siteUrl } ); siteName: siteName, siteUrl: siteUrl, shortFilePageUrl: filePageShortUrl } );
generatedHtml = formatter.getThumbnailHtml( info, thumbUrl, width, height ); generatedHtml = formatter.getThumbnailHtml( info, thumbUrl, width, height );
assert.ok( generatedHtml.match( titleText ), 'Title appears in generated HTML.' ); assert.ok( generatedHtml.match( titleText ), 'Title appears in generated HTML.' );
assert.ok( generatedHtml.match( filePageUrl ), 'Page url appears in generated HTML.' ); assert.ok( generatedHtml.match( filePageUrl ), 'Page url appears in generated HTML.' );
assert.ok( generatedHtml.match( thumbUrl ), 'Thumbnail url appears in generated HTML' ); assert.ok( generatedHtml.match( thumbUrl ), 'Thumbnail url appears in generated HTML' );
assert.ok( generatedHtml.match( siteName ), 'Site name should appear in generated HTML' );
assert.ok( !generatedHtml.match( 'Public License' ), 'License should not appear in generated HTML' ); assert.ok( !generatedHtml.match( 'Public License' ), 'License should not appear in generated HTML' );
assert.ok( !generatedHtml.match( 'Homer' ), 'Author should not appear in generated HTML' ); assert.ok( !generatedHtml.match( 'Homer' ), 'Author should not appear in generated HTML' );
assert.ok( !generatedHtml.match( 'Iliad' ), 'Source should not appear in generated HTML' ); assert.ok( !generatedHtml.match( 'Iliad' ), 'Source should not appear in generated HTML' );
assert.ok( generatedHtml.match( width ), 'Width appears in generated HTML' ); assert.ok( generatedHtml.match( width ), 'Width appears in generated HTML' );
assert.ok( generatedHtml.match( height ), 'Height appears in generated HTML' ); assert.ok( generatedHtml.match( height ), 'Height appears in generated HTML' );
assert.ok( generatedHtml.includes( filePageShortUrl ), 'Short URL appears in generated HTML');
} ); } );
@ -204,8 +208,6 @@
QUnit.test( 'getCreditText():', 2, function ( assert ) { QUnit.test( 'getCreditText():', 2, function ( assert ) {
var txt, formatter = new mw.mmv.EmbedFileFormatter(); var txt, formatter = new mw.mmv.EmbedFileFormatter();
this.sandbox.stub( formatter, 'getLinkUrl' ).returns( 'quuuux' );
txt = formatter.getCreditText( { txt = formatter.getCreditText( {
repoInfo: { repoInfo: {
displayName: 'Localcommons' displayName: 'Localcommons'
@ -214,13 +216,14 @@
imageInfo: { imageInfo: {
author: 'Author', author: 'Author',
source: 'Source', source: 'Source',
descriptionShortUrl: 'link',
title: { title: {
getNameText: function () { return 'Image Title'; } getNameText: function () { return 'Image Title'; }
} }
} }
} ); } );
assert.strictEqual( txt, '"Image Title" by Author - Source. Via Localcommons - quuuux', 'Sanity check' ); assert.strictEqual( txt, 'By Author - Source, link', 'Sanity check' );
txt = formatter.getCreditText( { txt = formatter.getCreditText( {
repoInfo: { repoInfo: {
@ -230,25 +233,24 @@
imageInfo: { imageInfo: {
author: 'Author', author: 'Author',
source: 'Source', source: 'Source',
descriptionShortUrl: 'link',
title: { title: {
getNameText: function () { return 'Image Title'; } getNameText: function () { return 'Image Title'; }
}, },
license: { license: {
getShortName: function () { return 'DWTFYWPL'; }, getShortName: function () { return 'WTFPL v2'; },
longName: 'Do What the Fuck You Want Public License', longName: 'Do What the Fuck You Want Public License Version 2',
isFree: this.sandbox.stub().returns( true ) isFree: this.sandbox.stub().returns( true )
} }
} }
} ); } );
assert.strictEqual( txt, '"Image Title" by Author - Source. Licensed under DWTFYWPL via Localcommons - quuuux', 'License message works' ); assert.strictEqual( txt, 'By Author - Source, WTFPL v2, link', 'License message works' );
} ); } );
QUnit.test( 'getCreditHtml():', 2, function ( assert ) { QUnit.test( 'getCreditHtml():', 2, function ( assert ) {
var html, formatter = new mw.mmv.EmbedFileFormatter(); var html, formatter = new mw.mmv.EmbedFileFormatter();
this.sandbox.stub( formatter, 'getLinkUrl' ).returns( 'quuuux' );
html = formatter.getCreditHtml( { html = formatter.getCreditHtml( {
repoInfo: { repoInfo: {
displayName: 'Localcommons', displayName: 'Localcommons',
@ -258,13 +260,14 @@
imageInfo: { imageInfo: {
author: 'Author', author: 'Author',
source: 'Source', source: 'Source',
descriptionShortUrl: 'link',
title: { title: {
getNameText: function () { return 'Image Title'; } getNameText: function () { return 'Image Title'; }
} }
} }
} ); } );
assert.strictEqual( html, '"<a href="quuuux">Image Title</a>" by Author - Source. Via <a href="quux">Localcommons</a>.', 'Sanity check' ); assert.strictEqual( html, 'By Author - Source, link', 'Sanity check' );
html = formatter.getCreditHtml( { html = formatter.getCreditHtml( {
repoInfo: { repoInfo: {
@ -275,17 +278,18 @@
imageInfo: { imageInfo: {
author: 'Author', author: 'Author',
source: 'Source', source: 'Source',
descriptionShortUrl: 'link',
title: { title: {
getNameText: function () { return 'Image Title'; } getNameText: function () { return 'Image Title'; }
}, },
license: { license: {
getShortLink: function () { return '<a href="http://dwtfywpl.net/">DWTFYWPL</a>'; }, getShortLink: function () { return '<a href="http://www.wtfpl.net/">WTFPL v2</a>'; },
longName: 'Do What the Fuck You Want Public License', longName: 'Do What the Fuck You Want Public License Version 2',
isFree: this.sandbox.stub().returns( true ) isFree: this.sandbox.stub().returns( true )
} }
} }
} ); } );
assert.strictEqual( html, '"<a href="quuuux">Image Title</a>" by Author - Source. Licensed under <a href="http://dwtfywpl.net/">DWTFYWPL</a> via <a href="quux">Localcommons</a>.', 'Sanity check' ); assert.strictEqual( html, 'By Author - Source, <a href="http://www.wtfpl.net/">WTFPL v2</a>, link', 'Sanity check' );
} ); } );
}( mediaWiki ) ); }( mediaWiki ) );

View file

@ -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', 23, function ( assert ) { QUnit.test( 'Image model constructor sanity check', 24, function ( assert ) {
var var
title = mw.Title.newFromText( 'File:Foobar.jpg' ), title = mw.Title.newFromText( 'File:Foobar.jpg' ),
name = 'Foo bar', name = 'Foo bar',
@ -27,7 +27,9 @@
height = 15, height = 15,
mime = 'image/jpeg', mime = 'image/jpeg',
url = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg', url = 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
pageID = 42,
descurl = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg', descurl = 'https://commons.wikimedia.org/wiki/File:Foobar.jpg',
descShortUrl = '',
repo = 'wikimediacommons', repo = 'wikimediacommons',
datetime = '2011-07-04T23:31:14Z', datetime = '2011-07-04T23:31:14Z',
anondatetime = '20110704000000', anondatetime = '20110704000000',
@ -44,7 +46,7 @@
restrictions = ['trademarked'], restrictions = ['trademarked'],
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, datetime, anondatetime, origdatetime, descurl, descShortUrl, pageID, repo, datetime, anondatetime, origdatetime,
description, source, author, authorCount, license, permission, attribution, description, source, author, authorCount, license, permission, attribution,
latitude, longitude, restrictions ); latitude, longitude, restrictions );
@ -56,6 +58,7 @@
assert.strictEqual( imageData.mimeType, mime, 'MIME type is set correctly' ); assert.strictEqual( imageData.mimeType, mime, 'MIME type is set correctly' );
assert.strictEqual( imageData.url, url, 'URL for original image is set correctly' ); assert.strictEqual( imageData.url, url, 'URL for original image is set correctly' );
assert.strictEqual( imageData.descriptionUrl, descurl, 'URL for image description page is set correctly' ); assert.strictEqual( imageData.descriptionUrl, descurl, 'URL for image description page is set correctly' );
assert.strictEqual( imageData.pageID, pageID, 'Page ID of image description is set correctly');
assert.strictEqual( imageData.repo, repo, 'Repository name is set correctly' ); assert.strictEqual( imageData.repo, repo, 'Repository name is set correctly' );
assert.strictEqual( imageData.uploadDateTime, datetime, 'Date and time of last upload is set correctly' ); assert.strictEqual( imageData.uploadDateTime, datetime, 'Date and time of last upload is set correctly' );
assert.strictEqual( imageData.anonymizedUploadDateTime, anondatetime, 'Anonymized date and time of last upload is set correctly' ); assert.strictEqual( imageData.anonymizedUploadDateTime, anondatetime, 'Anonymized date and time of last upload is set correctly' );
@ -77,13 +80,13 @@
var var
firstImageData = new mw.mmv.model.Image( firstImageData = 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', 42,
'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', 'My cat' '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', 42,
'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', 'My cat', 'A person', 'Another person', 1, 'CC-BY-SA-3.0', 'Permitted', 'My cat',
'39.91820938', '78.09812938' '39.91820938', '78.09812938'