Extension talk:Wikibase Client/Lua

mw.wikibase.getEntity
Is it possible to pass id to this function in order to get any entity? --DixonD (talk) 20:57, 27 March 2013 (UTC)
 * It is not possible yet. --Lydia Pintscher (WMDE) (talk) 10:54, 28 March 2013 (UTC)
 * Is it intentionally restricted or not? Bennylin (talk) 16:46, 18 September 2013 (UTC)
 * Look at the bug-49805 to develop. --Rical (talk) 23:58, 18 September 2013 (UTC)

Change Jens Ohlig's code at https://github.com/wikimedia/mediawiki-extensions-Wikibase/blob/master/client/resources/mw.wikibase.lua

from to I think this would work. Bennylin (talk) 18:19, 23 September 2013 (UTC)


 * I first answer on the bug-49805. Then I see your edit here. Very interesting, thanks. But probably with another function name like wikibase.get_Entity to not disturb the original Scribunto, and to test comparing the two fonctions. How to try it, because here I'm not admin, only in fr.wikisource. --Rical (talk) 22:58, 23 September 2013 (UTC)


 * Yes this would work. We have however intentionally restricted it and do not plan to change this for the time being. We need to solve caching and scalabillity issues first before we can allow access to data from arbitrary items. I know this isn't great but unfortunately needed. --Lydia Pintscher (WMDE) (talk) 21:37, 27 September 2013 (UTC)


 * Thanks for the confirmation. That's what I thought. Bennylin (talk) 10:35, 1 October 2013 (UTC)


 * Similar issue is with  and , which would have second argument (  and   accordingly) allowing to retrieve label in foreign language and interwiki link. Are there any chances for it? Or shall I wait until the bug described above is resolved? Paweł Ziemian (talk) 18:55, 17 October 2013 (UTC)

Troble while accessing personalia
I've written w:ru:Module:Wikibase but met a strange problem. If I try to write construction on any page having facts on Wikidata (Moscow, Mars, arctic fox), I get a pretty table. But on any personalia page (Jimbo, ru:Цзэн Чэн, Ossie Davis) I get only an error on line 51 of mw.wikibase.lua (attempts to index sitelinks which is nil). What to do? Ignatus (talk) 21:23, 3 April 2013 (UTC)
 * This is indeed a strange error. The sitelinks returned are definitely not nil on the items you gave as an example. A first glance at the code of the module you wrote didn't show anything unusual. Does the error persist? --Jens Ohlig (talk) 13:18, 5 April 2013 (UTC)
 * Yes, it's still an error with comment . Ah, I've got what causes this error: it's while trying to get   (male sex for humans, has no sitelinks). The function should be fixed to return nil silently in such cases, I believe. Ignatus (talk) 18:54, 6 April 2013 (UTC)
 * You are correct. I will commit a patch to solve this. Thanks for the error report! --Jens Ohlig (talk) 01:43, 7 April 2013 (UTC)
 * The patch now awaits approval at Gerrit Code Review--Jens Ohlig (talk) 01:54, 7 April 2013 (UTC)
 * And abandoned the patch. User:Tpt offered a better solution which I just merged. --Jens Ohlig (talk) 11:00, 8 April 2013 (UTC)
 * I've rewritten the module to catch it with pcall, now it works on all known pages. Ignatus (talk) 19:31, 6 April 2013 (UTC)
 * And if the identifier is not  (e.g.  ), module raises an error which is uncatchable; I think it also should be somehow moderated. Ignatus (talk) 19:18, 6 April 2013 (UTC)
 * I clarified this in the documentation. Thanks again. --Jens Ohlig (talk) 02:14, 7 April 2013 (UTC)


 * This issue has been raised 30/3 by User:Tpt who issued a patch here https://gerrit.wikimedia.org/r/#/c/56737/ HenkvD (talk) 17:27, 7 April 2013 (UTC)
 * Merged it. --Jens Ohlig (talk) 11:00, 8 April 2013 (UTC)

Hopes for getEntity and getProperty

 * Now, Lua calls to wikibase give many Script Errors. In this module, used in this page, I wrote the function wikidata. But better not blocking error messages could be usefull for many users.
 * To never receive Script Errors, I use :

local dat = wd.entity.claims if dat.p18 then wd.image = dat.p18[0].mainsnak.datavalue.value end -- (because dat["p18"][0] do not works)
 * Like DixonD upper, I hope  and
 * Even exactly  which return a string or nil, and where the element code is not necessary inside a page-element, but where it permits to document the module or the templates elsewhere out of main space, and to build genealogies or species classifications.
 * Now Lua modules work in fr.wikisource, but  do not works. Thanks for a better future. --Rical (talk) 16:02, 13 June 2013 (UTC)

Array numbering
In the examples, it is traditionaly for Lua from 1, but really, since I know, it's from 0. Ignatus (talk) 10:09, 20 July 2013 (UTC)

New interface to wikidata
I do not see differences between result from the deprecated mw.wikibase.getEntity and the new mw.wikibase.getEntityObject. I expected at least two changes: 1) all property names used as indexes in claims array begins with upper case letter P, and 2) the arrays with property values are indexed from 1. What is the difference except the new methods? May I switch to the new interface immediately or is better to wait because the new interface is not stable yet? Paweł Ziemian (talk) 21:57, 28 February 2014 (UTC)
 * Thanks for noticing, this indeed is a bug! It will be fixed by https://gerrit.wikimedia.org/r/116236 which will presumably be deployed on Monday - Hoo man (talk) 15:59, 1 March 2014 (UTC)
 * Good to know. Thanks. I have a second question/proposal about formatPropertyValues function. I called it on property with multiple values and the result was a list of formatted values separated with comma. How about expanding the interface of the function with two optional arguments separator and last_separator, which default to comma if not given, and last_separator defaults to separator if it is given. This could make more human friendly outputs for readers i.e. "consists of bla1, bla2, bla3, and bla4" or in case of unknown date of birth "1900-01-11 or 1900-01-12". Paweł Ziemian (talk) 21:38, 1 March 2014 (UTC)


 * The fix works! Paweł Ziemian (talk) 18:26, 3 March 2014 (UTC)

WDQ interface
Any chances to get some/any WDQ query interface ( http://wdq.wmflabs.org/api_documentation.html )? Let it be even sync request with timeoutError in say 5 sec out of 10 total allowed. Some  Any chances for that? --Neolexx (talk) 20:20, 4 September 2014 (UTC)

Arbitrary access
Just to confirm that arbitrary access is working as expected. I've taken a function from en:Module:Wikidata and created a sandbox module at nl:Module:Sandbox/RexxS/AA that works when invoked from my sandbox on Dutch Wikipedia nl:Gebruiker:RexxS/Kladblok. The corresponding sandbox module at en:Module:Sandbox/RexxS/AA at present gives "Lua error in Module:Sandbox/RexxS/AA at line 17: Access to arbitrary items has been disabled" when invoked from my English sandbox en:User:RexxS/sandbox. Ready to go when AA is enabled on en-wp. Cheers --RexxS (talk) 22:53, 11 May 2015 (UTC)
 * Awesome! Thank you :) --Lydia Pintscher (WMDE) (talk) 10:09, 12 May 2015 (UTC)
 * Did you also check that the value gets updated when changed on Wikidata? I think this is a kind of sensitive point we should test now. -- Bene* (talk) 11:16, 12 May 2015 (UTC)
 * I must admit I have never checked that a value fetched from the mw.wikibase.getEntity call is updated when the value is changed on Wikidata. As I know of no caching in operation, I would be amazed if the value fetched was ever out of sync with the Wikidata database. It should be an easy job to check that though - feel free to use my nl:Gebruiker:RexxS/Kladblok to check a Wikidata entry before and after changing it. --RexxS (talk) 21:51, 27 May 2015 (UTC)


 * Is any function like  planned to appear? It's difficult to refer data associated with specific pages by Wikidata ids, not their titles, and I currently can't see a way to do it. Ignatus (talk) 15:02, 23 June 2015 (UTC)
 * But all referred data are available as ids in claims of the loaded entity. Why do you want to refer by not-stable name, and what is the name? Paweł Ziemian (talk) 20:42, 23 June 2015 (UTC)
 * In Russian Wikipedia, in articles about administrative divisions there are tables of settlement in the division (example) where there are included such data as name, population and status. Currently, these data are mostly kept in modules written in Lua, but we had better them from Wikidata. So, I want to pass to a template in the article "Андреевская (Вожегодский район);Анисимовская (Бекетовское сельское поселение);…", not "Q4065685;Q4066371;…" — article code just needs to be editable. Ignatus (talk) 20:10, 28 June 2015 (UTC)
 * I hope such list will be available automatically when query is implemented. Any settlement should have its parent division set in specific property, and the query ask for all settlements, with the specified division. The result of that query should consists of all the required data (including labels and counts). I hope the last thing to do in Lua module that retrieves the data is to put all of them into nice table or graph for presentation purposes. But all of it is my wish. There are some rumors about queries but nobody knows what exactly it will be yet. I think that looking for item by name is very inefficient and ambiguous. There is nothing unusual that more than one item has the same label (name). In that case the hypothetical function would return an array of identifiers, and you have next problem. Paweł Ziemian (talk) 18:12, 1 July 2015 (UTC)

Get time properties in ISO 8601 format
In the module s:fr:Module:Author3 used in s:fr:Auteur:Nelson Mandela, I would compare dates-from-wikibase to detect abnormal lifetime and some other errors like partial dates. But getting the usual format "april 23 1997" this is not easy. I must first convert dates to numbers, which is complex. If I could get these dates in ISO 8601 format this could be easier! --Rical (talk) 18:06, 17 September 2015 (UTC)
 * @Rical: This module could help you . Matěj Suchánek (talk) 19:11, 17 September 2015 (UTC)
 * Nice! @Matěj, many thanks!
 * My module is based on s:fr:Module:ControlArgs able to convert any module as multilingual and centralisable. But I need to finalize it and use it on 2 wikis before to submit it to the community. --Rical (talk) 19:50, 17 September 2015 (UTC)

testing for a valid QID ?
Is there any way to test if a particular string is indeed a valid QID in wikidata (or another wikibase)? I can call mw.wikibase.getEntity(wikidata_qid) but this results in the beautifully striking red Lua error message "The ID entered is unknown to the system. Please use a valid entity ID.". I would like a way to test for validity that doesn't result in that red error message. Thanks I9606 (talk) I put that code into Module:Sandbox, and it doesn't work:
 * I tried wrapping the call to getEntity in a protected call (pcall) but I still get the error message thrown before it can be caught - though that pattern does work for a locally generated error. I9606 (talk)
 * example lua: that does not work as expected (never returns false, errors out before it can) ->   local worked, entity = pcall(mw.wikibase.getEntity, "Q14865053")
 * I have the same question. Did you find a solution ? Regards Liné1 (talk) 13:37, 25 May 2016 (UTC)
 * I've encountered this problem too. Pinging - Evad37 (talk) 04:19, 24 August 2016 (UTC)
 * Can you help? --Lydia Pintscher (WMDE) (talk) 07:32, 24 August 2016 (UTC)
 * The following should do what you want:  returns   if the entity does not exist:   — Preceding unsigned comment added by Hoo man (talk • contribs) 00:01, 25 August 2016





- Evad37 (talk) 07:38, 25 August 2016 (UTC)

"also known as"
how do i get also known as text, i want first item in 'also known as section' like we have mw.wikibase.description(id), can we have mw.wikibase.alsoknownas(id)(1) --Mdmahir (talk) 17:25, 13 February 2016 (UTC)

Look up QID based on page name or wikidata property?
Is there a way to look up wikidata q-code based on article name or wikidata property. For example I am on Commons:Category:Paul Abadie which has an old style interlanguage link to en:Paul Abadie; can a lua code run on that page be given en:Paul Abadie and look up q-code for this article? Or may be it is possible to look up using this extension which item's d:Property:P373 is set to Commons:Category:Paul Abadie (answer: ). --Jarekt (talk) 19:12, 18 May 2016 (UTC)
 * Is what you are looking for T135442? --Lydia Pintscher (WMDE) (talk) 07:35, 24 August 2016 (UTC)