Jump to content

Module:Wikidata table

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by RexxS (talk | contribs) at 13:24, 9 February 2021 (Creating Module:Sandbox/RexxS/Wikidata table). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local p = {}

local debugging = true

local function errmsg(txt)
	if debugging then
		return "Error: " .. txt
	else
		return nil
	end
end

local function getWD(qid, pid)
	-- try differnt schemes
	return mw.getCurrentFrame():callParserFunction{ name = "statements", args = {pid, from=qid} }
end

function p.makerows(args)
	args.qids = args.qids or ""
	if args.qids == "" then return errmsg("missing qids") end
	args.pids = args.pids or ""
	if args.pids == "" then return errmsg("missing pids") end

	local qids, pids = {}, {}
	for qid in args.qids:gmatch("Q%d+") do
		qids[#qids+1] = qid
	end
	for pid in args.pids:gmatch("P%d+") do
		pids[#pids+1] = pid
	end

	local out = ""
	for r, qid in ipairs(qids) do
		out = out .. "<tr>"
		for c, pid in ipairs(pids) do
			out = out .. "<td>" .. getWD(qid, pid) .. "</td>"
		end
		out = out .. "</tr>"
	end

	return out
end

return p