magnusmanske / listeria_rs

Repo for the Wikimedia Listeria bot
https://listeria.toolforge.org/
25 stars 6 forks source link

How to get the English Wikipedia article name? #134

Closed prototyperspective closed 1 month ago

prototyperspective commented 1 month ago

In this gallery on Commons I'd like to simply get the English Wikipedia article title so I can add a link to it. Other languages may get added later and it should also show an item when there is no ENWP article for it, this is just about adding a link if it exists.

I could not find info on how to retrieve a Wikipedia article title here. Also selecting ?articlename didn't work. I also couldn't find a useful examples in the sparql examples because I want to show the item also if no ENWP article exists. The query in the linked diff shows only items that have an ENWP article and even there I can't get it into a column.

pere-prlpz commented 1 month ago

I think you can get more help at https://www.wikidata.org/wiki/Wikidata:Request_a_query

Anyway, the solution to get articles with or without enwiki sitelink is to use OPTIONAL.

prototyperspective commented 1 month ago

Thanks for the info. Saying OPTIONAL is quite ambiguous. For instance, I had to first learn what it means and I don't wish to learn sparql because I have other Wikimedia things to do. However, this query seems to work and does return the Wikipedia articles. However, as you can see in that diff the bot does not add this as a column to to the templates.

prototyperspective commented 1 month ago

@pere-prlpz Okay another thing I just found is ?fieldname, a SPARQL result field name (variable). in the template documentation so now it adds the link to a new column. I don't yet know how to make it return an internal link – if you know how please let me know. I think I can solve this from there so I'm closing this issue already, thank you!

pere-prlpz commented 1 month ago

If you want to get a link, you can use links=text in the template, but that will be links to the wiki where the list is (e.g. links to Commons galleries if the page is in Commons). I suppose it's possible to link a specific Wikipedia but that needs to be worked in the query.

For questions about the query, it's better to ask at https://www.wikidata.org/wiki/Wikidata:Request_a_query , even if you don't want to learn SPARQL - although I recommend learning some SPARQL if you want to work with Wikidata.