Module talk:Wikidata

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Import from other wikis[edit]

For a more complete module, see fr:Module:Wikidata. However, it makes use of modules from the French Wikipedia and needs to be adapted before it can be used here. --Zolo (talk) 07:44, 2 October 2013 (UTC)[reply]

I have writen large parts of both wikidata:Module:Wikidata that has been imported here, and fr:Module:Wikidata. The latter is more complicated, but also more versatile, and, I think, better structured, and it is already widely used for real. If that sounds like a good idea, I can try to adapt it to Commons. There might be other interesting wikis to look at, like cs:Module:Wikidata or ru:Module:Wikidata. -Zolo (talk) 09:10, 28 April 2016 (UTC)[reply]

Zolo I am finding wikidata:Module:Wikidata to be chopped up in to many little pieces which are quite hard to follow. I was leaning towards wikidata:Module:Wikidata because it is the other multilingual project. Wikipedia's module often have too much hardwired language specific text. If fr:Module:Wikidata is better than feel free to exchange them. By the was I was looking at adding "link" parameter to formatStatementsE function and I am getting really lost in the maze of calls. I would like to eventually call "getLink(entity, typelink, lang)" but still did not found where formatStatementsE formats links. Maybe you know how to do that. --Jarekt (talk) 17:26, 3 May 2016 (UTC)[reply]
I have imported some parts from frwiki. Though it removes a few useless intermediary steps it is not exactly simpler now... Part of the reason for that is that it still needs some cleanup. However, Wikidata data structure is not very simple, and I have found that in order to get something really functional we need to accomodate way more options than first meets the eye.
Anyhow, to get an idea of the structure:
formatStatements
  1. selects the relevant statements and turns them into string through p.stringTable
  2. concatenates those strings through p.tableToText
stringTable
  1. selects the relevant claims through Module:Wikidata/GetClaims.getClaims
  2. format each of them through p.formatStatement (without an "s")
formatStatement
uses a various arguments to format a statement. It has to format the main part of the value, and when required, the qualifiers and the references. When the data formatted is of type "item", it does it through Module:Wikidata/FormatEntity which in turn uses Module:Wikidata/Tools.getLink.
Sure, that is no simple. Still, I have disabled some of the functions from frwiki. In particular, I have not fully activated tracker categories and linkbacks to Wikidata which I sometimes find pretty useful, but in some cases, it is pretty tricky to handle. Is that a functionality that we should try to have ?

Problem with dates[edit]

{{#invoke:Creator|creator| Wikidata = Q15058356}} gives

Theodoor Aenvanck  (1633–1690)  wikidata:Q15058356
 
Description painter
Date of birth/death 1633 Edit this at Wikidata 1690 Edit this at Wikidata
Location of birth/death Antwerp Antwerp
Work location
Antwerp (1669–1686) Edit this at Wikidata
Authority file
creator QS:P170,Q15058356

The problem is that the dates are wrong d:Q15058356 dates are 1633 and 1690 not 1633-01-01 and 1690-01-01. --Jarekt (talk) 02:20, 17 September 2016 (UTC)[reply]

I've fixed that, along with quiet a few things in Module:Wikidata/Dates. Buy the way, would you have a look at the formatDaterange function ? It should use Module:Complex date with "from", "until" or "from until" but I seem to get lost with the parameter order. --Zolo (talk) 11:02, 17 September 2016 (UTC)[reply]
It looks like "standardDisplay" also could use some help. I guess we will need to find some q-codes and properties that could be used to test each date type. Could you help with that? Maybe even set up proper test/result pages. Also once we the code is mostly stable it should be protected. I realize that will be quite inconvenient for you, but it will need to be done. --Jarekt (talk) 12:32, 17 September 2016 (UTC)[reply]
Yes, but Wikidata items being liable to change, I am not sure how to best do it. We could try to create a few items in Wikidata trying to list all possible configuration for unit tests, but that may not be very nice to have "fake" items floating around. --Zolo (talk) 15:36, 17 September 2016 (UTC)[reply]

Zolo, I just wrote and tested Module:Wikidata date which should serve as a layer between wikidata and Module:Complex date. You are welcome to call it from Module:Wikidata/Dates or replace Module:Wikidata/Dates with it. My next task is to use it in Module:Creator. --Jarekt (talk) 14:03, 28 June 2017 (UTC)[reply]

Problem with showdate attribute?[edit]

{{Temporary Exhibition |item=Q28043290}} renders as:
El Siglo de Oro. The Age of Velázquez, Gemäldegalerie (from until ) and Kunsthalle der Hypo-Kulturstiftung (from until ),
Why doesn't it use the start time (P580) qualifiers of d:Q28043290#P276? Furthermore, if it only fills the parentheses with the value of end time (P582) (also if there is only end time (P582) there shouldn't be the space after the opening parenthesis. I suspect something with the showdate attribute of Module:Wikidata, that's why I ask here. Thanks in advance, --Marsupium (talk) 08:05, 26 August 2017 (UTC)[reply]

Fixed The problem was formatDaterange in Module:Wikidata/Dates. That should probably be replaced in Module:Wikidata by the i18n ready Module:Wikidata date and Module:Complex date anyway. At least, for now I've fixed it in Module:Wikidata/Dates. --Marsupium (talk) 08:25, 26 August 2017 (UTC), 08:43, 26 August 2017 (UTC)[reply]

Problem with link=- when there is no wikidata label[edit]

{{#invoke:Wikidata|getLabel|entity=Q6319539|link=-}}=Category:Taurotragus should not display a link.
The reason is that Q6319539 has no english label.
Thanks for your cool template.
Cheers Liné1 (talk) 11:30, 24 October 2017 (UTC)[reply]

Liné1, I prefer using much smaller Module:Wikidata label. --Jarekt (talk) 11:45, 24 October 2017 (UTC)[reply]
Ok, I moved to Module:Wikidata label
Thanks 12:04, 24 October 2017 (UTC)

having difficulties with basic functions[edit]

Hello,

I am trying to call functions of this Module from another script [1] but I am having difficulties passing arguments as described in the documentation, as you can see in the test case [2]:

  • OK calling formatStatements with arguments item and property works
  •  Not OK when calling formatStatements with arguments item, property and lang, the argument for lang is ignored
  •  Not OK when calling formatStatements with arguments item, property and displayformat, the argument for displayformat is ignored
  •  Not OK when calling getLabel with argument entity, the argument apparently does not get through and the interpretor yields a Lua error in Module:Wikidata at line 34: attempt to get length of local 'args' (a nil value) error.

Can anybody see what I am doing wrong here? Thanks in advance! Rama (talk) 10:49, 24 January 2018 (UTC)[reply]

Note that all of these functions work as advertised when I request "p195" instead of "p170", which is another reason to wonder. Rama (talk) 13:03, 24 January 2018 (UTC)[reply]

Rama, I had some of the same problems and the code is so huge and convoluted I have hard time analyzing it. That is why, I try to avoid this module and In my other modules I am trying to use several much smaller and easier to test modules with specialized wikidata access tasks, like Module:Wikidata date, Module:Wikidata label, etc. It seems like it is hard to write and maintain a single do-it-all wikidata access module. Instead I use either the above specialized modules or access wikidata structures directly as in Module:Authority control, Module:Coordinates or [Module:City]]. --Jarekt (talk) 14:15, 24 January 2018 (UTC)[reply]
Darn, I'd need some of these features. I am afraid I'll need to keep on stumbling around until I can get somebody competent to re-implement my prototype :/ Many thanks for your reply, Jarekt! Rama (talk) 17:15, 24 January 2018 (UTC)[reply]
Rama I looked at your code and I would switch to local getLabel = require('Module:Wikidata label')._getLabel. That one is much more stable and is used on 4.5 M pages. As for displaying creator and institution I would call formatStatements using only "raw" option which should return a q-code which I would pass to getLabel function, so display_institution_fr could become
function p.display_institution_fr( frame )
	local q = formatStatements( { item=frame.args.qid, property="P195", displayformat="raw"} )
	return "display_institution_fr: " .. getLabel(q, "fr")
end
May be this will fix some of the issues, and if formatStatements does not work right than I would just write local version of it. --Jarekt (talk) 18:03, 24 January 2018 (UTC)[reply]
It seems that mw.wikibase.label and mw.wikibase.getLabelByLang are the only things I manage to get running.
Thank you for your tips and encouragements, this helped me draft Module:Wikidata dimension. Now User:Rama/Catdef is better internationalised (see Category:Scale model of Muiron-MnM 17 MG 7 in Russian, German or Hebrew) and relies on much cleaner code than Module:RamaTesting.
Cheers and good continuation! Rama (talk) 16:04, 25 January 2018 (UTC)[reply]

Issues[edit]

Parameter params in line 218 is never set. Anybody knows where is it suppose to come from? --Jarekt (talk) 22:38, 26 February 2019 (UTC)[reply]

A line added to /Tools ?[edit]

Well, I learned that I am not a "Template editor" when I tried to add a simple line to Module:Wikidata/Tools

starting at line 132 this is what is there:

		wikipedia = {'wiki', nil, true}, -- wikipedia
		commons = {'commonswiki', 'c', false},
		commonswiki = {'commonswiki', 'c', false},
		wikiquote = {'wikiquote', 'wikiquote', true},
		wikivoyage = {'wikivoyage', 'wikivoyage', true},
		wikibooks = {'wikibooks', 'wikibooks', true},
		wikinews = {'wikinews', 'wikinews', true},

I wanted to add:

	wikisource = {'wikisource', 'wikisource', true},

I don't think it would have hurt anything. I don't really know why it isn't there already.

Can a "template editor" or otherwise enabled person add this? Thanks!--RaboKarbakian (talk) 01:43, 13 July 2021 (UTC)[reply]

Script errors from trying to use function p.formatSnak() for a coordinate value without "displayformat"[edit]

Using using function p.formatSnak() with a coordinate value without "displayformat" seems to produce script errors, for example: {{#invoke:Wikidata|formatStatementsE|item=Q97440616|property=p625}} produces "table". What else should it output in that case? Maybe some link to geohack? Thanks in advance for thoughts! Best, --Marsupium (talk) 17:29, 8 February 2023 (UTC)[reply]