Module talk:WikidataIB/Archive 8

Out of memory error
I have just undone Special:Diff/971102807. It seems to cause an out of memory error (see before and after). Also the page loading time is significant in the old revision, faster in the new one. I would assume this is the memory issue. I'll leave it reverted for now, but I think people who understand this 10x more than I do need to discuss. -- Amanda  (aka DQ) 18:33, 30 December 2020 (UTC)
 * One possible solution: rather than fetching all property values and filtering out the last with p-1, we can mark a single value as preferred in Wikidata (d:Help:Ranking) and use p 1. From a quick test (after making the preferred value here), memory usage from that single call gets cut in half, from 8MB to 4MB. This requires keeping the preferred value up to date in Wikidata, but otherwise seems like an easy fix. Pinging Dellux mkd, who is keeping this updated in Wikidata. What do you think? —  The Earwig   talk 19:11, 30 December 2020 (UTC)
 * This call:
 * costs around 0.5 sec out of 10 sec and 8 MB out of 52 MB of Lua resources, which is pretty expensive for a way to get the latest date, and relies on Wikidata storing values in order. This call:
 * costs around 0.005 sec out of 10 sec and 0.6 MB out of 52 MB of Lua resources, which is a lot cheaper but relies on the latest date being marked as preferred. Neither of these calls on their own cause an out-of-memory error, but if the editors of the article insist on having a ludicrous 383 references, then every little saving on Lua resources will help to keep the article from falling over. Without either call, the Lua memory usage of the article is still 51.7 MB out of 52.4 MB with nearly 7 sec of Lua processing time. The real solution is to get rid of the massive overcitation, and dramatically reduce the content that's available in the daughter articles per WP:SS. Otherwise, it won't be long before it falls over again. --RexxS (talk) 20:44, 30 December 2020 (UTC)
 * Well, i just have to repeat what said and that is that i leave this discussion to people who understand this 10x more than i do. I agree with  and  that we must get rid of the massive overcitation. 383 references so far is way too much and can be reduced in order too keep the article from falling. Again i must say that i leave the call to people who understand this more than i do. Dellux mkd (talk) 21:36, 30 December 2020 (UTC)
 * Thanks, I'll restore the cheaper version and start nuking out some refs and maybe splitting. -- Amanda  (aka DQ) 22:20, 30 December 2020 (UTC)
 * While I did nuke a lot of things out of the article, me going through and removing any excess referencing seems like a monumental task compared to what we might be able to do by modifying the 15 invokes of this module. Right now, memory is: . After removing the module and replacing by hand:  . So if either of you can optimize anything on that page, it would be appreciated. --  Amanda  (aka DQ) 14:02, 31 December 2020 (UTC)
 * Thanks, I'll restore the cheaper version and start nuking out some refs and maybe splitting. -- Amanda  (aka DQ) 22:20, 30 December 2020 (UTC)
 * While I did nuke a lot of things out of the article, me going through and removing any excess referencing seems like a monumental task compared to what we might be able to do by modifying the 15 invokes of this module. Right now, memory is: . After removing the module and replacing by hand:  . So if either of you can optimize anything on that page, it would be appreciated. --  Amanda  (aka DQ) 14:02, 31 December 2020 (UTC)

Error continues at other sections
The "Lua error" is now present for the entire External links section as per latest version Special:Diff/999975064. Also, at COVID-19_pandemic_in_India one can see a table full of dates being displayed that is serving no logic. Please have a look and a resolution is highly appreciated. Besides this, I request to make the page temporary semi-protection due to disruptive editing by IP editors now and then. Thank you. — Amkgp 💬  18:04, 15 January 2021 (UTC)
 * Oh boy. Okay, we'll take a look at it.  ~Oshwah~  (talk) (contribs)   19:34, 15 January 2021 (UTC)
 * Someone restored the stuff I removed with this edit. -- Amanda  (aka DQ) 20:53, 15 January 2021 (UTC)
 * It's actually back to 10MB from the memory limit likely because of the continual increase in data from wikidata. I'm going to have to remove the values and we'll have to put it in by hand. -- Amanda  (aka DQ) 21:00, 15 January 2021 (UTC)
 * I took out the wikidata statements at they will be ever expanding, and WP:NOTNEWS and WP:INDISCRIMINATE. We can update the numbers manually. -- Amanda  (aka DQ) 21:07, 15 January 2021 (UTC)
 * The values on Wikidata were being updated without marking the latest date as preferred, so there's no way to reduce the overhead without cooperation there. I strongly recommend that we don't use Wikidata for these articles because of the time-sink involved in fixing avoidable problems. --RexxS (talk) 22:06, 15 January 2021 (UTC)

getQualValueByLang
How can I get a qualifier value by language?

I need to get the English value of the qualifier of the first value of the  statement on.

--Lectrician1 (talk) 06:00, 12 February 2021 (UTC)
 * Module:Wd by default gets the value in the local wiki's language, so this works for you:
 * Thayts  •••  09:20, 12 February 2021 (UTC)
 * Thayts  •••  09:20, 12 February 2021 (UTC)
 * Thayts  •••  09:20, 12 February 2021 (UTC)
 * Thayts  •••  09:20, 12 February 2021 (UTC)

Detecting same/different values in Wikidata
I would like a convenient way to detect when a locally-defined value is equal to the value on Wikidata (which would tell me I could safely remove the locally defined value) or when a locally-defined value is different to the value on Wikidata (which might indicate an error in either value). Possibilities I had in mind: In both cases, they would only appear if set by an editor's personal CSS. This is not something to trouble the reader with. Thanks for consideration &mdash; Martin (MSGJ · talk) 19:46, 3 March 2021 (UTC)
 * Colouring the entire value/text green or red (respectively) if the wd value is same/different
 * Adding a small icon (e.g. Check_icon.svg / Ambox question.svg) after the value.

Bug with checkBlacklist
→ &mdash; Martin (MSGJ · talk) 22:10, 15 March 2021 (UTC)
 * The module is outputting "false" which is treated the same as "true" by the "if" conditional. It might be better if it just outputted blank rather than false. &mdash; Martin (MSGJ · talk) 15:42, 17 March 2021 (UTC)
 * This works:

→
 * Shall I update the documentation, or can we change the output of "false"? &mdash; Martin (MSGJ · talk) 15:54, 17 March 2021 (UTC)

Bug?
Module:WikidataIB is currently returning true for both examples, when I'm pretty sure the first is meant to return "blacklisted". &#123;{u&#124; Sdkb  }&#125;  talk 08:56, 23 August 2021 (UTC)
 * Oh, I see raised this already and identified the issue. I'm not sure if changing to a blank output would cause any issues, but the documentation or something needs to change. &#123;{u&#124;  Sdkb  }&#125;  talk 08:58, 23 August 2021 (UTC)

Problem with caption
I'm having a problem getting the correct caption for the image. has two images. The first does not have a caption but the second does. gives me the first image, which is fine:

But is giving me the caption for the second image, which I don't want, because it doesn't match the image.

At Module talk:WikidataIB/Archive 6, suggested using the getQualifierValue function, but I can't get this to work &mdash; Martin (MSGJ · talk) 17:18, 27 November 2021 (UTC)

getting data
just found a 'fetchwikidata' entry on its own in an article infobox, the coords arg is also there but blank, the mapframe is showing, mapframe is correct, displayed coords are wrong ... is fetchwikidata a valid template thing or should it be an argument in a wikidata template box ? I copy/pasted the whole article and I'm getting no coords, but then my sandbox wouldn't have details to copy from ... John Whitton Bridge - User:Dave Rave/sandbox9 Dave Rave (talk) 00:13, 27 November 2021 (UTC)
 * That parameter appears to be working correctly. fetchwikidata is passed to Module:WikidataIB and used as documented in this module's documentation. The infobox is fetching coordinates from the Wikidata item associated with John Whitton Bridge, displaying them, and linking to the Geohack page, which links to maps that result in a location close to the bridge. If the coordinates are incorrect in Wikidata, they will be incorrect in the Wikipedia article. – Jonesey95 (talk) 02:12, 27 November 2021 (UTC)
 * wikidata gps is correct, mapframe is correct, fetched gps coords are wrong Dave Rave (talk) 09:00, 28 November 2021 (UTC)
 * As far as I can tell, for John Whitton Bridge, Wikidata says 33°49'23"S, 151°5'26"E and the infobox displays 33°49′S 151°05′E. When I click the coords, the Geohack page says 33°49′12″S, 151°5′24″E. The call to WikidataIB, as rendered by Coord, is a little different, and I can't explain that difference. If I use  directly on the page, I get the same results as the infobox (a little different). If I use WikidataCoord on the page, it displays, and links to, the Wikidata value of 33°49'23"S, 151°5'26"E. – Jonesey95 (talk) 14:34, 28 November 2021 (UTC)

Breaking changes made to live template twice
, please do more testing before changing this module again. The module is used in over one million pages. Your recent edit twice introduced Linter errors into more than 1,000 pages. It is possible that this indicates that a different template or module needs to be fixed before your proposed change can be reintroduced. I saw the following templates transcluded in pages that showed the error: Infobox software, Infobox company, Infobox drink, if that helps you track down the problem. – Jonesey95 (talk) 00:52, 8 December 2021 (UTC)


 * I'm struggling to diagnose the problem. Can you have a look please? &#8209;&#8209;Neveselbert (talk · contribs · email) 21:31, 13 December 2021 (UTC)
 * I'll be happy to. Please link to pages with test cases comparing infoboxes using your proposed edit and the existing module. – Jonesey95 (talk) 21:53, 13 December 2021 (UTC)

Help with converting a wikidata call to this module
How would I convert these two Wikidata calls to use this module? I want there to only return if there is a reference. The calls: Gonnym (talk) 10:49, 25 December 2021 (UTC)
 * -> - the above reference covers this so this is ok
 * -> - should not return
 * -> - should not return
 * as far as I know this module will not return references at all. It is a major weakness of this module over Module:Wikidata. It will check if statements are referenced via the onlysourced parameter, but it will not display the references. If you still want this question answered, then I will try &mdash; Martin (MSGJ · talk) 03:46, 24 February 2022 (UTC)

Only values with no end time (P582)
Is there a way to only show values with no end time (P582)? i.e. all current board members? Thank you! --Newt713 (talk) 08:55, 30 December 2021 (UTC)
 * An if statement would probably work for you. Something like  (fake code, obviously). – Jonesey95 (talk) 13:43, 30 December 2021 (UTC)
 * Thanks. But how do I include the if statement into the Module? In my case i.e. . I can't use an if statement for the whole statement. --Newt713 (talk) 21:34, 30 December 2021 (UTC)
 * I agree it won't work in your case. I assume you are trying to fetch only the current ? The usual way to deal with this is to make that statement have "preferred rank", then the rank=best option will pull that statement through. See wikidata:Help:Ranking for more details. &mdash; Martin (MSGJ · talk) 03:41, 24 February 2022 (UTC)
 * Thank you. That's my solution at the moment. I only think it's a bad solution, giving the inconsistent ranking data. It would be great to expand this module to allow "only current". --Newt713 (talk) 07:25, 24 February 2022 (UTC)

Translating Wikipedia page title, or redirect page title, to QID
QID codes and PID codes make wiki code hard to understand, for example in Wikidata based tables. Ordinary users get frustated when they see the complex wiki code.

The template Get QID would potentially solve the problem, but it does not seem to take article name as argument as the documenation says. For example should result in Q1 according to the documentation.

Question 1: Why not modify the Get QID template to use ? For example results in.

Question 2: Is there a way to make WikidataIB accept a redirected term as argument? For example should result in Q1, but results in. The URL https://en.wikipedia.org/w/index.php?title=Universes&redirect=yes acceps redirects and works. Do we have to wait for a change of the mw.wikibase syntax? For example in mw.wikibase.getEntityIdForTitle to accept redirect=yes, or RedirectResolvingEntityLookup. Can we expect such a modification?

Tomastvivlaren (talk) 22:09, 23 February 2022 (UTC)
 * Hi Tomastvivlaren! Quite a few points you have raised there.
 * is currently undocumented, and I was unaware of it till now.
 * I have used Module:ResolveEntityId for this purpose and it works well.
 * I fully agree it would be useful if redirects were followed. I posted a request for this in June 2021 and coincidentally followed up shortly before your post here. It is definitely technically feasible because we have the functionality in Module:Redirect.
 * Otherwise I am unsure how you propose to use this on Wikidata based tables. I agree that using QIDs in wikicode can look unfriendly and I have started using HTML comments in the wikitext (see List of lighthouses in Japan). But there no way to avoid using the QIDs that I can see?
 * Regards &mdash; Martin (MSGJ · talk) 03:31, 24 February 2022 (UTC)
 * I have now modified template:Get QID to get the QID for any Wikipedia page, based on the page title, by utilizing getEntityFromTitle in the module:WikidataIB.
 * It also works if the page is moved, since it follows the redirect using Module:Redirect. Thanks for the recommendation!
 * I have also used this to create population WD and area WD.Tomastvivlaren (talk) 18:28, 26 February 2022 (UTC)
 * Okay. I would advise to use QIDs and advise against using labels, which are not unique! &mdash; Martin (MSGJ · talk) 20:50, 26 February 2022 (UTC)
 * Well, I am not using Wikidata labels, but Wikipedia page article name. QID and PID in article wikicode makes it ugly and hard to understand, not only for non-programmers. Tomastvivlaren (talk) 21:49, 26 February 2022 (UTC)

Possible bug fix
I'm trying to set up my own wiki, and I've been importing various templates and modules from Wikipedia. Something I imported eventually complained that this module was missing, so I imported it.

At this point I feel like I should note that I have no idea what this module is for. With that said:

After importing this module, pages that were using it then started complaining about an attempted dereference of a nil reference. I "fixed" it (on my local site), at least insofar as that those pages no longer complain, but I don't want to update the module here on Wikipedia because, like I said, I have no idea what it's for. So, in case someone more knowledgeable than me wants to check if it would be appropriate to add my change here too, what I did was insert this line at the top of function _getcommonslink:

The mw.wikibase variable is dereferenced a couple lines later, which is where the error was thrown from. I hope this helps. -Rwv37 (talk) 23:24, 9 February 2022 (UTC)
 * mw.wikibase is the library of functions for accessing wikibase items via Lua. It's documented here. Without that extension I cannot think how this module can do anything for you on your home wiki. &mdash; Martin (MSGJ · talk) 03:37, 24 February 2022 (UTC)


 * Yeah, I eventually figured out what Wikibase is. The thing the module could do for my home wiki is exist, so as to stop other imported things from complaining about it being missing. Turns out that issues like this are all over the code, not just in Module:WikidataIB. -Rwv37 (talk) 10:15, 5 March 2022 (UTC)

How to get the latest value instead of the largest value?
This gives the largest population value:

I want it to show the newest value, which is 21,012 (2021). Is that possible using WikidataIB? Also in case all values have the same rank? Tomastvivlaren (talk) 09:41, 1 March 2022 (UTC)


 * I don't think there is a function for that. You should set preferred value and then use rank=best &mdash; Martin (MSGJ · talk) 11:26, 1 March 2022 (UTC)




 * Thnx for your good advise. I believe my current solution shows the most recently edited value (which often but not always is the newest value), if all values have the same rank:
 * Tomastvivlaren (talk) 23:53, 10 March 2022 (UTC)
 * Tomastvivlaren (talk) 23:53, 10 March 2022 (UTC)

How to only show year of a numeric value?
How can I only show the year of a numeric value, for example the year for the population size of a city? Now I used the following advanced string manipulation to remove the value, which makes the script slow - it gives the error message "The time allocated for running scripts has expired" if the script is included a large number of times in the same Wikipedia page:

Tomastvivlaren (talk) 00:06, 11 March 2022 (UTC)

sorted=true: by what?
I understand that true sorts the returned values, but I cannot see by what ordering. Eg, for, :
 * sorted=false:  dflt
 * sorted= true:
 * So, true-results have unexpected order IMO. (Incidentally, the itempage has/shows alphabetical order).

DePiep (talk) 13:26, 26 September 2022 (UTC)


 * Does it have to do with wikilinked/unlinked? If so, by some rationale or because of code like " DePiep (talk) 13:28, 26 September 2022 (UTC)
 * @DePiep From the doc page/comments: It's only a very dumb alphabetical sort and sorts linked values as " undefined. So a literal alphabetical sort that doesn't break up links to sort by label. That seems to match your example as well. -- [[User:Ferret|ferret (talk) 13:30, 26 September 2022 (UTC)
 * Thanks; makes me feel good having the question right ;-)
 * Consider answered. DePiep (talk) 13:38, 26 September 2022 (UTC)

getWebsite error
I think there is an error in the getWebsite function. If there is no wikidata item corresponding to the current page then it will not even display the locally defined parameter. That prevents it being tested properly on talk pages and testcases.

currently produces:

&mdash; Martin (MSGJ · talk) 06:36, 3 October 2022 (UTC)


 * @MSGJ Which infobox? This may be a template-level issue. Nevermind I'm dumb, I missed your example because it's literally blank :) Taking a glance... -- ferret (talk) 14:20, 3 October 2022 (UTC)
 * @MSGJ The culprit is the line if not qid then return nil end. If the page has no qid, the function ends early. I think this should probably be something like if not qid and not url then return nil end. That should allow it to continue if a locally defined url is set. -- ferret (talk) 14:29, 3 October 2022 (UTC)
 * Yes I agree. Was just checking in case I'd missed something silly. This function is not really documented. &mdash; Martin (MSGJ · talk) 15:41, 3 October 2022 (UTC)
 * I've got some code which seems to work in Module:WikidataIB/sandbox &mdash; Martin (MSGJ · talk) 14:35, 4 October 2022 (UTC)
 * Deployed &mdash; Martin (MSGJ · talk) 16:10, 6 October 2022 (UTC)

How to add references
Is there a way to show references? wikidata has this nice option:
 * &rarr;
 * &rarr;

But afaik it is less controllable. Some live examples in infoboxes? -DePiep (talk) 14:48, 26 September 2022 (UTC) DePiep (talk) 14:48, 26 September 2022 (UTC)


 * As far as I know, this module was never designed to produce references. It would be nice to produce well formatted references. I think it will be quite challenging to match an existing citation style on an article. &mdash; Martin (MSGJ · talk) 15:11, 26 September 2022 (UTC)
 * Ouch. This hurts... Thx. DePiep (talk) 18:57, 26 September 2022 (UTC)
 * Oh, thank you for opening this discussion @DePiep!
 * In case we manage to combine both, I opened the mirror version here:
 * https://en.wikipedia.org/wiki/Module_talk:Wd#Add_a_'maxvals'_option_as_in_https://en.wikipedia.org/wiki/Module:WikidataIB AdrianoRutz (talk) 08:43, 7 October 2022 (UTC)
 * OK, thx. Other issues in here: reference formatting (& omitting when maxval is used). Bottleneck in moving fwd is time here; sub-ideal solutions in mind. DePiep (talk) 08:50, 7 October 2022 (UTC)

Using "unknown value" in queries
Is there any way to query items with "unknown value" in their statemennts?

For example: Should return the date "29 October 2022" from the item Q104417487. T.Shafee(Evo &#38; Evo)talk 11:36, 2 November 2022 (UTC)
 * I recall last night that if I entered "anonymous" as the author name, the "add this statement to wikidata" button disappears. OhanaUnitedTalk page 13:39, 2 November 2022 (UTC)
 * That's becaues the current v:Template:Review_info template uses the query:
 * What I'm hoping to do is change it over to:
 * so that the "unknown value" special value can be used on the wikidata items, because that's where the community seems to be moving for indicating statements about anonymous peer reviewers.
 * The module seems to have some ability to understand "unknown value" statements because this query:
 * returns:
 * It just needs to be extended from the getValue function to the getQualifierValue function. T.Shafee(Evo &#38; Evo)talk 02:46, 3 November 2022 (UTC)
 * @Evolution and evolvability: If you absolutely need to query for unknown values, use  LennardHofmann (talk) 09:45, 4 November 2022 (UTC)
 * If using Module:Wd is an option, please use  instead. LennardHofmann (talk) 09:51, 4 November 2022 (UTC)
 * @LennardHofmann - oh good idea! I always forget about that module (tbh, I'm still a little hazy on the main differences between it and this one). Anyway, the template v:Template:Review_info now works again to first to detect whether a wikidata item has an anon peer reviewer (P4032="unknown value") and if not, adds one via quickstatements. T.Shafee(Evo &#38; Evo)talk 05:40, 11 November 2022 (UTC)
 * It just needs to be extended from the getValue function to the getQualifierValue function. T.Shafee(Evo &#38; Evo)talk 02:46, 3 November 2022 (UTC)
 * @Evolution and evolvability: If you absolutely need to query for unknown values, use  LennardHofmann (talk) 09:45, 4 November 2022 (UTC)
 * If using Module:Wd is an option, please use  instead. LennardHofmann (talk) 09:51, 4 November 2022 (UTC)
 * @LennardHofmann - oh good idea! I always forget about that module (tbh, I'm still a little hazy on the main differences between it and this one). Anyway, the template v:Template:Review_info now works again to first to detect whether a wikidata item has an anon peer reviewer (P4032="unknown value") and if not, adds one via quickstatements. T.Shafee(Evo &#38; Evo)talk 05:40, 11 November 2022 (UTC)

Pulling structured data from Commons
Is there an equivalent to this module to retrieve structured data from a file on wikimedia commons? E.g. should have P275 = Q20007257. Any ideas? T.Shafee(Evo &#38; Evo)talk 06:29, 10 March 2023 (UTC)

value instead of Qid in qvalue
With module Wd it's possible to do this (for total revenue in d:Q30288051): but module WikidataIB only takes qualifier ID for qvalue so the following does not work Is there a way to use any value, like in module Wd? Ponor (talk) 18:00, 2 June 2023 (UTC)


 * @Ponor: There is a comment in the code that says "We'll only deal with wikibase-items and strings for now". Checking whether a given date string (e.g. "2017") matches a Wikidata time value is non-trivial, so I don't expect that getValueByQual will support the  datatype any time soon. LennardHofmann (talk) 18:59, 2 June 2023 (UTC)