Module:Is article

This is the current revision of this page, as edited by Pppery (talk | contribs) at 16:56, 25 June 2025 (Changed protection settings for "Module:Is article": High-risk template or module ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite))). The present address (URL) is a permanent link to this version.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local p = {}

local disambiguationTemplates = {
	"[Dd]isambiguation",
	"[Dd]isambig",
	"[Dd]isamb",
	"[Dd]ab",
	"[Ss]urname",
	"[Tt]emplate disambiguation",
}

function p.main(frame)
	local getArgs = require("Module:Arguments").getArgs
	local args = getArgs(frame)
	local page = mw.title.new(args[1], 0)
	
	if not page then
		return "badtitle"
	end

	if not page.exists then
		return "empty"
	end

	if page.isRedirect then
		return "redirect"
	end

	local content = page:getContent()
	if content then
		content = string.gsub(content, "noinclude", "<!-- noinclude -->")
		for _, name in ipairs(disambiguationTemplates) do
			if content:match("{{%s?" .. name .. "%s?}}") and not content:match("{{{%s?" .. name .. "%s?}}}") then -- to disable false positives in parameter names {{{disamb}}}
				return "dab"
			end
		end
	end

	return "article"
end

return p