I’m trying without success to link to wikipedia text and add wikimedia commons image. I’m using…
image=https://upload.wikimedia.org/wikipedia/commons/9/92/Castelo_de_Algoso_12.jpg
wikimedia_commons=File:Castelo_de_Algoso_12.jpg
wikipedia=pt:Castelo_de_Algoso
wikipedia:pt=Castelo_de_Algoso
On the sidebar, when using the inspector (query features tool) the links are there but there is no rendered image or wikpedia abstract text.
Any help would be great I want to set on feature correectly before adding lot more castles
This is a bug in the inspector code:
opened 08:16PM - 26 Jul 24 UTC
bug
inspector
When a feature has `wikipedia` set to a non-English article, the inspector is un… able to display the article’s excerpt and then fails to show any explicitly tagged image.
## Example
[This forum post](https://forum.openhistoricalmap.org/t/need-help-with-wikipedia-links-and-wikimedia-commons-images/257) by @nafergo gives the [Algoso Castle](https://www.openhistoricalmap.org/way/200360438) as an example:
<img src="https://github.com/user-attachments/assets/a0e39577-ee32-4180-ac21-752e8bc2d445" width="346" alt="Way: Algoso Castle (200360438), Castelo de Algoso, [1150 - ], Wikipedia">
## Diagnosis
The feature is tagged `wikipedia=pt:Castelo_de_Algoso`. This is a perfectly valid tag for the feature (although I would’ve used spaces instead of underscores). `wikipedia=*` should always begin with a language code prefix. Unfortunately, when sniffing out the Wikipedia link, the inspector sees `wikipedia=*`, as opposed to `wikipedia:xy=*`, and assumes it’s in English:
https://github.com/OpenHistoricalMap/ohm-inspector/blob/bf1f3c38dc967a86aa3cdfb5531dc56c4b91a300/openhistoricalmap-inspector.js#L550-L554
Then it asks the _English_ Wikipedia’s API for the article titled “pt:Castelo_de_Algoso”:
https://github.com/OpenHistoricalMap/ohm-inspector/blob/bf1f3c38dc967a86aa3cdfb5531dc56c4b91a300/openhistoricalmap-inspector.js#L601
* Actual: https://en.wikipedia.org/w/api.php?action=query&prop=extracts&exsentences=2&exlimit=1&format=xml&explaintext=true&exintro=true&origin=*&titles=pt:Castelo_de_Algoso
* Expected: https://pt.wikipedia.org/w/api.php?action=query&prop=extracts&exsentences=2&exlimit=1&format=xml&explaintext=true&exintro=true&origin=*&titles=Castelo_de_Algoso
Since the English and Portuguese Wikipedias happen to be on the same server farm, it obliges by returning an interwiki redirect, but it doesn’t have access to the Portuguese Wikipedia database in order to return an extract. Nevertheless, the inspector assumes there is an extract in the response:
https://github.com/OpenHistoricalMap/ohm-inspector/blob/bf1f3c38dc967a86aa3cdfb5531dc56c4b91a300/openhistoricalmap-inspector.js#L607
This results in an uncaught JavaScript error:
```
Uncaught TypeError: can't access property "textContent", (new DOMParser()).parseFromString(...).getElementsByTagName(...)[0] is undefined
onload openhistoricalmap-inspector.js:607
value openhistoricalmap-inspector.js:605
value openhistoricalmap-inspector.js:331
value openhistoricalmap-inspector.js:77
onload openhistoricalmap-inspector.js:102
value openhistoricalmap-inspector.js:98
value openhistoricalmap-inspector.js:87
value openhistoricalmap-inspector.js:64
n index-32cceb42370ca13698403957a382becf901b1bd43a49db62b2e9b610b78298b1.js:1
o index-32cceb42370ca13698403957a382becf901b1bd43a49db62b2e9b610b78298b1.js:1
i index-32cceb42370ca13698403957a382becf901b1bd43a49db62b2e9b610b78298b1.js:1
i index-32cceb42370ca13698403957a382becf901b1bd43a49db62b2e9b610b78298b1.js:1
setInterval handler*r index-32cceb42370ca13698403957a382becf901b1bd43a49db62b2e9b610b78298b1.js:1
addOpenHistoricalMapTimeSlider index-32cceb42370ca13698403957a382becf901b1bd43a49db62b2e9b610b78298b1.js:1
load index-32cceb42370ca13698403957a382becf901b1bd43a49db62b2e9b610b78298b1.js:1
run index-32cceb42370ca13698403957a382becf901b1bd43a49db62b2e9b610b78298b1.js:11
load index-32cceb42370ca13698403957a382becf901b1bd43a49db62b2e9b610b78298b1.js:11
<anonymous> index-32cceb42370ca13698403957a382becf901b1bd43a49db62b2e9b610b78298b1.js:1
c application-1db896435e361ddc9564449bac4adc0cf20096cf4759b3febd4e9c27af35866b.js:12
p application-1db896435e361ddc9564449bac4adc0cf20096cf4759b3febd4e9c27af35866b.js:12
setTimeout handler*Deferred/then/r/< application-1db896435e361ddc9564449bac4adc0cf20096cf4759b3febd4e9c27af35866b.js:12
u application-1db896435e361ddc9564449bac4adc0cf20096cf4759b3febd4e9c27af35866b.js:12
fireWith application-1db896435e361ddc9564449bac4adc0cf20096cf4759b3febd4e9c27af35866b.js:12
fire application-1db896435e361ddc9564449bac4adc0cf20096cf4759b3febd4e9c27af35866b.js:12
u application-1db896435e361ddc9564449bac4adc0cf20096cf4759b3febd4e9c27af35866b.js:12
fireWith application-1db896435e361ddc9564449bac4adc0cf20096cf4759b3febd4e9c27af35866b.js:12
ready application-1db896435e361ddc9564449bac4adc0cf20096cf4759b3febd4e9c27af35866b.js:12
d application-1db896435e361ddc9564449bac4adc0cf20096cf4759b3febd4e9c27af35866b.js:11
EventListener.handleEvent* application-1db896435e361ddc9564449bac4adc0cf20096cf4759b3febd4e9c27af35866b.js:12
<anonymous> application-1db896435e361ddc9564449bac4adc0cf20096cf4759b3febd4e9c27af35866b.js:11
<anonymous> application-1db896435e361ddc9564449bac4adc0cf20096cf4759b3febd4e9c27af35866b.js:11
openhistoricalmap-inspector.js:607:33
```
The error prevents any subsequent code from running. This feature happens to have an unnecessary, redundant `wikipedia:pt=*` tag, but the following code is never reached:
https://github.com/OpenHistoricalMap/ohm-inspector/blob/bf1f3c38dc967a86aa3cdfb5531dc56c4b91a300/openhistoricalmap-inspector.js#L555-L559
It also has an `image=*` tag, but that code is never reached either.
If you need a temporary workaround urgently, you can remove the wikipedia=*
tag in favor of the wikipedia:pt=*
tag. However, the former syntax is preferred.
Note that the wikimedia_commons=*
tag is not yet supported, but don’t let this stop you from adding it.
opened 11:46PM - 14 Aug 23 UTC
inspector
linked data
images
The [`wikimedia_commons`](https://wiki.openstreetmap.org/wiki/Key:wikimedia_comm… ons) key can be set to either a category name (prefixed with `Category:`) or an image file name (`File:`). If it’s a file name, the inspector should display the image, just as it does when `image` is present on the selected feature.
Examples:
* https://www.openhistoricalmap.org/node/2099627661
* https://www.openhistoricalmap.org/way/198592495
* https://www.openhistoricalmap.org/way/199263808
The image from Wikipedia commons is licensed under CC By. Is there a tag I can use for the image attribution? What do you suggest?
It looks like the inspector’s slideshow code supports image:n:license
and image:n:source
, where n is any number from 1 through 99.
const imageurl = this.getTagValue(xmldoc, `image:${imagei}`, 'url');
const captiontext = this.getTagValue(xmldoc, `image:${imagei}:caption`);
const imagedate = this.getTagValue(xmldoc, `image:${imagei}:date`);
const sourcetext = this.getTagValue(xmldoc, `image:${imagei}:source`);
const licensetext = this.getTagValue(xmldoc, `image:${imagei}:license`);
For wikimedia_commons
, I wouldn’t worry about it because the inspector would most likely fetch the license and attribution from the Commons API.
1 Like