Module:Wikibase
Jump to navigation
Jump to search
Module documentation
[create]
-- from https://www.wikidata.org/wiki/Module:Wikibase#Code for full details, please see there
---------- Module:Wikibase ----------------
require('strict')
local p = {}
-- Return the label of an entity given its entity ID
-- or the item linked to the current page if no argument is provided.
function p.label(frame)
return mw.wikibase.getLabel(frame.args[1] and mw.text.trim(frame.args[1])) -- defaults to label of the item linked to the current page
end
-- Return the data type of a property given its entity ID.
function p.datatype(frame)
local prop = mw.wikibase.getEntity(frame.args[1] and mw.text.trim(frame.args[1]):upper():gsub('PROPERTY:P', 'P')) -- trim and remove any "Property:" prefix
return prop and prop.datatype
end
function p.descriptions(frame)
if frame.args[1] and frame.args[2] and mw.wikibase.getEntity(frame.args[1]) then
local args2 = frame:preprocess( frame.args[2] )
if mw.wikibase.getEntity(frame.args[1]).descriptions and mw.language.isKnownLanguageTag(args2) == true then
local fallbacks = mw.language.getFallbacksFor(args2)
if mw.wikibase.getEntity(frame.args[1]).descriptions[args2] then
return mw.wikibase.getEntity(frame.args[1]).descriptions[args2].value
else
for i, j in pairs (mw.language.getFallbacksFor(args2)) do
description = mw.wikibase.getEntity(frame.args[1]).descriptions[j].value
if description then
return description
end
end
end
end
end
end
return p