跳转到内容

Module:PRC-flk

維基文庫,自由的圖書館
文档图示 模块文档[创建]
local p = {}
local wd = require("Module:Wd")

local function addRow(out, key, value, count)
	if value ~= "" then
		out[#out+1] = '<tr><td style="background-color:#e0e0ee; font-weight:bold;">'.. key .. '</td><td>' .. value .. '</td></tr>'
		count = count + 1
	end
	return count
end

function p.main(frame)
	-- check if PRC flk ID exists
	local flkid = wd._property({"raw", "P9457"})
	if flkid == '' then
		if mw.title.getCurrentTitle().nsText ~= '' then
			-- skip not mainspace
			return ''
		end
		return '[[Category:维基数据没有国家法律法规数据库编号的法律]]'
	end
	local text = '<table class="wikitable">'
	local out = {}
	text = text .. '<tr><td style="background-color:#e0e0ee; font-weight:bold;" colspan=2>'.. wd._property({"linked", "edit", "P1476"}) ..'</td>'
	count = 1
	count = addRow(out, "法律位阶", wd._property({"linked", "edit", "P31"}), count)
	count = addRow(out, "立法机关", wd._property({"linked", "edit", "P467"}), count)
	count = addRow(out, "有效区域", wd._property({"linked", "edit", "P1001"}), count)
	count = addRow(out, "公布日期", wd._property({"edit", "P577"}), count)
	count = addRow(out, "施行日期", wd._property({"edit", "P7588"}), count)
	count = addRow(out, "收录于", "[[File:National_Emblem_of_the_People%27s_Republic_of_China.svg|15px]]&nbsp;".. wd._property({"raw", "edit", "P9457", ["format"]="\\[https://flk.npc.gov.cn/detail.html?%p 国家法律法规数据库\\]"}), count)
	if wd._property({"raw", "P996"}) ~= '' then
		text = text .. '<td rowspan=' .. count ..'>[[File:' .. wd._property({"raw", "P996"}) .. '|120px]]</td>'
	end
	text = text .. '</tr>'
	text = text .. table.concat(out, '') .. '</table>'
	-- Categories
	if mw.title.getCurrentTitle().nsText ~= '' then
		return text
	end
	text = text .. "[[Category:国家法律法规数据库收录的法律]]"
	text = text .. "[[Category:" ..wd._property({"P467"}) .. "]]" -- 此为临时设置,等待所有相关分类均建立后应从https://www.wikidata.org/wiki/Property:P910获取分类代替
	local idarg = frame.args['id']
	if idarg ~= nil and flkid ~= idarg then
		text = text .. "[[Category:国家法律法规数据库编号与维基数据不符的法律]]"
	end
	return text
end

return p