跳转到内容

模組:Property

被永久保护的模块
维基百科,自由的百科全书

这是本页的一个历史版本,由Kanashimi留言 | 贡献2016年4月6日 (三) 08:07编辑。这可能和当前版本存在着巨大的差异。

-- Module:Wikibase
-- https://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua

-- [[Template:Label]]

local p = {}

-- Return the data of a given data item.
function p.data(frame)
	if not mw.wikibase then
		return "未安裝 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]][1]['mainsnak']['datavalue']
	if property['type'] == nil then
		return "不存在此屬性: " .. 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