The wiki is currently a work in progress. If you'd like to help out, please check the Community Portal and our getting started guide. Also, check out our sister project on poewiki.net.

Module:Disambiguation

From Path of Exile 2 Wiki
Jump to navigation Jump to search
Module documentation[view] [edit] [history] [purge]

Lua error in Module:Lua at line 104: attempt to index field 'edit' (a nil value).

This module was adapted from Module:Disambiguation on Wikipedia.
Adaptation is noted for reference and attribution only. This module may differ from the original in function or in usage. The documentation on Wikipedia may be helpful in understanding this module.

local p = {}
local mRedirect = require('Module:Redirect')
local disambiguationTemplates = mw.loadData('Module:Disambiguation/templates')

local function capitalize(s)
	-- This function only works on ASCII strings. If your wiki has
	-- disambiguation templates that use Unicode strings, use the commented-out
	-- line instead. Enwiki uses ASCII string manipulation only here to improve
	-- performance.
	return s:sub(1, 1):upper() .. s:sub(2, -1)
	-- return mw.ustring.upper(mw.ustring.sub(1, 1)) .. mw.ustring.sub(2, -1)
end

local function isDisambiguationTemplate(template)
	return disambiguationTemplates[capitalize(template)] or false
end

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
	local templateNames = {}
	local activecontent = string.gsub(content, "<!%-%-.-%-%->", "")
	activecontent = string.gsub(activecontent, "<nowiki>.-</nowiki>", "")
	for template in string.gmatch(activecontent, "{{%s*([^|}]-)%s*[|}]") do
		if isDisambiguationTemplate(template) then
			return true
		end
	end

	-- check for magic word
	if string.find(content, "__DISAMBIG__", 1, true) ~= nil then
		return true
	end

	return false
end

p._isDisambiguationPage = function(page)
	-- Look "(disambiguation)" in the title
	if string.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.isDisambiguationPage = function(frame)
	local title = frame.args[1]
	return p._isDisambiguationPage(title) and "yes" or ""
end

return p