Add link to wikipedia-image in the attribution box, fix #1049

This commit is contained in:
Pieter Vander Vennet 2022-08-30 20:29:49 +02:00
parent efd1f5467b
commit c09b437d9a
3 changed files with 16 additions and 3 deletions

View file

@ -8,4 +8,5 @@ export class LicenseInfo {
copyrighted: boolean = false; copyrighted: boolean = false;
credit: string = ""; credit: string = "";
description: string = ""; description: string = "";
informationLocation: URL = undefined
} }

View file

@ -129,7 +129,7 @@ export class WikimediaImageProvider extends ImageProvider {
if (pageInfo === undefined) { if (pageInfo === undefined) {
return undefined; return undefined;
} }
const license = (pageInfo.imageinfo ?? [])[0]?.extmetadata; const license = (pageInfo.imageinfo ?? [])[0]?.extmetadata;
if (license === undefined) { if (license === undefined) {
console.warn("The file", filename, "has no usable metedata or license attached... Please fix the license info file yourself!") console.warn("The file", filename, "has no usable metedata or license attached... Please fix the license info file yourself!")
@ -153,6 +153,7 @@ export class WikimediaImageProvider extends ImageProvider {
licenseInfo.licenseShortName = license.LicenseShortName?.value; licenseInfo.licenseShortName = license.LicenseShortName?.value;
licenseInfo.credit = license.Credit?.value; licenseInfo.credit = license.Credit?.value;
licenseInfo.description = license.ImageDescription?.value; licenseInfo.description = license.ImageDescription?.value;
licenseInfo.informationLocation = new URL("https://en.wikipedia.org/wiki/"+pageInfo.title)
return licenseInfo; return licenseInfo;
} }

View file

@ -2,10 +2,14 @@ import Combine from "../Base/Combine";
import Translations from "../i18n/Translations"; import Translations from "../i18n/Translations";
import BaseUIElement from "../BaseUIElement"; import BaseUIElement from "../BaseUIElement";
import {VariableUiElement} from "../Base/VariableUIElement"; import {VariableUiElement} from "../Base/VariableUIElement";
import {Store, UIEventSource} from "../../Logic/UIEventSource"; import {Store} from "../../Logic/UIEventSource";
import {LicenseInfo} from "../../Logic/ImageProviders/LicenseInfo"; import {LicenseInfo} from "../../Logic/ImageProviders/LicenseInfo";
import {FixedUiElement} from "../Base/FixedUiElement"; import {FixedUiElement} from "../Base/FixedUiElement";
import Link from "../Base/Link";
/**
* Small box in the bottom left of an image, e.g. the image in a popup
*/
export default class Attribution extends VariableUiElement { export default class Attribution extends VariableUiElement {
constructor(license: Store<LicenseInfo>, icon: BaseUIElement, date?: Date) { constructor(license: Store<LicenseInfo>, icon: BaseUIElement, date?: Date) {
@ -18,11 +22,18 @@ export default class Attribution extends VariableUiElement {
return undefined return undefined
} }
let title = undefined;
if (license?.title) {
title = Translations.W(license?.title).SetClass("block")
if (license.informationLocation) {
title = new Link(title, license.informationLocation.href, true)
}
}
return new Combine([ return new Combine([
icon?.SetClass("block left").SetStyle("height: 2em; width: 2em; padding-right: 0.5em;"), icon?.SetClass("block left").SetStyle("height: 2em; width: 2em; padding-right: 0.5em;"),
new Combine([ new Combine([
Translations.W(license?.title).SetClass("block"), title,
Translations.W(license?.artist ?? "").SetClass("block font-bold"), Translations.W(license?.artist ?? "").SetClass("block font-bold"),
Translations.W(license?.license ?? license?.licenseShortName), Translations.W(license?.license ?? license?.licenseShortName),
date === undefined ? undefined : new FixedUiElement(date.toLocaleDateString()) date === undefined ? undefined : new FixedUiElement(date.toLocaleDateString())