Jump to content

Module:Is article: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m Protected "Module:Is article": Protecting sub template to a high visibility template per request at RfPP. ([Edit=Require autoconfirmed or confirmed access] (indefinite) [Move=Require extended confirmed access] (indefinite))
Jackmcbarn (talk | contribs)
handle the bad title case
Line 14: Line 14:
title = args[1]
title = args[1]
page = mw.title.new(title, 0)
page = mw.title.new(title, 0)
if (not page) then
return "badtitle"
end


if (not page.exists) then
if (not page.exists) then

Revision as of 02:26, 11 August 2020

local p = {}

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

function p.main(frame)
	local getArgs = require('Module:Arguments').getArgs
	local args = getArgs(frame)
	title = args[1]
	page = mw.title.new(title, 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
		for i, name in ipairs(disambiguationTemplates) do
			if (content:match('{{%s*' .. name .. '.*}}')) then
				return "dab"
			end
		end
	end

	return "article"
end

return p