Module:Endangered Languages Project

From Phuketer
Revision as of 15:10, 16 June 2026 by Maintenance script (talk | contribs) (ABC local final Wikibase guard)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Endangered Languages Project/doc

-- ABC_WIKIBASE_GUARD_FINAL2_START
mw.wikibase = mw.wikibase or {}
mw.wikibase.getEntityIdForCurrentPage = mw.wikibase.getEntityIdForCurrentPage or function() return nil end
mw.wikibase.getEntityIdForTitle = mw.wikibase.getEntityIdForTitle or function() return nil end
mw.wikibase.getSitelink = mw.wikibase.getSitelink or function() return nil end
mw.wikibase.getLabel = mw.wikibase.getLabel or function() return nil end
mw.wikibase.getBestStatements = mw.wikibase.getBestStatements or function() return {} end
mw.wikibase.getAllStatements = mw.wikibase.getAllStatements or function() return {} end
mw.wikibase.getEntity = mw.wikibase.getEntity or function() return nil end
mw.wikibase.getEntityObject = mw.wikibase.getEntityObject or function() return nil end
mw.wikibase.isValidEntityId = mw.wikibase.isValidEntityId or function() return false end
-- ABC_WIKIBASE_GUARD_FINAL2_END

-- ABC_WIKIBASE_GUARD_FINAL_START
-- ABC local patch: guard missing Wikibase on standalone Phuketer imports.
mw.wikibase = mw.wikibase or {}
mw.wikibase.getEntityIdForCurrentPage = mw.wikibase.getEntityIdForCurrentPage or function() return nil end
mw.wikibase.getEntityIdForTitle = mw.wikibase.getEntityIdForTitle or function() return nil end
mw.wikibase.getSitelink = mw.wikibase.getSitelink or function() return nil end
mw.wikibase.getLabel = mw.wikibase.getLabel or function() return nil end
mw.wikibase.getBestStatements = mw.wikibase.getBestStatements or function() return {} end
mw.wikibase.getAllStatements = mw.wikibase.getAllStatements or function() return {} end
mw.wikibase.getEntity = mw.wikibase.getEntity or function() return nil end
mw.wikibase.getEntityObject = mw.wikibase.getEntityObject or function() return nil end
mw.wikibase.isValidEntityId = mw.wikibase.isValidEntityId or function() return false end
-- ABC_WIKIBASE_GUARD_FINAL_END

-- ABC local patch: guard missing Wikibase on standalone Phuketer imports.
mw.wikibase = mw.wikibase or {}
mw.wikibase.getEntityIdForCurrentPage = mw.wikibase.getEntityIdForCurrentPage or function() return nil end
mw.wikibase.getEntityIdForTitle = mw.wikibase.getEntityIdForTitle or function() return nil end
mw.wikibase.getSitelink = mw.wikibase.getSitelink or function() return nil end
mw.wikibase.getLabel = mw.wikibase.getLabel or function() return nil end
mw.wikibase.getBestStatements = mw.wikibase.getBestStatements or function() return {} end
mw.wikibase.getAllStatements = mw.wikibase.getAllStatements or function() return {} end
mw.wikibase.getEntity = mw.wikibase.getEntity or function() return nil end
mw.wikibase.getEntityObject = mw.wikibase.getEntityObject or function() return nil end
mw.wikibase.isValidEntityId = mw.wikibase.isValidEntityId or function() return false end

local p = {}

local elpf = "https://www.endangeredlanguages.com/elp-language/" -- or get P1630

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

p.make_entry = function(frame)
	local out = {}
	local make_display = function(elpc, elpn)
		if elpc and elpn then
			table.insert(out, "[" .. elpf .. elpc .. " " .. elpn ..	"]")
		elseif elpc or elpn then
			table.insert(out, (elpc or "") .. (elpn or "") .. "[[Category:Language articles with missing ELP parameters]]")
		end
	end
	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()
	make_display(elpcode, elpname)
	if qid then
		local props = mw.wikibase.getBestStatements(qid, "P2192")
		if props[1] then
			for _, v in ipairs(props) do
				local elpc = v.mainsnak.datavalue and v.mainsnak.datavalue.value
				local elpn = v.qualifiers and v.qualifiers.P1810 and v.qualifiers.P1810[1].datavalue and v.qualifiers.P1810[1].datavalue.value
				make_display(elpc, elpn)
			end
		end
	end
	local ret = ""
	if #out > 1 then
		return frame:expandTemplate{title = "ubl", args = out}
	elseif #out==1 then
		return out[1]
	end
end

return p