Module talk:WikidataIB: Difference between revisions

From Doc-Wiki
Latest comment: 27 December 2025 by Lucas Werkmeister in topic Edit request 14 November 2025
Jump to navigation Jump to search
 
m 1 revision imported
 
(No difference)

Latest revision as of 14:36, 1 January 2026

Template:Permanently protected Template:WPBS Template:Banner holder Template:To-do Template:Archives User:MiszaBot/config

getValueByRefSource

There are no examples for getValueByRefSource... What I'm after is the population (P1082) of Toronto (Q172), as given by the 2021 Canadian Census (Q42317745). The data is there, and I'm trying to access it with the following:

{{#invoke:WikidataIB |getValueByRefSource |qid=Q172 | P1082 |match=Q42317745 |fwd=ALL}}

... which doesn't return anything, not even an error message. What am I missing here? Tompw (talk) 19:14, 11 November 2025 (UTC)Reply

Hmmmm. The documented way it works is that getValueByRefSource will only return a value if Toronto's property for Lua error in Module:Wd at line 633: attempt to index field 'wikibase' (a nil value). (P1082) has sub property Lua error in Module:Wd at line 633: attempt to index field 'wikibase' (a nil value). (P248) filled in. Toronto does not on the Lua error in Module:Wd at line 633: attempt to index field 'wikibase' (a nil value). (Q42317745) ref so your code won't work, earlier years do but it won't pull those back when I change the code - the plot thickens, it seems to only return values when a very specific qualifier is used, in this case only if Lua error in Module:Wd at line 633: attempt to index field 'wikibase' (a nil value). (Q21540096) or Lua error in Module:Wd at line 633: attempt to index field 'wikibase' (a nil value). (Q7804) is quoted, such as on Q28 or Q100874038, and amounts in dollars.
Full list using those qualifiers is here. Only around 200 articles satisfy the requirement. The module looks to have some hardcoded values in amongst the getValueByRefSource function code Lua error in Module:Wd at line 633: attempt to index field 'wikibase' (a nil value). (Q21540096) and Lua error in Module:Wd at line 633: attempt to index field 'wikibase' (a nil value). (Q4917), and looks to have been added during testing back in 2018 here. The returned figures are also being truncated, and it's not clear whether to use |qvalue= or |match= to input the qualifier but they are returning different amounts.
@Tompw If you instead use {{#invoke:WikidataIB |getValue |qid=Q172 | P1082 |ps=3}} that should fetch the data you need for now.
@Pigsonthewing @Jonesey95, as recent editors could you check the above thanks, I added some test cases in Module:WikidataIB/sandbox. Regs, The Equalizer (talk) 01:04, 22 December 2025 (UTC)Reply
No idea. I find this module's options, when combined with the jargon used on Wikidata, nearly impenetrable. I just keep trying things until it sometimes work. I give up about half the time. – Jonesey95 (talk) 02:19, 22 December 2025 (UTC)Reply

Edit request 14 November 2025

Template:Edit template-protected

Description of suggested change: Please apply c:Special:Diff/1115600336 to fix the order of "mul" in the language fallback sequence for labels (should be after all explicit fallbacks, but just before the implicit fallback to "en").

Diff: Template:Text diff Lucas Werkmeister (talk) 19:59, 14 November 2025 (UTC)Reply

Lucas Werkmeister, this change is now in the sandbox: Special:Diff/1317055591/1325225748. I'm not familiar with this module. Which templates use it? Is there a good way to test it? What problem visible in usages of this module does it solve? —⁠andrybak (talk) 22:06, 1 December 2025 (UTC)Reply
@Andrybak: It took a while to put together a working demo (because only such a small part of the module actually uses mul labels at the moment – it should probably be used in more places, using the correct version of the fallback code), but here’s one: User:Lucas Werkmeister/sandbox (Special:Permalink/1325240674). The statement shown is Lua error in Module:Wd at line 633: attempt to index field 'wikibase' (a nil value). (Q532240) | Lua error in Module:Wd at line 633: attempt to index field 'wikibase' (a nil value). (P3618), which is a quantity with the unit Lua error in Module:Wd at line 633: attempt to index field 'wikibase' (a nil value). (Q199471), and that unit has two unit symbols: Afs in English and ؋ in mul (the Pashto sign). The old code is incorrectly displaying the mul symbol rather than the English symbol. Lucas Werkmeister (talk) 23:45, 1 December 2025 (UTC)Reply

Template:Done—Please report any issues. Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 14:19, 8 December 2025 (UTC)Reply

Template:Ping I might have found a bug in this recent change. Two lighthouse pages had units of type M showing up. See these permalinks:
And look specifically at the Range values in the infobox. I went down the rabbit hole for both pages (which showed up in Category:Convert errors) and the ONLY relevant change I could find was to this module (no updates to wikidata, the articles themselves, {{Infobox lighthouse}}, etc.)
Now the temporary fix was to manually use {{convert}} on those pages... But that removes the call to wikidata and seems to be indicative of a larger problem. I would encourage a revert of the recent change that was made. Zackmann (Talk to me/What I been doing) 17:34, 8 December 2025 (UTC)Reply
Thank you. Reverted. Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 17:36, 8 December 2025 (UTC)Reply
Well that was insanely quick... Thanks Andy! Zackmann (Talk to me/What I been doing) 17:37, 8 December 2025 (UTC)Reply
@Zackmann08, @Pigsonthewing: I don’t think that was a bug? Lua error in Module:Wd at line 633: attempt to index field 'wikibase' (a nil value). (Q93318) has three English “unit symbol” statements and they all have the same rank. Lucas Werkmeister (talk) 19:32, 8 December 2025 (UTC)Reply
Template:Ping I'm not very good with Wikidata... All I know is that the 2 pages I linked to above were displaying an error because {{convert}} was trying to convert with unit type M as shown here:
Exactly why this is happening, I'm not sure... But it was pretty clearly directly related to the change that was implemented. Zackmann (Talk to me/What I been doing) 19:42, 8 December 2025 (UTC)Reply
I see, that sounds like a more serious error than what I expected, at least (I thought it just displayed the symbol as M instead). Plugging a Wikidata unit symbol into {{convert}} doesn’t sound like the greatest idea to me (the item ID of the unit would be a much more stable identifier), but that would be a larger change.
Looking at the code more closely… I think it’s badly broken anyway? I assume the intention is to follow the language fallback chain and find the first unit symbol statement with a language code matching the target language, or the target language’s first fallback, or its second fallback, and so on. But in fact, the structure of the loops means that, for the most part, it’ll find the first unit symbol statement whose language code appears anywhere in the language fallback chain? Except that there’s also another bug where the if found then break end is, if I’m not mistaken, placed one line above where it should be, with the result that it never breaks out of the outer loop, and therefore it actually returns the last statement where the language code appears anywhere in the fallback chain?
I still haven’t worked out why the requested edit made a difference, though. I think it would’ve changed the fbtbl from {"mul", "en", "en"} to {"en", "mul", "en"} (assuming that, in the context of those pages, args.lang is "en"), but why did that change the result… Lucas Werkmeister (talk) 20:15, 8 December 2025 (UTC)Reply
Oh, apparently the old code resulted in {"mul", "en"} instead (no second "en" as I expected). Lucas Werkmeister (talk) 20:21, 8 December 2025 (UTC)Reply
Template:Ping Please consider retrying the edit request with Special:Diff/1326419389 applied on top; as far as I can tell from trying out the Lua snippets at Special:Permalink/1326419901 in the debug console, that should work better. (But you, unlike me, should be able to try it out using the “preview page with this template” feature, to make sure that Abu Musa and Lindisfarne don’t regress again.) --Lucas Werkmeister (talk) 22:08, 8 December 2025 (UTC)Reply
I suggest sandboxing your code and use some test cases to verify it works — Martin (MSGJ · talk) 15:10, 9 December 2025 (UTC)Reply
Agree. Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 15:36, 9 December 2025 (UTC)Reply
What do you mean, “my code”? This isn’t my module. And I did extract the code as far as possible and tested it, that’s what you’re seeing on Special:Permalink/1326419901. Lucas Werkmeister (talk) 17:44, 9 December 2025 (UTC)Reply
Sorry, I think I misunderstood what you meant and overreacted… I thought “sandboxing” meant you were expecting me to refactor the whole module (some 3500 lines long) to make it more testable in isolation. I’m now guessing you meant putting the code into the /sandbox subpage (I wasn’t aware of such a meaning of “sandbox” as a verb before, but then I don’t move around much in the technical namespaces of enwiki).
But I’ve done that, haven’t I? I’ve updated the /sandbox page again, and my previous test case at Special:Permalink/1325240674 still behaves correctly with the improved sandbox code; it’s unclear to me how I’m supposed to test the error reported at Abu Mus and Lindisfarne (how do you “thread” the /sandbox usage through X layers of intermediate templates?), but I tested that situation in isolation at Special:Permalink/1326419901 and as far as I can tell the new version ought to behave correctly there. I don’t know what else I’m supposed to test without having access to the “preview page with this template” feature, which ought to make it trivial for the person fulfilling the edit request to check how Abu Mus and Lindisfarne behave with the new version. Lucas Werkmeister (talk) 18:10, 9 December 2025 (UTC)Reply

Template:Od I assume Martin was referring to your comment: "But you, unlike me, should be able to try it out using the “preview page with this template” feature, to make sure that Abu Musa and Lindisfarne don’t regress again."

It's normal that the person requesting the change tests it before-hand. Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 19:16, 9 December 2025 (UTC)Reply

I understand that, but what I keep trying to say is that I believe I’ve tested the change as much as I reasonably can, and you ought to be able to further test it in a way that I’m simply unable to. Lucas Werkmeister (talk) 20:59, 9 December 2025 (UTC)Reply
(Reactivating the edit request as there’s been no response for while and I would still like the edit to be made.) --Lucas Werkmeister (talk) 11:40, 27 December 2025 (UTC)Reply
Template:Done taavi (talk!) 11:47, 27 December 2025 (UTC)Reply
Thank you! Let’s hope it works better this time. Lucas Werkmeister (talk) 17:37, 27 December 2025 (UTC)Reply

Trying to retrieve just a qualifier value, unable to make sense of the documentation

I'm trying to retrieve the qualifier value "2021" on its own from Lua error in Module:Wd at line 633: attempt to index field 'wikibase' (a nil value). (P585) of Lua error in Module:Wd at line 633: attempt to index field 'wikibase' (a nil value). (P1082) on Lua error in Module:Wd at line 633: attempt to index field 'wikibase' (a nil value). (Q133291). I can get the population and the year using {{#invoke:WikidataIB|getValue|P1082|qual=P585|ps=3}}, yielding "14,355 (2021)" (the latest sourced population figure). I would like an invocation that returns just "2021", but I have been unsuccessful in using qual= or pval= or getQualifierValue. What is the magic incantation that I need? – Jonesey95 (talk) 20:42, 18 December 2025 (UTC)Reply

I don't think it is possible using this module, as pval only seems to work with values with are wikibase items. I could write you some code to do this, but would need a bit more information. What should happen if there are two values marked as preferred? What should happen if there are no preferred values? What if the preferred value is not the most recent? — Martin (MSGJ · talk) 22:03, 18 December 2025 (UTC)Reply
 {{#invoke:WikidataIB|getValue|qid=Q133291|P1082|qual=P585|rank=best|fwd=ALL|qualsonly=true|noicon=true}}
Regs, The Equalizer (talk) 22:23, 18 December 2025 (UTC)Reply
Thanks The Equalizer, that works perfectly. This was for Template:Infobox_Russian_inhabited_locality/sandbox. See the talk page. I had successfully retrieved the most recent sourced population estimate, and I wanted to take the date that matches that population and put it into |pop_est_as_of=. I had tried a few different things, but not the combination above. – Jonesey95 (talk) 22:43, 18 December 2025 (UTC)Reply