Jump to content

Module:Disambiguation

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Evad37 (talk | contribs) at 09:36, 18 November 2019 (Entry points for templates). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}
local mRedirect = require('Module:Redirect')

local disambigTemplates = {
	"[Dd][Aa][Bb]",
	"[Dd]big",
	"[%w_%s]-%f[%w][Dd]isam[%w]-",
	"[Hh][Nn][Dd][Ii][Ss]"
}

p._isDisambiguation = function(content)
	-- false if there is no content
	if content == nil then return false end
	
	-- redirects are not disambiguation pages
	if mRedirect.getTargetFromText(content) ~= nil then return false end
	
	-- check for disambiguation templates in the content
	for _i, v in ipairs(disambigTemplates) do
		if mw.ustring.find(content, "{{%s*".. v .. "%s*%f[|}]") ~= nil then
			return true
		end
	end
	return false
end

p._isDisambiguationPage = function(page)
	-- Look "(disambiguation)" in the title
	if mw.ustring.find(page, "(disambiguation)",0,true) ~= nil then
		return true;
	end
	-- Look for disamiguation template in page content
	local title = mw.title.new(page)
	if not title then return false end
	local content = title:getContent()
	return p.isDisambiguation(content)
end

-- Entry points for templates
p.isDisambiguation = function(frame)
	return p._isDisambiguation(frame.args[1])
end
p.isDisambiguationPage = function(frame)
	return p._isDisambiguationPage(frame.args[1])
end

return p