Module:Endangered Languages Project: Difference between revisions
Appearance
Content deleted Content added
MusikBot II (talk | contribs) m Protected "Module:Endangered Languages Project": High-risk template or module (more info) ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite)) |
The Earwig (talk | contribs) removed <code> formatting, since they seem to be language names instead of codes in any usual sense (the proper code is an integer in the URL, but we don't need to display that to the reader) |
||
Line 10: | Line 10: | ||
local pfargs = { "ref", "[" .. elpf .. elpc .. " Endangered Languages Project data for " .. elpn .. "].", name="ELP" .. (idx or "") } |
local pfargs = { "ref", "[" .. elpf .. elpc .. " Endangered Languages Project data for " .. elpn .. "].", name="ELP" .. (idx or "") } |
||
local ref = mw.getCurrentFrame():callParserFunction{ name = "#tag", args = pfargs } |
local ref = mw.getCurrentFrame():callParserFunction{ name = "#tag", args = pfargs } |
||
return " |
return "[" .. elpf .. elpc .. " " .. elpn .. "]" .. ref |
||
end |
end |
||
Revision as of 09:22, 7 February 2021
--[[
Module:Endangered Languages Project
--]]
local p = {}
local elpf = "http://www.endangeredlanguages.com/lang/" -- or get P1630
local make_display = function(elpc, elpn, idx)
local pfargs = { "ref", "[" .. elpf .. elpc .. " Endangered Languages Project data for " .. elpn .. "].", name="ELP" .. (idx or "") }
local ref = mw.getCurrentFrame():callParserFunction{ name = "#tag", args = pfargs }
return "[" .. elpf .. elpc .. " " .. elpn .. "]" .. 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()
local out = {}
if elpcode and elpname then
out[#out+1] = make_display(elpcode, elpname)
else
if qid then
local props = mw.wikibase.getBestStatements(qid, "P2192")
if props[1] then
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, i)
end
end
elseif elpcode or elpname then
return (elpcode or "") .. (elpname or "") .. "[[Category:Language articles with missing ELP parameters]]"
end
else
if elpcode or elpname then
return (elpcode or "") .. (elpname or "") .. "[[Category:Language articles with missing ELP parameters]]"
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