Jump to content

Module:Endangered Languages Project

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by RexxS (talk | contribs) at 12:45, 28 January 2021 (it's name, not title for some reason). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
--[[
	Module:Endangered Languages Project
--]]

local p = {}

local elpf = "http://www.endangeredlanguages.com/lang/" -- or get P1630

local make_display = function(elpc, elpn)
	local pfargs = { "ref", "[" .. elpf .. elpc .. " Endangered Languages Project data for " .. elpn .. "]." }
	local ref = mw.getCurrentFrame():callParserFunction{ name = "tag", args = pfargs }
	return "<code>[" .. elpf .. elpc .. " " .. elpn ..	"]</code>" .. ref
end

local tidy_param = function(param)
	if param == "" then param = nil end
	return param
end

p.make_entry = function(frame)
	local elpname = tidy_param(frame.args.elpname)
	local elpcode = tidy_param(frame.args.elpcode)
	local qid = tidy_param((frame.args.qid or ""):upper()) or mw.wikibase.getEntityIdForCurrentPage()

	if not qid and not (elpcode and elpname) then return nil end

	local out = {}
	if elpcode and elpname then
		out[#out+1] = make_display(elpcode, elpname)
	else
		local props = mw.wikibase.getBestStatements(qid, "P2192")
		for i, v in ipairs(props) do
			local elpc = elpcode or v.mainsnak.datavalue and v.mainsnak.datavalue.value
			local elpn = elpname or v.qualifiers["P1810"][1].datavalue and v.qualifiers["P1810"][1].datavalue.value
			if elpc and elpn then
				out[#out+1] = make_display(elpc, elpn)
			end
		end
	end

	local ret = ""
	if #out > 1 then
		ret = frame:expandTemplate{title = "ubl", args = out}
	else
		ret = out[1]
	end

	return ret
end

return p