Module:Sandbox/pppery/validate config

From Northumberland Climbing
< Module:Sandbox
Revision as of 10:40, 21 April 2020 by module>Pppery
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Sandbox/pppery/validate config/doc

local p = {}
function p.main(frame)
	local out = {}
	local configWikitext = mw.title.new("Manual:Configuration settings"):getContent()
	local lines = mw.text.split(configWikitext,"\n")
	local section
	local sectionMap = {
		paths = "urls and file paths",
		["resource loader"] = "resourceloader",
		["squid"] = "cdn / squid",
		["job queue"] = "jobs"
	}
	for _, line in ipairs(lines) do
		local sectionDef = line:match("=+ (.*) =+")
		if sectionDef then 
			section = sectionDef:lower():gsub("-"," ")
		else
			local configDef = line:match("* {{configuration list entry|([^$]+)}}")
			if configDef == "wgQueryPages" then
				configDef = nil 
				-- False positive
			end
			if configDef then
				local title = mw.title.new("Manual:$" .. configDef)
				local definedSection = title:getContent():match("%s*|%s*section%s*=%s*([^\n]+)\n")
				if definedSection == nil then
					out[#out+1] = "* Could not find section for $" .. configDef
				else
					definedSection = mw.text.trim(definedSection:lower():gsub("-"," "))
					if sectionMap[definedSection] then
						definedSection = sectionMap[definedSection]
					end
					if definedSection:lower():gsub("-"," ") ~= section then
						out[#out+1] = "* Section mismatch: $" .. configDef .. " is in " .. section .. " on config page, but " .. definedSection .. " on its own page."
					end
				end
			end
		end
	end
	return table.concat(out, "\n")
end
return p;