Module talk:Wikidata
This is the talk page for discussing improvements to the Wikidata module. |
|
Archives: 1, 2Auto-archiving period: 6 months ![]() |
![]() | Use Wikipedia talk:Wikidata for general Wikidata support discussions |
|
||
This page has archives. Sections older than 180 days may be automatically archived by Lowercase sigmabot III when more than 3 sections are present. |
QID lookup from enwp article title
Using getValue to get the next or previous episode of a given TV series
How would I use the getValue function to get the next or previous episode of a given TV series? --Gonnym (talk) 07:06, 9 August 2019 (UTC)
- @Gonnym: If the data exists on Wikidata, then it's fairly easy. Take Friends S1 E4, as an example. It has a Wikidata entry, The One with George Stephanopoulos (Q20785929). That has two statements with properties follows (P155) and followed by (P156). So:
{{#invoke:WikidataIB |getValue |fwd=ALL |osd=n |P155 |qid=Q20785929}}
→ The One with the Thumb{{#invoke:WikidataIB |getValue |fwd=ALL |osd=n |P156 |qid=Q20785929}}
→ The One with the East German Laundry Detergent
- Note that the first one (S1 E3) has its own article, and the second (S1 E5) is a redirect. WikidataIB should handle those okay.
- Using Module:Wikidata:
{{#invoke:Wikidata |getValue |P155 |qid=Q20785929 |FETCH_WIKIDATA}}
→ The One with the Thumb{{#invoke:Wikidata |getValue |P156 |qid=Q20785929 |FETCH_WIKIDATA}}
→ The One with the East German Laundry Detergent
- That also works fine. --RexxS (talk) 14:40, 9 August 2019 (UTC)
- Is there a way to get the
|qid=
with the episode name? I'm researching if there is a way to add this feature to {{Infobox television episode}}, but if the episode ID needs to be manually added, then it won't work. --Gonnym (talk) 14:44, 9 August 2019 (UTC)- @Gonnym: You mean use the current page's linked qid? Just don't supply it and the function uses the associated qid for whatever page it's on. That works on all of the functions. You can paste the following into a section of The One with George Stephanopoulos and preview it to test:
{{#invoke:WikidataIB |getValue |fwd=ALL |osd=n |P155 |qid={{{qid|}}}}}
{{#invoke:WikidataIB |getValue |fwd=ALL |osd=n |P156 |qid={{{qid|}}}}}
{{#invoke:Wikidata |getValue |P155 |qid={{{qid|}}} |FETCH_WIKIDATA}}
{{#invoke:Wikidata |getValue |P156 |qid={{{qid|}}} |FETCH_WIKIDATA}}
- Obviously, once it's used in a infobox, you can then supply the
|qid=
to test the infobox outside of the article (the whole purpose of the qid parameter is to allow testing and examples like this). --RexxS (talk) 15:06, 9 August 2019 (UTC)- Ah, I didn't know; that's exactly what I wanted. Thanks RexxS, I'll test this now. --Gonnym (talk) 15:18, 9 August 2019 (UTC)
- @Gonnym: You mean use the current page's linked qid? Just don't supply it and the function uses the associated qid for whatever page it's on. That works on all of the functions. You can paste the following into a section of The One with George Stephanopoulos and preview it to test:
- Is there a way to get the
- There is a scenario where the title of the episode is a crossover (Touch of Death (crossover event)) and I know the TV series name and the "current" episode name. Is there a way to get the
|qid=
from these names? --Gonnym (talk) 11:23, 10 August 2019 (UTC)- @Gonnym: I'm not sure I understand what you want by
Is there a way to get the
There needs to be more data available at Touch of Death (Q65049550) if you want to use it - consider adding has part(s) (P527) for each constituent episode. However if you just want the qid of a value of a property, then the function|qid=
from these names?followQid
will do that for you (check the documentation in the code). For The One with the Thumb (Q20785993) and followed by (P156):{{#invoke:WikidataIB |followQid |props=P156 |qid=Q20785993}}
→ Q20785929
- That gives the qid for The One with George Stephanopoulos (Q20785929). Cheers --RexxS (talk) 14:44, 10 August 2019 (UTC)
followQid takes three optional parameters: qid, props, and all. If qid is not given, it uses the qid for the connected page
- if I'm understanding this correctly, then this isn't helpful in my scenario. I'll explain again. I want to invoke getValue() from page A and get results for a different WikiData item (page B). So let's say I'm on the page of The One with the Thumb, I want to know if it's possible to pass the title of another en.wiki article and use getValue with it (again, without using qid, only article title). --Gonnym (talk) 14:51, 10 August 2019 (UTC)- Any Scribunto module that wants to access data from Wikidata has to determine which Wikidata entity it is going to use. Each of those entities is uniquely identified by its entity-ID, the Q-number (qid), not by a title because Wikidata is a fully multilingual site and the same Wikidata entity can be associated with articles in many different languages. Because the association between a particular Wikipedia article title and the corresponding Wikidata entity is only stored in that Wikidata entity, the data that is exposed to Scribunto is a one-way association: that is, if you know the qid of a Wikidata entity, you can simply determine the title of the associated en-wiki article using code that runs anywhere, but not the other way round. Sorry I can't help with that.
- On the other hand, if page B is the value of a property for page A, then we can use
getPropOfProp
on page A to retrieve values of properties on page B, but that's not using the title of page B. If we want to get info (for example: Rotten Tomatoes ID (P1258)) for The One with George Stephanopoulos (Q20785929) from the The One with the Thumb (Q20785993) article, we can use the relationship that Q20785929 follows Q20785993:{{#invoke:WikidataIB |getPropOfProp |prop1=P156 |prop2=P1258 |fwd=ALL |osd=n |noicon=t |qid=Q20785993}}
→ tv/friends/s01/e04
- which is the Rotten Tomatoes ID for The One with George Stephanopoulos. Incidentally, that ID is useful because it tells you the season and episode. --RexxS (talk) 16:03, 10 August 2019 (UTC)
- Thanks for that explanation. I was hoping there was a reverse lookup using the en.wiki title value which produces a valid wikidata ID (which tbh, should really be a valid method). Adding the information to wikidata while overall good, isn't helpful in this situation, as I'm trying to automate this. --Gonnym (talk) 16:36, 10 August 2019 (UTC)
- I just noticed you added getEntityFromTitle() to Module:WikidataIB which if I'm not mistaken is exactly what I needed. --Gonnym (talk) 17:58, 12 August 2019 (UTC)
- @Gonnym: I'm not sure I understand what you want by
Error related to i18n
@RexxS: At Malaybalay, {{PH wikidata}} causes an error as it calls this module, which calls Module:i18n to load i18n data, but Module:Wikidata/i18n is empty and does not contain the required res.i18n
table. I think line 89 should be commented as it's clearly not used (yet). Thayts ••• 16:42, 29 September 2019 (UTC)
- Hi, Thayts, I stopped active work on Module:Wikidata over three years ago when I shifted my efforts into creating Module:WikidataIB specifically for use in infoboxes. The functions in there are now much more up-to-date and I'd really recommend using that in preference to this module, which contains an amalgamation of all sorts of code from different Wikipedias.
- The Module:Wikidata/i18n returns an empty table, which is pretty much what I'd expect as the internationalisation for en-wiki is in lines 16–80. The point of the Module:Wikidata/i18n was to allow other wikis to create their own values, which would overwrite those in lines 16–80 as needed when the module was loaded. If you were to comment out line 89, that would mean that other wikis would have to re-enable it every time they do an update from here.
- The code that used to handle it (without problem as far as I can recall) was changed in these edits, so I can't tell you what the reasoning was.
- Instead, I suggest you check line 83 of Module:WikidataIB:
which may offer a solution for you, while retaining the ability of non-English wikis to use the code from here, along with their own internationalisation from their version of Module:Wikidata/i18n. --RexxS (talk) 19:29, 29 September 2019 (UTC)if 'en' ~= mw.getContentLanguage():getCode() then
- Alright. Well, I don't know how, but the error(s) suddenly disappeared. Thayts ••• 20:09, 29 September 2019 (UTC)
- So this happened. Probably not related to this module then. Thayts ••• 07:05, 30 September 2019 (UTC)
- @RexxS: Turns out I have to reconsider again. This is a problem with this module (as we found out). However, I don't have the rights to change this module... Thayts ••• 20:47, 30 September 2019 (UTC)
- @Thayts: I've modified the code to only load Module:Wikidata/i18n on non-English wikis. See if that helps. --RexxS (talk) 21:04, 30 September 2019 (UTC)
- That is not a solution for the other wikis, but alas. Thayts ••• 21:47, 30 September 2019 (UTC)
- The real solution for other wikis is not to use this module. It has no regular maintainer and doesn't get updated. For example, it still uses the expensive
mw.wikibase.getEntityObject()
calls, which were replaced more than a year ago in Module:WikidataIB. --RexxS (talk) 23:38, 30 September 2019 (UTC)- It would be great if we had just one wikidata module and you all worked together to keep it maintained :) — Martin (MSGJ · talk) 10:54, 11 October 2019 (UTC)
- The real solution for other wikis is not to use this module. It has no regular maintainer and doesn't get updated. For example, it still uses the expensive
- That is not a solution for the other wikis, but alas. Thayts ••• 21:47, 30 September 2019 (UTC)
- @Thayts: I've modified the code to only load Module:Wikidata/i18n on non-English wikis. See if that helps. --RexxS (talk) 21:04, 30 September 2019 (UTC)
Get a single QID
Hello. How can I get only the preferred value (i.e. limit to only the best ranked value), when using this code: {{#invoke:Wikidata|getPropertyIDs|P516|qid={{{qid|}}}|FETCH_WIKIDATA}}
? I'm looking for something like the |rank=best
and/or |maxvals=1
functions in Module:WikidataIB. Rehman 10:49, 13 October 2019 (UTC)
- @Rehman: I've implemented the function in WikidataIB so that you should have full use of ranks, onlysourced, maxvals, sorted, etc. as usual.
{{#invoke:WikidataIB/sandbox |getPropertyIDs |qid=Q151973 |P26 |fwd=ALL |osd=n}}
→ Q34851, Q7659507, Q16770428, Q34851, Q3469983
- Let me know if any features are missing. I've set
|noicon=
to default to true but you can enable it with|noicon=false
, if required. Cheers --RexxS (talk) 18:02, 13 October 2019 (UTC)- Thank you, RexxS. It works great! Rehman 02:33, 14 October 2019 (UTC)
Deprecation
This module was marked as deprecated but has 487,638 transclusions. I'm assuming this most come from a few highly transcluded templates. Can anyone help finding those usages? It will give us a star start with converting to Module:WikidataIB and Module:Wd. --Gonnym (talk) 15:27, 2 January 2020 (UTC)
- Here are the transclusions in template space. From that page, click on "links" next to any template name and then click "Transclusion count".
- {{Infobox AFL biography}}: 13,600
- {{Infobox CFL biography}}: 6,161
- {{Infobox Gaelic Athletic Association player}}: 4,187
- {{Infobox anatomy}}: 4,449
- {{Infobox award}}: 7,361
- {{Infobox book}}: 44,111
- {{Infobox college coach}}: 10,000
- {{Infobox lighthouse}}: 2,535
- {{Infobox religious building}}: 9,368
- {{Infobox volleyball biography}}: 4,734
- {{Wikidata sitelink}}: 6,819 (used in the "Expand xxx" templates, so if you get this one, at least 145 templates will be removed from the list)
- {{Wikisource author}}: 4,681
- {{Infobox video game}}: 24,086
- That looks like about 150,000 transclusions. Start there, and if you get through that list, come back and I'll take another look. – Jonesey95 (talk) 17:23, 2 January 2020 (UTC)
- Your assumption is probably correct; remaining requires uses are limited to sandboxes. I suppose someone could invoke the module through wikitext in a module by preprocessing, but I find that less likely (for the curious; most look like documentation and comments). --Izno (talk) 18:23, 2 January 2020 (UTC)
- This is a search of template space for #invoke. There are some 200 templates using the module. --Izno (talk) 18:25, 2 January 2020 (UTC)
- That's a good search. That led me to:
- {{Birth date}}: 269,902 transclusions
- {{Infobox power station}}: 2,471 transclusions
- {{Death date}}: 8,443 transclusions
- {{Birth year and age}}: 25,891 transclusions
- {{Wikidata redirect}}: 25,963 transclusions
- Have fun! – Jonesey95 (talk) 18:36, 2 January 2020 (UTC)
- Thanks for the lists!
- Anyone know how to find an article that uses {{Infobox AFL biography}} and gets the image from wikidata? [1] fails. --Gonnym (talk) 18:43, 2 January 2020 (UTC)
- Query for the presence of P3546 and P18 in the same item. I don't know how to do it. – Jonesey95 (talk) 23:28, 2 January 2020 (UTC)
- @Gonnym: Looks like 25,260 results on Wikidata: see this query. I can't easily tell you how many of those have articles, though. --RexxS (talk) 23:57, 2 January 2020 (UTC)
- P.S. Category:Pages using Wikidata property P3546 shows 13,302 articles using {{Infobox AFL biography}} and having a AustralianFootball.com player ID (P3546). You need the intersection of those two sets. --RexxS (talk) 00:01, 3 January 2020 (UTC)
- Your first link helped me find an article that has a Wikidata:Q5214052 image. On Dan Moriarty (footballer, born 1875) I'm using
{{#invoke:WikidataIB|getValue|P18}}
on the page to test the code but it doesn't return the image. What am I doing wrong? --Gonnym (talk) 00:12, 3 January 2020 (UTC)- @Gonnym: Because
WikidataIB|getValue
is used in articles where the editors insist that fetching Wikidata has to be enabled (i.e. it is disabled by default), you always have to specify further parameters to enable the fetch. The simplest way is to use|ps=1
like this for Dan Moriarty (Q5214052):{{#invoke:WikidataIB|getValue|P18|ps=1|qid=Q5214052}}
→ Dan Moriarty (before 1903).jpg
- Obviously, you don't need the qid if you're calling it from the article's own page. HTH --RexxS (talk) 00:22, 3 January 2020 (UTC)
- Is
|ps=
missing from the doc? I couldn't find it there. Anyways, {{Infobox AFL biography/sandbox}} seems to work.
- Is
- @Gonnym: Because
- Your first link helped me find an article that has a Wikidata:Q5214052 image. On Dan Moriarty (footballer, born 1875) I'm using
- Query for the presence of P3546 and P18 in the same item. I don't know how to do it. – Jonesey95 (talk) 23:28, 2 January 2020 (UTC)
- That's a good search. That led me to:
Template name | No. of transclusions | Test page(s) | Status |
---|---|---|---|
{{Infobox AFL biography}} | 13,600 | Dan Moriarty (footballer, born 1875) | Waiting sandbox review |
{{Infobox CFL biography}} | 6,161 | ||
{{Infobox Gaelic Athletic Association player}} | 4,187 | ||
{{Infobox anatomy}} | 4,449 | ||
{{Infobox award}} | 7,361 | ||
{{Infobox book}} | 44,111 | The Red Pyramid (Library of Congress) Under Fire (Blackwood novel) (website) - Not able to get website to show using the infobox. |
Waiting sandbox review |
{{Infobox college coach}} | 10,000 | ||
{{Infobox lighthouse}} | 2,535 | ||
{{Infobox religious building}} | 9,368 | ||
{{Infobox volleyball biography}} | 4,734 | ||
{{Wikidata sitelink}} | 6,819 | ||
{{Wikisource author}} | 4,681 | ||
{{Infobox video game}} | 24,086 | ||
{{Birth date}} | 269,902 | Atia Abawi (no value on wikidata) Abraham Lincoln (has value) |
Waiting sandbox review |
{{Infobox power station}} | 2,471 | ||
{{Death date}} | 8,443 | ||
{{Birth year and age}} | 25,891 | ||
{{Wikidata redirect}} | 25,963 | Abel | Waiting sandbox review |
Following the discussion at Template talk:Medical resources #Template-protected edit request on 3 December 2019, I was hopeful that somebody else would add the documentation for a change, so I apologise for not doing it sooner. It's documented now. There's probably no more than a handful of undocumented parameters and calls left now. --RexxS (talk) 18:01, 3 January 2020 (UTC)
Infobox AFL biography
When I remove the |image=
value from Dan Moriarty (footballer, born 1875) (leaving a blank parameter), no image is shown, using either the live template or the sandbox template. It seems like an image should be shown. – Jonesey95 (talk) 16:16, 3 January 2020 (UTC)
- Some template editors decide to code parameters as A|B which means that if A is there, even blank, it doesn't show B. I personally code with {{If empty |A |B }} which means that if A is empty, it checks B. I didn't change the syntax there, just the module invoke. --Gonnym (talk) 16:19, 3 January 2020 (UTC)
- @Gonnym and Jonesey95: To produce its image, Template:Infobox AFL biography calls Module:InfoboxImage, which returns empty if the image parameter is missing or empty. So it should be no surprise that removing the value of
|image=
from an article results in no image. However, Module:WikidataIB treats a blank parameter the same as a missing parameter, so in the#invoke:InfoboxImage|InfoboxImage
, if you use the syntax:|image={{#invoke:WikidataIB |getValue |P18 |ps=1 |maxvals=1 |{{{image|}}} }}
- it will return the Wikidata value whenever
|image=
is empty or missing in the article. It relies on getValue always returning the local parameter if one is supplied to it as the second unnamed parameter, and is intended to simplify the template coding. This is possibly what Jonesey95 was looking for. --RexxS (talk) 17:52, 3 January 2020 (UTC)- That works for me in the sandbox. – Jonesey95 (talk) 18:10, 3 January 2020 (UTC)
- @Gonnym and Jonesey95: To produce its image, Template:Infobox AFL biography calls Module:InfoboxImage, which returns empty if the image parameter is missing or empty. So it should be no surprise that removing the value of