Jump to content

Module:Is article: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
fix
better disambiguation handling
Tag: Reverted
Line 1: Line 1:
local p = {}
local p = {}

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


function p.main(frame)
function p.main(frame)
Line 15: Line 7:
page = mw.title.new(title, 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
content = frame:preprocess(content)
if (content:match('{{%s?' .. name .. '%s?}}')) then
if content:match('dmbox') then
return "dab"
return "dab"
end
end
end
end
end

Revision as of 11:53, 10 July 2022

local p = {}

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
		content = string.gsub(content, "noinclude", "<!-- noinclude -->")
		content = frame:preprocess(content)
		if content:match('dmbox') then
			return "dab"
		end
	end

	return "article"
end

return p