Module:Configuration list entry

From Laserwiki
Revision as of 04:19, 20 April 2020 by mw>Pppery
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
local p = {}
local thisLang = require("Module:Template translation").getCurrentLanguageSubpage()
function p._main(name)
	local frame = mw.getCurrentFrame()
	local translatedPage, translatedText
	-- reimplementing [[Module:Template translation]]'s getTranslatedTemplate function here to avoid expensive parser function
	-- call limits
	if thisLang ~= nil then
		-- try translation
		translatedPage =  "Manual:$" .. name .. "/" .. thisLang
		translatedText = mw.title.new(translatedPage):getContent()
	end
	if translatedText == nil then
		-- try English
		translatedPage = "Manual:$" .. name .. "/en"
		translatedText = mw.title.new(translatedPage):getContent()
	end
	if translatedText == nil then
		-- try base page in case a configuration setting is not translatable at all
		translatedPage = "Manual:$" .. name
		translatedText = mw.title.new(translatedPage):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 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
		summary = " – " .. summary
		if removed and removed ~= "" then
			local num = tonumber(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
	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;