模組:Property
外观
-- [[Template:P]]
local p = {}
-- Get the property of given wikidata entity.
-- 取得wikidata中指定實體項目的指定屬性。
-- https://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua
function p.data(frame)
if not mw.wikibase then
return "未安裝 Module:Wikibase 模組?"
end
entity = mw.wikibase.getEntity(frame.args[2])
-- if not entity then return nil end
if entity == nil then
return "不存在此項目: " .. frame.args[2]
end
if frame.args[1] == nil then
return mw.wikibase.label(entity.id)
end
property = entity['claims'][frame.args[1]]
if property == nil then
return "此項目 [[d:" .. frame.args[2] .. "]] 不存在此屬性: " .. frame.args[1]
end
property = property[1]['mainsnak']['datavalue']
if property['type'] ~= 'wikibase-entityid' then
return "無法處理此屬性: " .. frame.args[1]
end
return mw.wikibase.label('Q' .. property['value']['numeric-id'])
end
return p