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

Module:TrickValidator: Difference between revisions

From Trackmania Wiki
No edit summary
No edit summary
Line 3: Line 3:
local requiredSections = {
local requiredSections = {
"Description",
"Description",
"Origin",
"Use Cases & Purpose",
"Requirements and limits",
    "Conditions and limits",
"Variations",
"How to Perform",
     "Examples"
    "Origin & History",
"Variations & Related Tricks",
     "Examples in Practice"
}
}



Revision as of 21:50, 17 September 2025

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

local p = {}

local requiredSections = {
	"Description",
	"Use Cases & Purpose",
    "Conditions and limits",
	"How to Perform",
    "Origin & History",
	"Variations & Related Tricks",
    "Examples in Practice"
}

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