Jump to content

Module:Is article: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Undid recent revision by Gonnym -> This edit seems to have lead to template recursion issues. This has affected Category:Pages using infobox PH collegiate finals with unknown parameters and the template Unknown parameters category. WIll leave you to debug this
this should work without the loop
 
Line 6: Line 6:
"[Dd]isamb",
"[Dd]isamb",
"[Dd]ab",
"[Dd]ab",
"[Ss]urname"
"[Ss]urname",
"[Tt]emplate disambiguation",
}
}


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


if (not page.exists) then
if not page.exists then
return "empty"
return "empty"
end
end


if (page.isRedirect) then
if page.isRedirect then
return "redirect"
return "redirect"
end
end


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

Latest revision as of 21:25, 10 July 2022

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