Module:Wikidata2
Itsura
Module permitting basic data retrieval from items. It is mosly useful for other modules or for {{Data}}
A copy is available on test Wikidata
Functions callable from Lua
p._getClaims returns claims in a particular item that match a particular query
- item (required): its Qid
- property (required) property that the claims should have
- qualifier = qualifiers that the statement should have
- withrank = rank of the statement ; 'preferred', 'normal', 'deprecated' or 'valid' (ie. normal and preferred). By default = preferred.
- sourceproperty = this property should be used in the source
- withsource = the source that should be provided in the statement (if sourceproperty is not provided, the property used is Padron:P)
- excludespecial = set to true if you do not want to get "novalue" and "somevalue".
- numval = if you want to set a maximum number of values to be returned
- sorttype = set to "chronological" to get the statements in chronological order using the Padron:P, Padron:P and Padron:P qualifiers. Set to "inverted" for chronological order. From a Lua module, you can also define your own sorting criteria.
- showsource = set to "true" if you want the source of the statement to be displayed.
p.formatStatements(args): returns a string containing the statements given in the table args. Same keys as getClaims, plus formatting arguments:
- lang (required) for the desired language
- format = the format in which the args should be returned. For example, for a string-type property displayformat = "weblink" returns a formatted weblink.
- conjtype = the conjunction separating the statements. For example, conj = '<br />' will make a new line between each statement.
- showqualifiers = the qualifiers that should be shown along with the mainsnak value
p.getLabel get the label of an entity
- entity = entity ID with its Q or P
- lang
Functions callable from wikitext
- p.formatStatementsE same as p._formatStatements, except that "lang" is not required. It is most conveniently used from {{Data}} that takes exactly the same arguments.
Examples
Code | Render | Comment |
---|---|---|
{{#invoke:Wikidata2|getLabel|entity=Q42|link=wikipedia}} | Kamalian ng Lua na sa linyang 1: attempt to index global 'p' (a nil value). | |
{{#invoke:Wikidata2|getLabel|entity=Q42|link=wikipedia|lang=ja}} | Kamalian ng Lua na sa linyang 1: attempt to index global 'p' (a nil value). | |
{{#invoke:Wikidata2|getLabel|entity=Q42|link=wikidata}} | Kamalian ng Lua na sa linyang 1: attempt to index global 'p' (a nil value). | |
{{#invoke:Wikidata2|getLabel|entity=Q42|link=wikidata|lang=ja}} | Kamalian ng Lua na sa linyang 1: attempt to index global 'p' (a nil value). | |
{{#invoke:Wikidata2|formatStatementsE|item=Q42|property=p31}} | Kamalian ng Lua na sa linyang 1: attempt to index global 'p' (a nil value). | |
{{#invoke:Wikidata2|formatStatementsE|item=Q42|property=p31|lang=ja}} | Kamalian ng Lua na sa linyang 1: attempt to index global 'p' (a nil value). | |
{{#invoke:Wikidata2|formatStatementsE|item=Q42|property=p569}} | Kamalian ng Lua na sa linyang 1: attempt to index global 'p' (a nil value). | |
{{#invoke:Wikidata2|formatStatementsE|item=Q42|property=p569|lang=ja}} | Kamalian ng Lua na sa linyang 1: attempt to index global 'p' (a nil value). | |
{{#invoke:Wikidata2|formatStatementsE|item=Q12418|property=p186}} | Kamalian ng Lua na sa linyang 1: attempt to index global 'p' (a nil value). | |
{{#invoke:Wikidata2|formatStatementsE|item=Q12418|property=p186|displayformat=raw}} | Kamalian ng Lua na sa linyang 1: attempt to index global 'p' (a nil value). | |
{{#invoke:Wikidata2|formatStatementsE|item=Q12418|property=p186|lang=ja}} | Kamalian ng Lua na sa linyang 1: attempt to index global 'p' (a nil value). | |
{{#invoke:Wikidata2|formatStatementsE|item=Q12418|property=p186|rank=valid}} | Kamalian ng Lua na sa linyang 1: attempt to index global 'p' (a nil value). | rank = "valid" accepts both "preferred" and "normal" values |
{{#invoke:Wikidata2|formatStatementsE|item=Q12418|property=p186|showqualifiers=p518}} | Kamalian ng Lua na sa linyang 1: attempt to index global 'p' (a nil value). | shows the value of the p518 qualifier (if any) in addition to the main value |
{{#invoke:Wikidata2|formatStatementsE|item=Q83259|property=p669|showqualifiers=p670|delimiter= }} | Kamalian ng Lua na sa linyang 1: attempt to index global 'p' (a nil value). | shows the value of the P670 qualifier (if any) in addition to the main value separated by a space |
{{#invoke:Wikidata2|formatStatementsE|item=Q12418|property=p186|qualifier=p518}} | Kamalian ng Lua na sa linyang 1: attempt to index global 'p' (a nil value). | should only display values that have a p518 qualifier |
{{#invoke:Wikidata2|formatStatementsE|item=Q12418|property=p186|numval=1}} | Kamalian ng Lua na sa linyang 1: attempt to index global 'p' (a nil value). | returns the number of values numval (priority to those with "rank= preferred", if there are not enough of them, also accepts "rank = normal") |
{{#invoke:Wikidata2|formatStatementsE|item=Q12418|property=P276|sourceproperty=P854}} | Kamalian ng Lua na sa linyang 1: attempt to index global 'p' (a nil value). | |
{{#invoke:Wikidata2|formatStatementsE|item=Q11879536|property=P460|withsource=Q1645493}} | Kamalian ng Lua na sa linyang 1: attempt to index global 'p' (a nil value). | |
{{#invoke:Wikidata2|formatStatementsE|item=Q11879536|property=P460|withsource=Q1645493|showsource=true}} | Kamalian ng Lua na sa linyang 1: attempt to index global 'p' (a nil value). | |
{{#invoke:Wikidata2|formatStatementsE|item=Q153|property=P231|showsource=true}} | Kamalian ng Lua na sa linyang 1: attempt to index global 'p' (a nil value). | |
{{#invoke:Wikidata2|formatStatementsE|item=Q205309|property=P793|sorttype=inverted}} | Kamalian ng Lua na sa linyang 1: attempt to index global 'p' (a nil value). |
function p.getLabel(frame) -- simple for simple templates like {{Q|}}}
local args = frame.args
local entity = args.entity
local lang = args.lang
if lang == '' then
lang = defaultlang
end
if string.sub(entity, 1, 10) == 'Property:P' then
entity = string.sub(entity, 10)
elseif (string.sub(entity, 1, 1) ~= 'P' and string.sub(entity, 1, 1) ~= 'Q') or (not tonumber(string.sub(entity, 2))) then
return i18n('invalid-id')
end
if not args.link or args.link == '' then -- by default: no link
args.link = '-'
end
if args.link == '-' then
return p._getLabel(entity, lang) or i18n('invalid-id')
else
return p.formatEntity(entity, args)
end
end