Difference between revisions of "Module:Sandbox/pppery/validate config"

From Northumberland Climbing
Jump to navigation Jump to search
module>Pppery
 
m (1 revision imported)
 
(No difference)

Latest revision as of 05:51, 31 July 2020

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;