Cannabis Ruderalis

Content deleted Content added
PresN (talk | contribs)
copy in from main
Tags: Manual revert Reverted
PresN (talk | contribs)
false positives blacklist of templates
Line 33: Line 33:
"[Rr]oad disambiguation",
"[Rr]oad disambiguation",
"[Rr]oaddis",
"[Rr]oaddis",
}

-- Some templates with 'disambiguation' in their titles are misleading
falsePositives = {
"[Ii]talic disambiguation"
}
}


Line 47: Line 52:
templateNames[name] = true
templateNames[name] = true
end
end
inFalsePositives = false
for _i, v in ipairs(disambigTemplates) do
for _i, v in ipairs(disambigTemplates) do
for template, _ in pairs(templateNames) do
for template, _ in pairs(templateNames) do
if string.match(template, "^"..v.."$") then
if string.match(template, "^"..v.."$") then
for _j, v2 in ipairs(falsePositives) do
return true
if string.match(template, "^"..v2.."$") then
inFalsePositives = true
end
end
if not inFalsePositives then
return true
end
end
end
end
end

Revision as of 12:32, 30 August 2023

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

local disambigTemplates = {
	"[Dd][Aa][Bb]",
	"[Dd]big",
	"[Dd]is",
	"[Dd]isambiguation",
	"[%w_%s]-%f[%w][Dd]isam[%w]-",
	"[Gg]eodis",
	"[Hh][Nn][Dd][Ii][Ss]",
	"[Hh]ndisambig",
	"[Ll]etter%-[Nn]umber [Cc]ombination [Dd]isambiguation",
	"[Ll]etter%-NumberCombDisambig",
	"[Mm]il%-unit%-dis",
	"[Nn]umberdis",
	"[Ss]choold[ai][bs]",
	"[Mm]il-unit-disambig",
	"[Mm]ilitary unit disambiguation",
	"[Gg]eo-dis",
	"[Gg]eodisambig",
	"[Dd]isambig[Gg]eo",
	"[Dd]isambig[GN]",
	"[Dd]isambigNm",
	"[Dd]isambigName",
	"[Ss]urnames?",
	"[Ss]pecies Latin name disambiguation",
	"[Ss]peciesLatinNameDisambig",
	"[Ll]atinNameDisambig",
	"[Mm]athematical disambiguation",
	"[Mm]athematics disambiguation",
	"[Mm]ath ?dab",
	"[Rr]oad disambiguation",
	"[Rr]oaddis",
}

-- Some templates with 'disambiguation' in their titles are misleading
falsePositives = {
	"[Ii]talic disambiguation"
}

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 = {}
	for name in string.gmatch(content, "{{%s*([^|}]-)%s*[|}]") do
		templateNames[name] = true
	end
	inFalsePositives = false
	for _i, v in ipairs(disambigTemplates) do
		for template, _ in pairs(templateNames) do
			if string.match(template, "^"..v.."$") then
				for _j, v2 in ipairs(falsePositives) do
					if string.match(template, "^"..v2.."$") then
						inFalsePositives = true
					end
				end
				if not inFalsePositives then
					return true
				end
			end
		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

Leave a Reply