Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:TrickValidator

From Trackmania Wiki
Revision as of 21:29, 17 September 2025 by Skycrafter (talk | contribs)

Documentation for this module may be created at Module:TrickValidator/doc

local p = {}

local requiredSections = {
	"Description",
	"Origin",
	"Requirements and limits",
	"Variations",
    "Examples"
}

local function getPageWikitext()
	local t = mw.title.getCurrentTitle()
	return t and t:getContent() or nil
end

local function l2Headings(wikitext)
	local out = {}
	if not wikitext then return out end
	wikitext = "\n" .. wikitext .. "\n"
	for h in mw.ustring.gmatch(wikitext, "\n==%s*([^=\n][^\n]-)%s*==%s*\n") do
		table.insert(out, mw.text.trim(h))
	end
	return out
end

function p.validate(frame)
	local pageContent = getPageWikitext()
	if not pageContent then
		return "" -- cannot validate without content
	end

	local found = l2Headings(pageContent)

	local ok = (#found == #requiredSections)
	if ok then
		for i, req in ipairs(requiredSections) do
			if found[i] ~= req then ok = false break end
		end
	end

	if not ok then
		local msg = "This article's structure is incorrect. It must have the following sections in this exact order: '''"
			.. table.concat(requiredSections, "''', '''") .. "'''. No other sections are allowed."
		return '<div class="mw-message-box mw-message-box-error">' .. msg .. '</div>[[Category:Trick articles with formatting errors]]'
	end

	return ""
end

return p