Module talk:WikidataIB/Archive 6
![]() | This is an archive of past discussions about Module:WikidataIB. Do not edit the contents of this page. If you wish to start a new discussion or revive an old one, please do so on the current talk page. |
Archive 1 | ← | Archive 4 | Archive 5 | Archive 6 | Archive 7 | Archive 8 |
Retrieving nth value using #invoke:WikidataIB
- Also posted at data:Wikidata:Project_chat
Is it possibly to retrieve an nth value from wikidata within a property. E.g. for a person to retrieve the first listed occupation separately to the second, the third etc? Example:
{{#invoke:WikidataIB| getQualifierValue| qid=Q15136093| P106| pval=Q3809586| qual=P108| name=occupation| fetchwikidata=ALL}}
returns me the whole list of employers when I use it here, or just the first one if I use it over at wikidata's talkpages. T.Shafee(Evo&Evo)talk 02:05, 21 September 2019 (UTC)
-
{{#invoke:WikidataIB |getQualifierValue |qid=Q15136093 |P106 | pval=Q3809586 |qual=P108 |name=occupation |fetchwikidata=ALL |noicon=y}}
→ Staffordshire Record Office, Lancashire County Council’s Museum Service, TED, Queen Mary University of London, Museum Data Service
- Using the split function from Module:String2:
{{#invoke:String2 |split | txt={{#invoke:WikidataIB |getQualifierValue |qid=Q15136093 |P106 | pval=Q3809586 |qual=P108 |name=occupation |fetchwikidata=ALL |noicon=y}} |sep=", " |idx=1}}
→ Staffordshire Record Office{{#invoke:String2 |split | txt={{#invoke:WikidataIB |getQualifierValue |qid=Q15136093 |P106 | pval=Q3809586 |qual=P108 |name=occupation |fetchwikidata=ALL |noicon=y}} |sep=", " |idx=2}}
→ Lancashire County Council’s Museum Service{{#invoke:String2 |split | txt={{#invoke:WikidataIB |getQualifierValue |qid=Q15136093 |P106 | pval=Q3809586 |qual=P108 |name=occupation |fetchwikidata=ALL |noicon=y}} |sep=", " |idx=3}}
→ TED
- and so on. --RexxS (talk) 19:05, 21 September 2019 (UTC)
- @RexxS: Thank you - very logical now that I see it! One limitation though: For properties where not all values have an entry (e.g. end time (P582) of the example above), is there a way to ask invoke:WikidataIB to include an empty string for the missing value? In the example above end time (P582), |idx=3 should return an "" empty string but idx=4 should return "June 2013". Could a
|fulllist=
parameter be included to avoid removing repeat separators? T.Shafee(Evo&Evo)talk 23:57, 22 September 2019 (UTC)- @Evolution and evolvability: I'm not too certain what you're trying to achieve, so it's quite hard to guess at what code would be best. Can I suggest you have a look at what getValue can do with its qualifiers and see if that gives you a solution before I start re-coding, please? It can duplicate the functionality of getQualifierValue and quite a lot more now. Here are some examples using Andy Mabbett (Q15136093):
{{#invoke:WikidataIB |getValue |qid=Q15136093 |P106 |qual=P108 |qualsonly=y |fetchwikidata=ALL |noicon=y}}
→ Staffordshire Record Office, Lancashire County Council’s Museum Service, TED, Queen Mary University of London, Museum Data Service{{#invoke:WikidataIB |getValue |qid=Q15136093 |P106 |qual=P108 |fetchwikidata=ALL |noicon=y}}
→ Wikipedian in residence (Staffordshire Record Office), Wikipedian in residence (Lancashire County Council’s Museum Service), Wikipedian in residence (TED), Wikipedian in residence (Queen Mary University of London), author, consultant, freelancer, Wikipedian in residence (Museum Data Service){{#invoke:WikidataIB |getValue |qid=Q15136093 |P106 |qual=ALL |fetchwikidata=ALL |noicon=y}}
→ Wikipedian in residence (Staffordshire County Museum, Wikipedian in Residence, https://outreach.wikimedia.org/wiki/Wikipedian_in_Residence/SAHS, Staffordshire Record Office, 2013–2013), Wikipedian in residence (Queen Street Mill, Wikipedian in Residence, https://outreach.wikimedia.org/wiki/Wikipedian_in_Residence/QSMM, Lancashire County Council’s Museum Service, 2013–2014), Wikipedian in residence (TED, Wikipedian in Residence, 2016–2016), Wikipedian in residence (Wikimedian in Residence, Queen Mary University of London, London, https://en.wikipedia.org/wiki/Wikipedia:GLAM/HMBRG, History of Modern Biomedicine Research Group, 2017–2017), author, consultant (most frequent value), freelancer, Wikipedian in residence (Museum Data Service, Wikimedian in Residence, 2025–){{#invoke:WikidataIB |getValue |qid=Q15136093 |P106 |qual=ALL |fetchwikidata=ALL |noicon=y |prefix="''" |postfix="''"}}
→ Wikipedian in residence (Staffordshire County Museum, Wikipedian in Residence, https://outreach.wikimedia.org/wiki/Wikipedian_in_Residence/SAHS, Staffordshire Record Office, 2013–2013), Wikipedian in residence (Queen Street Mill, Wikipedian in Residence, https://outreach.wikimedia.org/wiki/Wikipedian_in_Residence/QSMM, Lancashire County Council’s Museum Service, 2013–2014), Wikipedian in residence (TED, Wikipedian in Residence, 2016–2016), Wikipedian in residence (Wikimedian in Residence, Queen Mary University of London, London, https://en.wikipedia.org/wiki/Wikipedia:GLAM/HMBRG, History of Modern Biomedicine Research Group, 2017–2017), author, consultant (most frequent value), freelancer, Wikipedian in residence (Museum Data Service, Wikimedian in Residence, 2025–){{#invoke:WikidataIB |getValue |qid=Q15136093 |P106 |qual=ALL |qualsonly=y |fetchwikidata=ALL |noicon=y |sep=" -- "}}
→ Staffordshire County Museum, Wikipedian in Residence, https://outreach.wikimedia.org/wiki/Wikipedian_in_Residence/SAHS, Staffordshire Record Office, May 2013 – June 2013 -- Queen Street Mill, Wikipedian in Residence, https://outreach.wikimedia.org/wiki/Wikipedian_in_Residence/QSMM, Lancashire County Council’s Museum Service, March 2013 – September 2014 -- TED, Wikipedian in Residence, January 2016 – July 2016 -- Wikimedian in Residence, Queen Mary University of London, London, https://en.wikipedia.org/wiki/Wikipedia:GLAM/HMBRG, History of Modern Biomedicine Research Group, April 2017 – August 2017 -- most frequent value -- Museum Data Service, Wikimedian in Residence, January 2025 –{{#invoke:WikidataIB |getValue |qid=Q15136093 |P106 |qual=P108, P580, P582 |qualsonly=y |fetchwikidata=ALL |noicon=y |sep=" -- "}}
→ Staffordshire Record Office, May 2013 – June 2013 -- Lancashire County Council’s Museum Service, March 2013 – September 2014 -- TED, January 2016 – July 2016 -- Queen Mary University of London, April 2017 – August 2017 -- Museum Data Service, January 2025 –{{#invoke:WikidataIB |getValue |qid=Q15136093 |P106 |qual=ALL |qualsonly=y |fetchwikidata=ALL |noicon=y |list=ubl}}
→- Staffordshire County Museum, Wikipedian in Residence, https://outreach.wikimedia.org/wiki/Wikipedian_in_Residence/SAHS, Staffordshire Record Office, May 2013 – June 2013
- Queen Street Mill, Wikipedian in Residence, https://outreach.wikimedia.org/wiki/Wikipedian_in_Residence/QSMM, Lancashire County Council’s Museum Service, March 2013 – September 2014
- TED, Wikipedian in Residence, January 2016 – July 2016
- Wikimedian in Residence, Queen Mary University of London, London, https://en.wikipedia.org/wiki/Wikipedia:GLAM/HMBRG, History of Modern Biomedicine Research Group, April 2017 – August 2017
- most frequent value
- Museum Data Service, Wikimedian in Residence, January 2025 –
{{#invoke:WikidataIB |getValue |qid=Q15136093 |P106 |qual=DATES |fetchwikidata=ALL |noicon=y}}
→ Wikipedian in residence (2013–2013), Wikipedian in residence (2013–2014), Wikipedian in residence (2016–2016), Wikipedian in residence (2017–2017), author, consultant, freelancer, Wikipedian in residence (2025–){{#invoke:WikidataIB |getValue |qid=Q15136093 |P106 |qual=DATES |qualsonly=y |fetchwikidata=ALL |noicon=y}}
→ May 2013 – June 2013, March 2013 – September 2014, January 2016 – July 2016, April 2017 – August 2017, January 2025
- I've recently updated the documentation, so it might pay to check what's possible using different pre/post-fixes and separators. Cheers --RexxS (talk) 01:37, 23 September 2019 (UTC)
- @RexxS: Apologies, I'll give a bit more detail. In this instance, I'm trying to automatically generate rows of a table such as this one, where each row details the a values of a property. In this case, for each instance of occupation = "Wikimedian in Residence", return organisation, location, start, and end dates. This all works fine when a person has only ever held a single WiR position, but if a person has held multiple WiR positions, only some of which have end dates, you end up with the end date column shifting upwards where empty cells should be (example). Eventually I'll template it so that generating rows only requires the QIDs. 05:35, 23 September 2019 (UTC)
- @Evolution and evolvability: Because most of the folks who use WikidataIB are template coders, rather than Lua coders, I've created some wrapper templates like Template:Stringsplit and Template:Wdib to condense the calls to modules such as String2 and WikidataIB. Using those can make your template more readable - just use
{{stringsplit
to replace{{#invoke:String2 |split
and{{wdib
in place of{{#invoke:WikidataIb |getValue
. You ought to consider using getValue instead of getQualifierValue. - I also created some helper templates like Template:If then show to do common tasks for template coders. That template tests whether a parameter is empty and displays it if it is, or returns another parameter if it isn't. That allows us to call Wikidata once and then test and display the result, or give something else if the result is blank, So we could provide a non-breaking space if the call was empty, thus creating an blank cell in the table for you.
- Having said all of that, it doesn't offer a solution for your problem. What you need is a non-empty value to pad out the returned list of qualifers, so that each list is the same length. The snag is that it can only work if we know how many items you want to be in the list. I'll have a look at how I can insert a non-empty value every time the qualifier has no value and let you know when I've coded it. --RexxS (talk) 16:43, 23 September 2019 (UTC)
- @Evolution and evolvability: Because most of the folks who use WikidataIB are template coders, rather than Lua coders, I've created some wrapper templates like Template:Stringsplit and Template:Wdib to condense the calls to modules such as String2 and WikidataIB. Using those can make your template more readable - just use
- @RexxS: Apologies, I'll give a bit more detail. In this instance, I'm trying to automatically generate rows of a table such as this one, where each row details the a values of a property. In this case, for each instance of occupation = "Wikimedian in Residence", return organisation, location, start, and end dates. This all works fine when a person has only ever held a single WiR position, but if a person has held multiple WiR positions, only some of which have end dates, you end up with the end date column shifting upwards where empty cells should be (example). Eventually I'll template it so that generating rows only requires the QIDs. 05:35, 23 September 2019 (UTC)
- @Evolution and evolvability: I'm not too certain what you're trying to achieve, so it's quite hard to guess at what code would be best. Can I suggest you have a look at what getValue can do with its qualifiers and see if that gives you a solution before I start re-coding, please? It can duplicate the functionality of getQualifierValue and quite a lot more now. Here are some examples using Andy Mabbett (Q15136093):
- @RexxS: Thank you - very logical now that I see it! One limitation though: For properties where not all values have an entry (e.g. end time (P582) of the example above), is there a way to ask invoke:WikidataIB to include an empty string for the missing value? In the example above end time (P582), |idx=3 should return an "" empty string but idx=4 should return "June 2013". Could a
Function qualsToTable
How does that look? It's only an early draft and needs internationalisation and a parameter for the placeholder (currently hard-coded as "-" so I can see what's happening), but you could play around with it for now and let me know what changes you want. --RexxS (talk) 22:31, 23 September 2019 (UTC)
- @RexxS: You're a champion, thank you. And it looks like it should be possible to merge into the current template I've been working on
{{WiR table row}}
. Thanks again. It looks like that should work perfectly! Some additional features that would improve functionality:- Having ymd dates (2019-08-30) would make the date columns sortable (and probably useful for other applications).
- Being able to include the qid and edit icon as the row's first item would be valuable (see
{{WiR table row}}
). Perhaps a parameter to omit the <tr> and </tr> tags to allow it be used in the middle of a row? - In case some of the urls are extremely long, it might be useful to be able to place the links inside [https://www.example.com custom text], but that might be over-specialised for the module.
- T.Shafee(Evo&Evo)talk 00:54, 24 September 2019 (UTC)
- @Evolution and evolvability: I've implemented date sorting using Template:Date table sorting inside the module. Using ISO-style dates in article text is generally not recommended (see MOS:DATEUNIFY). I know how to add a first column and have an idea for shortening the displayed urls. I'll do that later this evening. --RexxS (talk) 17:15, 24 September 2019 (UTC)
- Done. See if you can find any problems and let me know. Cheers --RexxS (talk) 21:47, 24 September 2019 (UTC)
- Postscript: I also implemented a parameter
|emptycell=
so you can choose what to have in the empty cells. It defaults to
, but you can set|emptycell=-
for a short dash. etc. --RexxS (talk) 21:59, 24 September 2019 (UTC)- @RexxS: Thank you again - I'll leave a link here once I've got the system up and running at outreach.wikimedia.org. T.Shafee(Evo&Evo)talk 23:41, 24 September 2019 (UTC)
- @Evolution and evolvability: I just spotted your suggestion about removing
<tr>...</tr>
. It can't work because the module outputs multiple rows and won't fit in a table in any other way. If you should need more than one extra column at the start of a row, you can just use something like|firstcol=Cell 1 value</td><td>Cell 2 value
. That would give two extra columns and could be extended as long as you only want a fixed value in each column. --RexxS (talk) 00:56, 25 September 2019 (UTC)- @RexxS: That makes sense. The
|firstcol=
works well for any of the use cases I can think of. Let me know when the functionality has been moved from the /sandbox into the main template. I'm asking or it to be imported over to outreachwiki here. T.Shafee(Evo&Evo)talk 02:00, 25 September 2019 (UTC) - @RexxS: Going well so far. A couple of urls shorten oddly though (e.g. (Q68772051#P106)). Any ideas? T.Shafee(Evo&Evo)talk 11:49, 29 September 2019 (UTC)
- @Evolution and evolvability: Its quite hard to cleanly shorten https://he.wikipedia.org/wiki/%D7%95%D7%99%D7%A7%D7%99%D7%A4%D7%93%D7%99%D7%94:%D7%9E%D7%99%D7%96%D7%9E%D7%99_%D7%95%D7%99%D7%A7%D7%99%D7%A4%D7%93%D7%99%D7%94/%D7%92%D7%9C%D7%90%D7%9D/%D7%A1%D7%A4%D7%A8%D7%99%D7%99%D7%AA_%D7%99%D7%95%D7%A0%D7%A1_%D7%95%D7%A1%D7%95%D7%A8%D7%90%D7%99%D7%94_%D7%A0%D7%96%D7%A8%D7%99%D7%90%D7%9F,_%D7%90%D7%95%D7%A0%D7%99%D7%91%D7%A8%D7%A1%D7%99%D7%98%D7%AA_%D7%97%D7%99%D7%A4%D7%94
- In Module:WikidataIB/sandbox, I've tried decoding the url before capturing the final word, so we would get:
- @RexxS: That makes sense. The
- @Evolution and evolvability: I just spotted your suggestion about removing
- @RexxS: Thank you again - I'll leave a link here once I've got the system up and running at outreach.wikimedia.org. T.Shafee(Evo&Evo)talk 23:41, 24 September 2019 (UTC)
Liron Dorfman Younes and Soraya Nazarian Library, University of Haifa אוניברסיטת חיפה Haifa August 2012 February 2013
- Would you have a chance to try out the sandbox for now, please? as I don't want to keep making minor alterations to the main module. As soon as you're happy, I'll update the main module, but let's dig out the bugs using the sandbox first. I suspect that there will be other occasions where we will need to use unicode string matching. --RexxS (talk) 18:47, 29 September 2019 (UTC)
@RexxS: Ok, I think I've finished with inputting all the relevant info to wikidata. See the table as it currently stands. The only thing that really to be edited in the module sandbx before merging into the main module and importing over to meta: is there any way to avoid the error message when the end date is 'unknown'. A question mark or similar would be better if possible. Finally, is there any way to avoid having to manually list the QID for each wikimedian in residence individually, and instead just list all Q for which P106==Q3809586? T.Shafee(Evo&Evo)talk 08:22, 27 October 2019 (UTC)
- @Evolution and evolvability: I've fixed the error message when the date is unknown and used "?" for the value. It's easy to change, just let me know.
- The only practical way to create a list of items from Wikidata that match a given criterion is to use a bot which interrogates the Wikidata Query Service and creates the list. One such bot is User:ListeriaBot, but unfortunately the output it creates doesn't suit the Luddites because if they alter it, it gets changed back the next time the bot is run. So the bot has been banned from from being used in mainspace. You'll have to do it manually, although you could use https://w.wiki/Asg to generate the list of WiRs for you whenever you need them. You could also use Listeriabot with that query to generate the list in your userspace, where it is not banned.
- Let me know when you're ready to update the main module. Cheers --RexxS (talk) 18:23, 27 October 2019 (UTC)
- Excellent. In that case, I think it is now ready to merge the sandbox into the main module so that it can also be imported over to meta and outreachwiki. I see what you mean about ListeriaBot. For the moment I'll see how the solution works with the table as currently set up. T.Shafee(Evo&Evo)talk 23:44, 27 October 2019 (UTC)
- @Evolution and evolvability: The main template is now synced with the sandbox. It's ready to go wherever you want. Cheers --RexxS (talk) 01:32, 28 October 2019 (UTC)
- Excellent. In that case, I think it is now ready to merge the sandbox into the main module so that it can also be imported over to meta and outreachwiki. I see what you mean about ListeriaBot. For the moment I'll see how the solution works with the table as currently set up. T.Shafee(Evo&Evo)talk 23:44, 27 October 2019 (UTC)
Last steps over at meta
@RexxS: Hi! The copy over at meta is so close to operational (see example meta:Wikimedian_in_residence) The only thing that doesn't seem to be operating is the date display, but no error message is being shown. Any guesses for what template/module is missing? T.Shafee(Evo&Evo)talk 10:30, 28 November 2019 (UTC)
- @Evolution and evolvability: the problem is that Meta has the Module:Complex date, but none of its dependencies. Have a look at Module:WikidataIB, lines 15 to 17, for a list of its eight dependencies. You'll have to arrange to have those imported from Commons, as well as re-importing the Commons version of Module:Complex date. The complication is that the English Wikipedia already had a Module:Date, so the modules here have been altered slightly to use a differently named module for Module:Date. --RexxS (talk) 17:23, 28 November 2019 (UTC)
Remove pen icon from every row in infoboxes
I find the pen icon to edit individual rows of infoboxes quite distracting and unsightly. See for example Arecibo Observatory.
Would it be possible to remove it? I think keeping [edit on Wikidata] option would be enough. Vpab15 (talk) 23:46, 18 December 2019 (UTC)
- There is a "noicon" option for the module. Infobox telescope doesn't seem to implement it, but look at Infobox video game for an example. -- ferret (talk) 00:05, 19 December 2019 (UTC)
- @Vpab15: I personally don't find the pen icon distracting and unsightly, but personal tastes differ. If the pen icon is disabled, other editors with different preferences may ask for it to be restored, so that doesn't bode well for finding a consensus on whether it should appear or not.
- It has the functionality of allowing editors who spot a mistake or vandalism to go directly to the place on Wikidata where they need to make the correction, so that in itself must be a argument to retain the links. In addition, under current plans, when mw:Wikidata Bridge is implemented, the pen icon will be needed to pop-up the proposed editing interface to directly edit Wikidata from within a Wikipedia article.
- Nevertheless, I could add a class to the icon, for example
class="penicon"
, which would then allow you to add a line to your common.css file:- .penicon { display: none; }
- The line would ensure that you never see the pen icons, although other readers would be unaffected. Would that represent an acceptable solution for you? --RexxS (talk) 02:55, 19 December 2019 (UTC)
- Thanks @Ferret:, @RexxS:. I agree it is a matter of taste, but the average Wikipedia reader would probably find it more puzzling and distracting than useful. I can live with it as it is now, although I appreciate the offer, RexxS. It is more a question of whether it is a better user experience to have the pen icons or to just have the "edit on Wikidata" link. Vpab15 (talk) 15:58, 19 December 2019 (UTC)
Output of currency values
Hi. Following-up on a previous discussion we had here some time back. Looking at an article like Ace Embilipitiya Power Station, can we craft a way to change the output of the "Construction cost" parameter (which currently displays as 8,000 million Rs (2005)
), so that it displays as Rs 8,000 million (2005)
instead (including links)? Rehman 13:08, 18 February 2020 (UTC)