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 06:06, 15 May 2019 (added more shows to the exceptionList). 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 invalidNameList = {
	"television film",
	"tv miniseries",
	"television miniseries",
	"tv game show",
	"television game show",
	"tv talk show",
	"television talk show"
}

local franchise = "franchise"
local season = "season"
local radio = "radio"

local exceptionList = {
	"The (206)",
	"Cinderella (Apakah Cinta Hanyalah Mimpi?)",
	"How to Live with Your Parents (For the Rest of Your Life)",
	"How to Sell Drugs Online (Fast)",
	"I (Almost) Got Away With It",
	"Kevin (Probably) Saves the World",
	"Monty Python: Almost the Truth (Lawyers Cut)",
	"Off Sides (Pigs vs. Freaks)",
	"Randall and Hopkirk (Deceased)",
	"Who the (Bleep)...",
	"Who the (Bleep) Did I Marry?"
}

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]]",
	["radio"] = "[[Category:Television articles using incorrect infobox|R]]"
}

local isValid = false
local category = ""

local function _main(args)
	local title = args[1]
	
	-- Exit module if the parameter has no value.
	if (title == nil or title == "") then
		return ""
	end
	
	local match = require("Module:String")._match
	-- Get the disambiguation text and make sure that if the title has more than 1 pair of brackets, it returns the last one.
	local disambiguation = match(title, "%s%((.-)%)", 1, -1, false, "")

	-- Exit module if the title has no disambiguation.
	if (not disambiguation or disambiguation == "") then
		return ""
	end
	
	-- Exit module if the title has brackets that are part of the title (not disambiguation).
	for _, v in ipairs(exceptionList) do
		if (v == title) then
			return ""
		end
	end
	
	-- Check if the disambiguation is valid.
	for _, v in ipairs(validNameList) do
		if (string.match(disambiguation, v)) then
			-- Name valid, set isValid to true.
			isValid = true
			-- Check if the disambiguation is using one of the extended not supported styles.
			if (v == "miniseries" or v == "game show" or v == "talk show" or v == "film") then
				local disambiguationLowerCaps = mw.ustring.lower(disambiguation)
				for _, j in ipairs(invalidNameList) do
					if (string.match(disambiguationLowerCaps, j)) then
						isValid = false
						break
					end
				end
			else 
				break
			end
		end
	end
	
	-- Check if the disambiguation is using "franchise".
	if (string.match(disambiguation, franchise)) then
		isValid = true
		category = categoryList["franchise"]
	end

	-- Check if the disambiguation is using "season".
	if (string.match(disambiguation, season)) then
		isValid = true
		category = categoryList["season"]
	end

	-- Check if the disambiguation is using "radio".
	if (string.match(disambiguation, radio)) then
		isValid = true
		category = categoryList["radio"]
	end
	
	-- Check if the disambiguation is not valid and add category.
	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