Module talk:Wd

This is an old revision of this page, as edited by Trappist the monk (talk | contribs) at 14:52, 26 August 2025 (Handling of Wikidata refs - empty titles and missing properties). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Support for P5017 last update

@Thayts and Janhrach: Hi. Is it possible to add support for P5017 last update property? It seems to be perfectly valid citation/reference property for continuously updated sources to indicate last-update date of the version actually cited and it is being used all over WD this way, see backlinks and stat. Right now rendering attempt of a citation having this property filled here on enwiki leads to a nasty error output:

{{#invoke:wd|reference|Q733993|P2046}}[1]
  1. ^ Error: Unable to display the reference from Wikidata properly. Technical details:
    • Reason for the failure of {{Cite web}}: The Wikidata reference contains the property last update (P5017), which is not assigned to any parameter of this template.
    • Reason for the failure of {{Cite Q}}: The Wikidata reference contains the property last update (P5017), which is not assigned to any parameter of this template.
    See the documentation for further details.

On other wikis such citations are citable at least, even if the last update value is not used. E.g.: [1].

If there really is a good reason to keep current strict semantics (i.e. to fail with error on any unknown/unmapped citation property instead of just ignoring it or maybe including some hidden note and a monitoring cat. assignment), maybe an explicit whitelist of "tolerated" though unused citation properties would be useful. It doesn't make much sense to be completely unable to render citations that are valid on WD itself and renderable on other projects. And another negative side effect of this approach is that if anyone adds such an unsupported property on WD side later, unaware of the limitations of this module, it will introduce an unintentional error here, that is out of control of the original author, who inserted a (then working) citation. That's definitely not nice behavior. --Teslaton (talk) 18:41, 24 November 2024 (UTC)Reply

Hello, sorry for the late reply.
As for adding P5017, it is of course possible. Which Cite-web parameter should it be mapped to? Should it override publication date?
Note that wikidata:Help:sources does not mention this property at all, which, in itself, is not a problem. I am mentioning the Wikidata page because it is worth noting that references on Wikidata aren't really standardized. That page is, at least in my knowledge, the only one to say something about formatting references, yet it seems to be far from complete.
Unfortunately, there is no simple way to fix the citation-rendering function to just ignore unknown properties – outputting an error on failure is an inherent property of the (very simple) algorithm, as long as we want it to always produce understandable results. For example, an exteral id property (together with a "stated in" property) is sufficient to generate a Cite-web citation. However, this combination is also sufficient to create a Cite-Q citation. How should the module decide which citation template to use?
The original algorithm solved this problem by not using a citation template if the Wikidata reference contained any properties not mapped to its parameters. If neither of the templates could be used, a fallback citation was generated. However, this fallback was removed (almost two years ago), because it was dissimilar to existing citation styles and sometime quite human-unfriendly.
This is a very conservative solution – it rarely produces gibberish citations (e.g. leaving out information essential to the reference), but always fails on atypical Wikidata citations.
If you have ideas for a better algorithm, please share your ideas.
PS: After finishing writing this reply, I got an idea: maybe a good solution would be to ignore properties that are unknown to both of the citation templates (and issue an invisible error when encountering them). I will think about it.
Janhrach (talk) 19:08, 5 December 2024 (UTC)Reply
Test: [1] Janhrach (talk) 20:27, 20 December 2024 (UTC)Reply

Gentlemen, please, any thought on this? --Teslaton (talk) 13:16, 2 December 2024 (UTC)Reply


References

  1. ^ Hustota obyvateľstva - obce [om7014rr] : Rozloha (Štvorcový meter) (in Slovak), Bratislava: Statistical Office of the Slovak Republic, 31 March 2025, Wikidata Q125653048, retrieved 24 April 2025

Proposed fix

I have implemented (in /sandbox) support for configuring the module (in /i18n) for using multiple Wikidata properties as sources for citation paramenters. These properties are ordered – each has it priority, which determines when to use the said property. I used this functionality to fix the above issue. (Both publication date and last update are used as a source for the date citation argument, but last update has higher priority.) I also used this mechanism to reimplement the usage of subject named as as a fallback for title. Your comments are welcome. Janhrach (talk) 16:48, 6 July 2025 (UTC)Reply

  Done. Implemented. Janhrach (talk) 19:55, 22 July 2025 (UTC)Reply

Intenationalisation of dates

Hi, a Spanish Wikipedian noted that dates in Spanish use the article "de". For instance, "10 november 1992" will be "10 de noviembre de 1992". Is there a way to account for this in the i18n code? Julius Schwarz (talk) 08:31, 5 June 2025 (UTC)Reply

Actually, secondary question: is there a way to account for the plural form for currencies? Like "1 euro, 2 euros". Julius Schwarz (talk) 08:33, 5 June 2025 (UTC)Reply
Unfortunately, both of these behaviors are hardcoded and are not (yet) configurable. Janhrach (talk) 18:19, 7 June 2025 (UTC)Reply
Thanks! Julius Schwarz (talk) 07:20, 9 June 2025 (UTC)Reply
Actually @Janhrach, even though this is not currently feasible in Wd, how would you go about adding an "s" to the currency in a forked module? Assuming the currency value is always plural. Julius Schwarz (talk) 07:24, 9 June 2025 (UTC)Reply
Has Ahecht already answered your questtion? Janhrach (talk) 18:17, 12 June 2025 (UTC)Reply
Yes, he has, thanks for asking @Janhrach Julius Schwarz (talk) 20:18, 12 June 2025 (UTC)Reply
@Janhrach Maybe the changes made to Module:European and national party data/Wd can be useful to Module:Wd? Julius Schwarz (talk) 20:19, 12 June 2025 (UTC)Reply
Maybe. I have some work to do in the sandbox, which I want to finish before I start doing anything else related to this module. Janhrach (talk) 13:36, 15 June 2025 (UTC)Reply
@Julius Schwarz For the first case, are you trying to output the date in that format? If so, as long as the input date is the raw "1992-11-10" or in English, you could set up the code to run the date through something like lang:formatDate( i18n.fullDate, '1992-11-10') and then, for Spanish, set i18n.fullDate = 'n \\d\\e F \\d\\e Y'. --Ahecht (TALK
PAGE
)
14:14, 9 June 2025 (UTC)Reply
Thanks a lot, @Ahecht. In the meantime, a Spanish contributor, @Leoncastro, helped out here and here, in case you want to have a look! Julius Schwarz (talk) 14:37, 9 June 2025 (UTC)Reply
PS: @Ahecht, would you know how to hard-code a plural for the currency, by any chance? Julius Schwarz (talk) 18:34, 9 June 2025 (UTC)Reply
@Julius Schwarz If you modify your module to do two calls to Module:Wd, one with the raw flag and one with the data flag, you can then do something like if amount > 1 then unit = unit .. 's' end (and you would then have an override for languages such as Swedish where the plural of 'krone' is 'kroner'). I suppose you could also I did update Module:European and national party data/sandbox so that you can request the unit from allpp_get_data() or xlate_wikidata(). --Ahecht (TALK
PAGE
)
20:53, 9 June 2025 (UTC)Reply
Thanks @Ahecht. First time not lucky :D Did I get your unit=yes/no right? Julius Schwarz (talk) 14:28, 10 June 2025 (UTC)Reply
@Julius Schwarz I don't have time to debug your code, but I think you need to specify raw=yes to get it without the unit. When I uncomment the 2nd-to-last line of the module (the one that exports xlate_wikidata) and run =p.xlate_wikidata('property', 'Q950179', 'P12919', '', '', '', '', '', '', 'unit=yes') in the console it returns euro and when I do =mw.getContentLanguage():formatNum(tonumber(p.xlate_wikidata('property', 'Q950179', 'P12919', '', '', '', '', 'raw=yes', '', ''))) it returns 171,460.56. --Ahecht (TALK
PAGE
)
15:10, 10 June 2025 (UTC)Reply
Thanks @Ahecht. I will check it out and try and fix it. I guess what I was trying to say is that I am not really sure how the "unit" bit works. Julius Schwarz (talk) 20:18, 10 June 2025 (UTC)Reply
@Ahecht second time almost lucky! That did help, but somehow we lose the thousand delimiter in the process :S Julius Schwarz (talk) 09:31, 11 June 2025 (UTC)Reply
@Julius Schwarz The mw.getContentLanguage():formatNum(tonumber()) part above around the raw currency amount should fix that. --Ahecht (TALK
PAGE
)
13:15, 11 June 2025 (UTC)Reply
@Ahecht took a bit of tinkering but I think it is working, thanks a lot! Julius Schwarz (talk) 13:26, 11 June 2025 (UTC)Reply

Seeking most recent value

When seeking a value such as a population via this template, Wikidata will often have multiple values with different point in time (P585) qualifiers. Sometimes the most recent one will be given a preferred rank but sometimes not. Is there any way to ask it to retrieve the most recent one? I don't think (?) the future/current/former flags can work for this, both because they rely only on start time (P580)/end time (P582), not on point in time (P585), and because even if they did, the most recent value would just be one instance of a former value and wouldn't be prioritized if the other happened to be listed first.

I asked about this a few years ago and @Thayts mentioned something in the works; has there been progress on it? Sdkbtalk 22:37, 28 July 2025 (UTC)Reply

Specifying URL alive/dead status

Citations with archive URLs are displayed differently when the URL is specified as alive via |url-status=live vs. when it's specified as dead or not specified (see first paragraph of here). Would it be possible to create a way for this template to likewise specify URL status? Sdkbtalk 00:22, 29 July 2025 (UTC)Reply

Yes, maybe sometime in the future, but it is not supported right now. Janhrach (talk) 16:20, 7 August 2025 (UTC)Reply

Handling of Wikidata refs - empty titles and missing properties

We have a problem on cywiki where we have pages taking references from Wikidata. In 2023, @Janhrach very kindly forked the code and applied some additional handling to prevent visible errors. Time moves on and the code in the module has been refactored. I applied this version but it shows errors again - see https://cy.wikipedia.org/wiki/8_Mile

I would like to keep the module up-to-date, so I had various attempts to re-apply the previous fix - but as variables have changed, it's quite tricky. There are also some more significant errors regarding those properties such as Rotten Tomatoes and Meta Critic, which is potentially easier to fix. Is there a possibility of handling this in an easier way? I would prefer not to put in special handling just for us as it limits future updates, but it would be good to know what's feasible. I could revert my changes to what was working, but I suspect that I would also need to revert other updates to Citation/CS1 modules as well. Thank you. Dafyddt (talk) 22:42, 22 August 2025 (UTC)Reply

Regarding the specific errors you have mentioned, the problem was that Wikidata says that references citing online databases need to contain both stated in (P248) and a property of the External identifier data type, while the references causing errors contained only the latter. This may seem like a minor technicality, but database references are handled by an ugly hack in the module, and I do not want to make this hacky code more complicated to support references like this. I plan to fix this issue by creating a separate template for citing database references; this will hopefully also eliminate cryptic error messages like these.
As for re-introducing the cywiki fix, the old code is probably of little use, because the code has changed quite a lot. If it is really needed, I can try to reimplement it, but I would strongly prefer if you waited until I make the fix I have mentioned in the previous paragraph.
Also, regarding the changes since I made the cywiki fix, there were two of them that are especially relevant here:
  • I added verbose error messages. They should mostly be comprehensible after reading the documentation. I agree though that the errors you have mentioned are hard to understand; I will fix that.
  • |title= is no longer a mandatory param for {{Cite web}}. In practice, this means that missing titles in references do not cause errors in this module, but in the citation template, like you see in the article you have linked. This hopefully made the errors more understandable. When I create the database-citation template, many of these missing-title errors could be eliminated.
Janhrach (talk) 14:19, 26 August 2025 (UTC)Reply
|title= is no longer a mandatory param for {{Cite web}}. False. I don't know where you got that idea but you are mistook. |title= is, and likely will always be, required by {{cite web}}. If you have found some place where it is stated that |title= is not required, name that place so that it can be visited and fixed.
Trappist the monk (talk) 14:40, 26 August 2025 (UTC)Reply
I meant that this module does not consider it mandatory. I wrote that this means that missing titles in references do not cause errors in this module, but in the citation template[...] Janhrach (talk) 14:43, 26 August 2025 (UTC)Reply
Yes, I saw that, but your initial declaration that |title= is not required by {{cite web}} is false. That declaration cannot be allowed to stand unchallenged.
Trappist the monk (talk) 14:52, 26 August 2025 (UTC)Reply