Module:Configuration list entry

From Bonkipedia
local p = {}
local version = require("Module:Version").version
local function versiontonumber(version)
	if #version == 6 then
		return versiontonumber(version:sub(0,4)) + tonumber(version:sub(6))/1000
	end
	local num = tonumber(version)
	if #version == 3 then
		return 1 + (num-1)/10
	else
		return num
	end
end
function p._main(name)
	local frame = mw.getCurrentFrame()
	-- reimplementing [[Module:Template translation]]'s getTranslatedTemplate function here to avoid expensive parser function
	-- call limits
	local thisLang = frame:preprocess('{{PAGELANGUAGE}}')
	-- try translation
	local lang = thisLang
	local translatedText = mw.title.new("Manual:$" .. name .. "/" .. thisLang):getContent()
	if translatedText == nil and thisLang ~= 'en' then
		-- try English
		lang = 'en'
		translatedText = mw.title.new("Manual:$" .. name .. "/en"):getContent()
	end
	if translatedText == nil then
		-- try base page in case a configuration setting is not translatable at all
		translatedText = mw.title.new("Manual:$" .. name):getContent()
	end
	if translatedText == nil then
		error("Bogus configuration variable: $" .. name)
	end
	local summary = translatedText:match("\n%s*|%s*summary%s*=%s*([^\n]*)\n") 
	local introduced = translatedText:match("\n%s*|%s*version_min%s*=%s*([^|\n]-)%.?0?\n")
	local removed = translatedText:match("\n%s*|%s*version_max%s*=%s*([^|\n]-)%.?0?\n")
	local deprecated = translatedText:match("\n%s*|%s*version_deprecated%s*=%s*([^|\n]-)%.?0?\n")
	if summary then
		if lang ~= thisLang then
			summary = '<bdi lang="' .. lang .. '">' .. summary .. "</bdi>"
		end
		summary = " – " .. summary
		if removed and removed ~= "" then
			local num = versiontonumber(removed)
			if num and num < 1.19 then
				error("$" .. name .. " was removed before 1.19, so shouldn't be listed.")
			end
			summary = frame:expandTemplate{title="removed-inline",args={removed}} .. summary
		elseif deprecated and deprecated ~= "" then
			summary = frame:expandTemplate{title="deprecated-inline",args={deprecated}} .. summary
		end
		if introduced then
			local num = versiontonumber(introduced)
			if num and num > versiontonumber(version("legacylts","branch")) then
				summary = frame:expandTemplate{title="introduced-inline",args={introduced}} .. " " .. summary
			end
		end
	else
		error("Could not find summary for $" .. name)
	end
	return frame:preprocess(summary)
end
function p.main(frame)
	return p._main(frame.args.name)
end
return p;