Jump to content

Module:Infobox television disambiguation check

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Gonnym (talk | contribs) at 18:55, 4 May 2019. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

-- This module requires the use of Module:Arguments.
local getArgs = require('Module:Arguments').getArgs

local p = {}

local validNameList = {
	"TV series",
	"TV program",
	"TV programme",
	"TV film",
	"film",
	"miniseries",
	"serial",
	"game show",
	"talk show",
	"web series"
}

local franchise = "franchise"
local season = "season"
local exceptionList = {
	"(Deceased)" -- temp until better way to handle this Randall and Hopkirk (Deceased)
}

local categoryList = {
	["incorrect"] = "[[Category:Television articles with incorrect naming style]]",
	["franchise"] = "[[Category:Television articles using incorrect infobox|F]]",
	["season"] = "[[Category:Television articles using incorrect infobox|S]]",
}

local isValid = false
local category = ""

local function _main(args)
	if (args[1] == nil or args[1] == "") then
		return ""
	end
	
	local disambiguation = string.match(args[1], "%s%((.-)%)")
	
	if (not disambiguation) then
		-- Nothing to check.
		return ""
	end

	for _, v in ipairs(validNameList) do
		if (not string.match(disambiguation, v)) then
			-- Name not valid, do nothing.
		else
			-- Name valid, set isValid to true.
			isValid = true
			break
		end
	end
	
	if (string.match(disambiguation, franchise)) then
		isValid = true
		category = categoryList["franchise"]
	end

	if (string.match(disambiguation, season)) then
		isValid = true
		category = categoryList["season"]
	end

	for _, v in ipairs(exceptionList) do
		if (string.match(disambiguation, v)) then
			-- Name not valid, do nothing.
			isValid = true
			break
		end
	end
	
	if (not isValid) then
		category = categoryList["incorrect"]
	end
	
	return category
end

function p.main(frame)
	local args = getArgs(frame)
	return _main(args)
end

return p