Extension talk:Wikibase Client/Lua

mw.wikibase.getEntity() edit

Is it possible to pass id to this function in order to get any entity? --DixonD (talk) 20:57, 27 March 2013 (UTC)Reply

It is not possible yet. --Lydia Pintscher (WMDE) (talk) 10:54, 28 March 2013 (UTC)Reply
Is it intentionally restricted or not? Bennylin (talk) 16:46, 18 September 2013 (UTC)Reply
Look at the bug-49805 to develop. --Rical (talk) 23:58, 18 September 2013 (UTC)Reply

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

from

  wikibase.getEntity = function ()
    local id = php.getEntityId( tostring( mw.title.getCurrentTitle().prefixedText ) )
    if id == nil then return nil end
    local entity = php.getEntity( id )
    return entity
  end

to

  wikibase.getEntity = function ( id )
    if id == nil then 
        id = php.getEntityId( tostring( mw.title.getCurrentTitle().prefixedText ) )
        if id == nil then return nil end
    end
    local entity = php.getEntity( id )
    return entity
  end

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

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)Reply
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)Reply
Thanks for the confirmation. That's what I thought. Bennylin (talk) 10:35, 1 October 2013 (UTC)Reply
  • Similar issue is with mw.wikibase.label and mw.wikibase.sitelink, which would have second argument (code and siteid 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)Reply

Troble while accessing personalia edit

I've written w:ru:Module:Wikibase but met a strange problem. If I try to write construction

{|class=wikitable
{{#invoke:wikibase|wdprops}}
|}

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)Reply

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)Reply
Yes, it's still an error with comment Ошибка Lua в mw.wikibase.lua на строке 51: attempt to index field 'sitelinks' (a nil value). Ah, I've got what causes this error: it's while trying to get mw.wikibase.sitelink('q6581097') (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)Reply
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)Reply
The patch now awaits approval at Gerrit Code Review--Jens Ohlig (talk) 01:54, 7 April 2013 (UTC)Reply
And abandoned the patch. User:Tpt offered a better solution which I just merged. --Jens Ohlig (talk) 11:00, 8 April 2013 (UTC)Reply
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)Reply
And if the identifier is not q%d+ (e.g. pcall(mw.wikibase.label,'qaaaaa')), module raises an error which is uncatchable; I think it also should be somehow moderated. Ignatus (talk) 19:18, 6 April 2013 (UTC)Reply
I clarified this in the documentation. Thanks again. --Jens Ohlig (talk) 02:14, 7 April 2013 (UTC)Reply
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)Reply
Merged it. --Jens Ohlig (talk) 11:00, 8 April 2013 (UTC)Reply

Hopes for getEntity and getProperty edit

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 mw.wikibase.getEntity("Q535") and mw.wikibase.getProperty("p20")
Even exactly mw.wikibase.getProperty("p20", "Q535") 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 mw.wikibase.getEntity() do not works. Thanks for a better future. --Rical (talk) 16:02, 13 June 2013 (UTC)Reply

Array numbering edit

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)Reply

New interface to wikidata edit

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)Reply

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)Reply
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)Reply

WDQ interface edit

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 mw.wikibase.query('WikidataQuery API string') Any chances for that? --Neolexx (talk) 20:20, 4 September 2014 (UTC)Reply

Arbitrary access edit

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)Reply

Awesome! Thank you :) --Lydia Pintscher (WMDE) (talk) 10:09, 12 May 2015 (UTC)Reply
@RexxS: 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)Reply
@Bene*: 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)Reply
  • Is any function like mw.wikibase.getEntityId('Count von Count') == 'Q12345' 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)Reply
    • 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)Reply
      • 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)Reply
        • 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)Reply

Get time properties in ISO 8601 format edit

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)Reply

@Rical: This module could help you (Time.newFromWikidataValue()). Matěj Suchánek (talk) 19:11, 17 September 2015 (UTC)Reply
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)Reply

testing for a valid QID ? edit

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 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)Reply
I've encountered this problem too. Pinging @Lydia Pintscher (WMDE): - Evad37 (talk) 04:19, 24 August 2016 (UTC)Reply
@Hoo man: Can you help? --Lydia Pintscher (WMDE) (talk) 07:32, 24 August 2016 (UTC)Reply
@Liné1, I9606, and Evad37: The following should do what you want: mw.wikibase.getEntity returns nil if the entity does not exist:
function entityCheck(entityId)
	if string.match(entityId, '^[PQ]%d+$') == nil then
		return entityId .. ': Invalid entity id'
	end

	if mw.wikibase.getEntity(entityId) then
		return entityId .. ': Does exist'
	else
		return entityId .. ': Does not exist'
	end
end
— Preceding unsigned comment added by Hoo man (talkcontribs) 00:01, 25 August 2016

@Hoo man: I put that code into Module:Sandbox, and it doesn't work:

{{#invoke:Sandbox|check|Q42}}
Script error: The function "check" does not exist.
{{#invoke:Sandbox|check|foo}}
Script error: The function "check" does not exist.
{{#invoke:Sandbox|check|Q42000000000000000000000000000}}
Script error: The function "check" does not exist.

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

Similarly when using pcall:

{{#invoke:Sandbox|pcall_check|Q42}}
Script error: The function "pcall_check" does not exist.
{{#invoke:Sandbox|pcall_check|foo}}
Script error: The function "pcall_check" does not exist.
{{#invoke:Sandbox|pcall_check|Q42000000000000000000000000000}}
Script error: The function "pcall_check" does not exist.

or when using xpcall:

{{#invoke:Sandbox|xpcall_check|Q42}}
Script error: The function "xpcall_check" does not exist.
{{#invoke:Sandbox|xpcall_check|foo}}
Script error: The function "xpcall_check" does not exist.
{{#invoke:Sandbox|xpcall_check|Q000000000000000000000000000}}
Script error: The function "xpcall_check" does not exist.

- Evad37 (talk) 04:31, 26 August 2016 (UTC)Reply

Reported in Phabricator as phab:T143970 - Evad37 (talk) 04:58, 26 August 2016 (UTC)Reply
Use "mw.wikibase.getEntityUrl( entityId )", e.g. print (mw.wikibase.getEntityUrl( "Q12000000000000000000000000" ) and 'does exist' or 'doesnt exist') — Preceding unsigned comment added by 197.218.88.180 (talkcontribs) 15:54, 9 February 2018 (UTC)Reply
Yes, sadly that does not work as mw.wikibase.getEntityUrl will gladly create URLs for invalid and nonexistent entity IDs. 2600:1700:EDB0:A060:14D0:1D18:969:4211 12:40, 21 April 2018 (UTC)Reply

"also known as" edit

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)Reply

+1 E.g. for w:GNU General Public License (d:Q7603) get GNU GPL, GPL etc. --Valerio Bozzolan (talk) 01:57, 6 March 2017 (UTC)Reply
I believe you are looking for the list of aliases. This can be done via Scribunto Lua, however, currently only via the expensive mw.wikibase.entity and looking at its "aliases" field. A request could be made for mw.wikibase.getAliases/mw.wikibase.getAliasesWithLang and mw.wikibase.entity:getAliases/mw.wikibase.entity:getAliasesWithLang. In a similar vein, short of mw.wikibase.entity, we do not have a means to get sitelink badges, entity types (although we can guess based on the first character of the eID: Q or P) or the schema version. Perhaps an argument could be made to get some sort of abbreviated entity object without the "claims" (which is usually the heaviest part). 2600:1700:EDB0:A060:14D0:1D18:969:4211 13:06, 21 April 2018 (UTC)Reply

Look up QID based on page name or wikidata property? edit

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: Paul Abadie (Q367627)). --Jarekt (talk) 19:12, 18 May 2016 (UTC)Reply

Is what you are looking for phabricator:T135442? --Lydia Pintscher (WMDE) (talk) 07:35, 24 August 2016 (UTC)Reply
Yes precisely --Jarekt (talk) 19:08, 25 October 2016 (UTC)Reply

Problem with mw.wikibase.label edit

Hello, there is a problem with this function mw.wikibase.label. Now, if there is an opposite value of the item in the local wiki; it gives the value in the local wiki, and if not, it returns the value of the English opposite of the item. Sometimes I used this function, and I don't need it to return the english value, but I need only the local wiki value of the item (If exist). Is there a way to skip this problem?. Or fix it Maybe?.--ASammour (talk) 18:40, 7 November 2016 (UTC)Reply

@ASammour: Use mw.wikibase.getLabelWithLang() (for details, see phab:T138163, phab:T143094 and phab:T145138). Matěj Suchánek (talk) 20:22, 30 December 2016 (UTC)Reply

mw.wikibase.entity:formatStatements edit

Hello everybody, I am not sure if mw.wikibase.entity:formatStatements works for me on my private wiki or if I am making something wrong; check this example:

e = mw.wikibase.getEntity('Q1208')
e:formatStatements('P29')

Lua error in console input at line 8: attempt to call method 'formatStatements' (a nil value).

It seems I can execute any other entity method, but not this one.

My Lua is at version 55.1 and Scribuntu is – (a665621) 00:03, 25 October 2016, so all pretty recent. Has this method changed or been removed at some point? — Preceding unsigned comment added by Dragan Espenschied (talkcontribs) 29. 12. 2016, 14:24‎ (UTC)

If I remember correctly, this method has been implemented very recently, so you'll have to update. Matěj Suchánek (talk) 20:17, 30 December 2016 (UTC)Reply
Thanks Matěj! What part of Mediawiki do I have to update, Scributo, the Lua binary…? Also, what exactly is the output of this method? Does it generate Links to items, or pages of items, or is it just plain text with special wikitext characters escaped? --Dragan Espenschied (talk) 22:28, 30 December 2016 (UTC)Reply
The Wikibase extension since it holds the code for the data access (but I don't know if there are some further dependecies like MW core). Oh, and I forgot that there are also some switches to enable this.
The output should be exactly what you get from #statements, see [1]. Matěj Suchánek (talk) 10:07, 31 December 2016 (UTC)Reply

mw.wikibase.entity:formatPropertyValues documentation edit

The doc seems to imply that formatPropertyValues return a simple string, while apparently it returns a table containing a value and a label. Can I add that to the doc ? I took me 15 minutes to figure out why my module went wrong because of that. Zolo (talk) 12:06, 12 August 2017 (UTC)Reply

It may have taken you that long to find the information but it is already documented in the example comment as: -- Return a table like: { value = "Formatted claim value", label = "Label of the Property" }. It can be found in Extension:Wikibase Client/Lua#mw.wikibase.entity:formatPropertyValues (and previously at the time you asked as Special:PermanentLink/2489735#mw.wikibase.entity:formatPropertyValues). 50.53.21.2 06:57, 21 January 2018 (UTC)Reply

What means RANK_TRUTH, RANK_PREFERRED ... ? edit

RANK_TRUTH, RANK_PREFERRED... seem not enough described.
What means each of these RANK? in which case are they usefull?
What they change when a Lua coder uses RANK_PREFERRED?
What happens if the Lua coder select another one of them? --Rical (talk) 21:12, 5 February 2018 (UTC)Reply
You are probably referring to Extension:Wikibase Client/Lua#mw.wikibase.entity.claimRanks. See d:Help:Ranks for what they mean. Matěj Suchánek (talk) 10:08, 6 February 2018 (UTC)Reply
I continue here because I started here but the rigth place is in Extension:Wikibase Client/Lua.
I search RANK_TRUTH... in mediawiki, wikibase, meta, test2 but find them only in Extension:Wikibase Client/Lua#mw.wikibase.entity.claimRanks and d:Help:Ranks.
Where to find other documentations?
Do you agree if I write in d:Help:Ranks something like:
  • Ranks are a mean to represent the degree of confidence and obsolescence of each data in Wikibase.
  • Each rank contain a table of some values until 0. Examples: children from a parent or books from an author.
  • From the best to the worse, confidence levels are: RANK_TRUTH = 3, RANK_PREFERRED = 2, RANK_NORMAL = 1, RANK_DEPRECATED = 0
  • RANK_TRUTH is the confidence in a data which permit to say "that is enough sure, no doubt are known in wikibase".
  • RANK_PREFERRED is less sure but enough to be used in most cases.
  • RANK_NORMAL is the least admissible confidence to use.
  • RANK_DEPRECATED means that a data exists, but obsolete or not sure.
--Rical (talk) 15:07, 7 February 2018 (UTC)Reply
update --Rical (talk)
This is not content suitable for documentation meant to Wikidata users. Moreover, your descriptions of individual ranks are inaccurate. As you would read in the linked help, they are not based on a degree of confidence. Additionally, RANK_TRUTH is not an actual rank. I'm not sure about its meaning, though (likely a fallback for RANK_PREFERRED?). Matěj Suchánek (talk) 09:09, 8 February 2018 (UTC)Reply
RANK_TRUTH was used for "claims that are not statements" in 2013, but it was removed in 2015 (data model version 3.0). It is no longer in the Wikibase RDF vocabulary; I don't know whether it can be removed without notice from lua.wiki (well, the equivalent on Gerrit) because it was part of the interface, but probably it should be somehow. GreenReaper (talk) 14:27, 29 August 2019 (UTC)Reply

Caching edit

The docs don't mention caching anywhere. Is the client expected to cache results if needed, or is there some level of caching already performed by the extension itself? – Jberkel (talk) 11:38, 21 February 2018 (UTC)Reply

At most 15 entities are cached, see mw.wikibase.lua. --Tacsipacsi (talk) 23:20, 3 March 2018 (UTC)Reply
And only the entity objects returned via mw.wikibase.entity are cached. If you use another interface like mw.wikibase.getBestStatements there is no caching provided. 2600:1700:EDB0:A060:14D0:1D18:969:4211 14:07, 21 April 2018 (UTC)Reply

Redirects edit

The manual doesn't describe how to access entities though redirects. For instance 2016 Grand Prix Cycliste de Montréal (Q26837454) is redirected to 2016 Grand Prix Cycliste de Montréal (Q26253612). Access to statements with mw.wikibase.getBestStatements('Q26837454') or mw.wikibase.getAllStatements('Q26837454') works fine, but I cannot get sitelinks and labels. mw.wikibase.getLabel('Q26837454') and mw.wikibase.getSitelink('Q26837454') both gives nil.

How do I get labels and sitelinks in a module when my entity is redirected, or alternatively how do I find out that it is redirected and get the redirection target? --Dipsacus fullonum (talk) 15:26, 21 August 2018 (UTC)Reply

See phab:T96478, phab:T192462 and phab:T157868. Matěj Suchánek (talk) 17:18, 21 August 2018 (UTC)Reply
Ugh! It seems that I have to use the expensive wikibase.getEntity() for no good reason to get sitelinks and labels in a reliable way. That is very bad news. What a waste. But thank you for the answer. --Dipsacus fullonum (talk) 18:22, 21 August 2018 (UTC)Reply
PS. The manual should be updated to warn against using the direct access but unreliable functions. --Dipsacus fullonum (talk) 18:25, 21 August 2018 (UTC)Reply

Error with mw.wikibase edit

Hi all,

For some references, and without knowing why, I have the following error: Lua error in Module:Citation/CS1/Identifiers at line 47: attempt to index a nil value.

For your information, Module:Citation/CS1/Identifiers was imported directly from Wikipedia (see the content as hosted on my personal wiki here: https://pastebin.com/YPnKm9Jc).

Especially, this is the line (47) that generates the error: wd_article = mw.wikibase.getEntity (options.q):getSitelink (this_wiki_code .. 'wiki');

I tried to install Wikibase: I've followed the tutorial, installed both the repository and the client, and I have the "Add links" section.

I've run php maintenance/runJobs.php and php maintenance/update.php, but the error is still here.

Do anyone know what is the problem here?

Thank you, — Preceding unsigned comment added by Hwgen22 (talkcontribs) 15:26, 6 December 2018 (UTC)Reply

@Hwgen22: Where does options.q come from? Normally you have to check whether mw.wikibase.getEntity(options.q) is nil, and only proceed by calling its method getSitelink if it isn’t. —Tacsipacsi (talk) 22:09, 6 December 2018 (UTC)Reply
@Tacsipacsi: Well, I've followed the tutorial from citation tool page and I've directly imported Module:Citation/CS1/Identifiers from Wikipedia (https://en.wikipedia.org/wiki/Module:Citation/CS1/Identifiers). options.q comes from here. It seems that even wikibase here is nil. And to be honest, I don't really know what does that mean. I've installed Wikibase Client and Repository, hoping that it would solve my problem, but I still have this error that appears without knowing why. — Preceding unsigned comment added by Hwgen22 (talkcontribs) 09:23, 7 December 2018 (UTC)Reply
@Hwgen22: It’s easy to find out whether mw.wikibase is nil: just execute =mw.wikibase in the Lua console (it’s on the bottom of all module editing pages). By the way, do you need it? I don’t know how this module works, but changing the line too wd_article = nil (or even better, deleting lines 46–51 entirely) eliminates this script error for sure. —Tacsipacsi (talk) 23:32, 7 December 2018 (UTC)Reply
@Tacsipacsi: I tried what you said and mw.wikibase is not nil (Lua console returns "table"). To be honest, I'm not sure I need it. This module is used by the citation tool, in order to add and manage references on articles. By following the trace of error, it seems that the error is raised when trying to handle (create? retrieve? something else?) DOI. If I remove the DOI from the template, I have the same error but for the ISSN. If I remove it too, it works. I tried to remove the if condition and what it contains to see if this helps, and after running all jobs manually (for those who will experience the same error, just execute php maintenance/runJobs.php from the wiki folder, inside a terminal), I have no more error. On the reference list, the DOI is displayed correctly, in this format: doi:<DOI here>, where doi is a link to my local Wiki. I thought that creating the page on my wiki would potentially resolve the problem but if I put again the code between the if statement, the error appears again. In any case, I will comment the if statement for now, hoping that no side effects will appear because of such change. I will try to see on another discussion page (maybe the one related to this module, or to the citation tool) if someone as any clue about this problem. Thank you very much for the time you took to respond, and for your help!

FYI I reported this to the maintainers of the module and they plan to fix it. There is a solution there as well which I have tried and works (which is equivalent to just deleting it, but makes it dependant on mw.wikibase being enabled): w:Help_talk:Citation_Style_1#Errors_from_imported_CS1_templates_into_third_party_wikis_which_don't_have_wikibase. Mvolz (talk) 10:52, 6 February 2019 (UTC)Reply

For reference, the above quoted discussion has been archived to w:Help talk:Citation Style 1/Archive 51#Errors from imported CS1 templates into third party wikis which don't have wikibase. 50.53.21.2 20:27, 21 October 2019 (UTC)Reply
This worked. Seraphim System (talk) 01:58, 24 February 2019 (UTC)Reply

Instructions to Fix

In summary, this fix worked for me:

  • Click on "Module:Citation/CS1/Identifiers at line 47: attempt to index a nil value.", then go into the module "Module:Citation/CS1/Identifiers".
  • Delete lines 46 to 51. To find the correct line numbers, it might help to first copy the text into an editor such as SubLime.
  • Refresh the scripts by running this in the terminal in the Wiki folder:
php maintenance/runJobs.php

broken mw.wikibase.entity:getSitelink function edit

Any changes today, that might have broken mw.wikibase.entity:getSitelink function? Today c:Category:Pages with script errors started to fill up with files showing "Lua error in Module:Wikidata_label at line 24: attempt to call method 'getSitelink' (a nil value)" error. For example this page. I do not think that error was caused by any changes to Lua code on Commons, so perhaps something went broke in mw:Extension:Wikibase Client/Lua. --Jarekt (talk) 04:55, 12 December 2019 (UTC)Reply

wikibase.getEntityIdForCurrentPage() when called from talkpage edit

How can one get wikibase.getEntityIdForCurrentPage() to return the appropriate QID when called form a talkpage? Example use that doesn't work from talkpage:

function p.QID(frame)
	if not mw.wikibase then
		return "no mw.wikibase"
	end
	return mw.wikibase.getEntityIdForCurrentPage() or "no entity"
end

Thanks in advance for any advice. T.Shafee(Evo﹠Evo)talk 02:26, 18 September 2020 (UTC)Reply

A workaround is using mw.wikibase.getEntityIdForTitle() and specifying the associated page title. --Matěj Suchánek (talk) 08:56, 18 September 2020 (UTC)Reply
@Matěj Suchánek: thanks. Would there be a way to pull the pagetitle automatically from within the lua module to pass to that function? I'm pretty new to lua, so any assistance appreciated! (current sandbox). T.Shafee(Evo﹠Evo)talk 00:43, 23 September 2020 (UTC)Reply
@Thomas: You need to call a property of the title object for the current page (see Extension:Scribunto/Lua reference manual #Title library. As an example for you, I've made a demo of small routine that returns the subject page title when called from any talk page (or the subject page) at w:Module:Sandbox/RexxS/Pagetitle. The test is at w:Module talk:Sandbox/RexxS/Pagetitle. Cheers --RexxS (talk) 15:29, 23 September 2020 (UTC)Reply
@RexxS: Thanks. The ideal would be to pass that table output straight to mw.wikibase.getEntityIdForTitle(). Is there some tabletostring function so that its output is compatible? The use case is that this works but this doesn't. T.Shafee(Evo﹠Evo)talk 00:43, 24 September 2020 (UTC)Reply
@Thomas: sorry, I'm used to the Scribunto interface converting a title object (i.e. table) into the string representing its title. That's just the .text property of the object. I've re-written the demo module for you with two functions, one for the title string and one for the q-number. The actual code you need to use in a module is:
  • mw.wikibase.getEntityIdForTitle( mw.title.getCurrentTitle().subjectPageTitle.text )
That will give the qid for the associated page on Wikidata whether it is called from the talk page or the main page. Let me know if that doesn't work for you. Cheers --RexxS (talk) 01:43, 24 September 2020 (UTC)Reply

Retrieving an ID knowing only a property value? edit

Is it possible to use any extension to retrieve a QID based on a property value within mediawiki? For example, knowing an author's ORCID number, and returning their QID within mediawiki?

  • Something like wikibase.getEntityIdForPropertyValue(Property, Value)
  • Such that wikibase.getEntityIdForPropertyValue(P496,'0000-0002-6779-3151') → Q4693015

Any ideas welcomed! T.Shafee(Evo﹠Evo)talk 08:56, 10 October 2020 (UTC)Reply

You can make a seach on Wikidata after haswbstatement:P496=0000-0002-6779-3151. --Dipsacus fullonum (talk) 10:13, 2 December 2020 (UTC)Reply

Retrieving an ID knowing only an item label? edit

Additional request (possibly easier): Is it possible to use any extension to retrieve a QID based on its label, equivalent to wikibase.resolvePropertyId?

  • Something like wikibase.resolveItemId(itemLabelOrId)
  • Such that wikibase.resolveItemId('Sereana Naepi') → Q90197093

For some strings, it might return multiple hits (e.g. 'John Smith'), so in such cases returning a list? Again, any ideas welcomed. T.Shafee(Evo﹠Evo)talk 10:21, 23 October 2020 (UTC)Reply

Return to "Wikibase Client/Lua" page.