Module:Infobox television disambiguation check: Difference between revisions

Created page with "-- This module requires the use of the following modules. local getArgs = require('Module:Arguments').getArgs local validateDisambiguation = require('Module:Television infoboxes disambiguation check') local p = {} local validDisambiguationTypeList = { "TV series", "TV programme", "TV program", "TV film", "film", "miniseries", "serial", "game show", "talk show", "web series" } local validDisambiguationPatternList = { validateDisambiguation.DisambiguationPat..."
 
No edit summary
 
Line 1: Line 1:
-- This module requires the use of the following modules.
require("strict")
local getArgs = require('Module:Arguments').getArgs
 
local validateDisambiguation = require('Module:Television infoboxes disambiguation check')
local getArgs = require("Module:Arguments").getArgs
local validateDisambiguation = require("Module:Television infoboxes disambiguation check")


local p = {}
local p = {}


-----------------------------------------------------------------------
-- Valid disambiguation types for infobox television
-----------------------------------------------------------------------
local validDisambiguationTypeList = {
local validDisambiguationTypeList = {
"TV series",
"TV series",
Line 18: Line 22:
}
}


local validDisambiguationPatternList = {
-----------------------------------------------------------------------
validateDisambiguation.DisambiguationPattern{pattern = "^(%d+) (%D+)", type = 1}, --"VALIDATION_TYPE_YEAR_COUNTRY"
-- Valid disambiguation patterns (AFTER removing type)
validateDisambiguation.DisambiguationPattern{pattern = "^%d+$", type = 2}, --"VALIDATION_TYPE_YEAR"
-----------------------------------------------------------------------
validateDisambiguation.DisambiguationPattern{pattern = "^%D+$", type = 3} --"VALIDATION_TYPE_COUNTRY"
local validDisambiguationPatternList = {
-- YEAR + COUNTRY  → "1999 American"
validateDisambiguation.DisambiguationPattern{
pattern = "^(%d+)%s+(%D+)$",
type = validateDisambiguation.VALIDATION_TYPE_YEAR_COUNTRY
},
 
-- YEAR ONLY → "1999"
validateDisambiguation.DisambiguationPattern{
pattern = "^%d+$",
type = validateDisambiguation.VALIDATION_TYPE_YEAR
},
 
-- COUNTRY ONLY → "American"
validateDisambiguation.DisambiguationPattern{
pattern = "^%D+$",
type = validateDisambiguation.VALIDATION_TYPE_COUNTRY
}
}
}


-----------------------------------------------------------------------
-- Titles where parentheses are NOT disambiguation
-----------------------------------------------------------------------
local exceptionList = {
local exceptionList = {
"The (206)",
"The (206)",
Line 33: Line 57:
"Deal or No Deal Malaysia (English-language game show)",
"Deal or No Deal Malaysia (English-language game show)",
"Deal or No Deal Malaysia (Mandarin-language game show)",
"Deal or No Deal Malaysia (Mandarin-language game show)",
"Gympl s (r)učením omezeným",
"How to Live with Your Parents (For the Rest of Your Life)",
"How to Live with Your Parents (For the Rest of Your Life)",
"How to Sell Drugs Online (Fast)",
"How to Sell Drugs Online (Fast)",
"I (Almost) Got Away With It",
"I (Almost) Got Away With It",
"I Do (But I Don't)",
"Kevin (Probably) Saves the World",
"Kevin (Probably) Saves the World",
"Love (ft. Marriage and Divorce)",
"Love (ft. Marriage and Divorce)",
Line 44: Line 70:
"Wednesday 9:30 (8:30 Central)",
"Wednesday 9:30 (8:30 Central)",
"Who the (Bleep)...",
"Who the (Bleep)...",
"Who the (Bleep) Did I Marry?",
"Who the (Bleep) Did I Marry?"
}
}


-----------------------------------------------------------------------
-- Infoboxes that should NOT use this module
-----------------------------------------------------------------------
local otherInfoboxList = {
local otherInfoboxList = {
["franchise"] = "[[Category:Television articles using incorrect infobox|FRANCHISE]]",
["franchise"] = "[[Category:Television articles using incorrect infobox|FRANCHISE]]",
Line 56: Line 85:
}
}


-- Empty for now.
-----------------------------------------------------------------------
-- No invalid title styles for this module
-----------------------------------------------------------------------
local invalidTitleStyleList = {}
local invalidTitleStyleList = {}


-----------------------------------------------------------------------
-- Internal main
-----------------------------------------------------------------------
local function _main(args)
local function _main(args)
local title = args[1]
local title = args[1]
return validateDisambiguation.main(title, "infobox television", validDisambiguationTypeList, validDisambiguationPatternList, exceptionList, otherInfoboxList, invalidTitleStyleList)
return validateDisambiguation.main(
title,
"infobox television",
validDisambiguationTypeList,
validDisambiguationPatternList,
exceptionList,
otherInfoboxList,
invalidTitleStyleList
)
end
end


-----------------------------------------------------------------------
-- Public entry point
-----------------------------------------------------------------------
function p.main(frame)
function p.main(frame)
local args = getArgs(frame)
local args = getArgs(frame)
local category, debugString = _main(args)
local category = _main(args)
return category
return category
end
end


-----------------------------------------------------------------------
-- Utility: remove a value from an array
-----------------------------------------------------------------------
local function removeFromArray(t, delete)
local function removeFromArray(t, delete)
    local j = 1
local j = 1
    local n = #t
local n = #t


    for i = 1, n do
for i = 1, n do
        if (t[i] ~= delete) then
if t[i] ~= delete then
            -- Move i's kept value to j's position, if it's not already there.
if i ~= j then
            if (i ~= j) then
t[j] = t[i]
                t[j] = t[i]
t[i] = nil
                t[i] = nil
end
            end
j = j + 1
            j = j + 1 -- Increment position of where we'll place the next kept value.
else
        else
t[i] = nil
            t[i] = nil
end
        end
end
    end


    return t
return t
end
end


-----------------------------------------------------------------------
-- Export list of disambiguation types EXCEPT "TV series"
-- Used by the season module to detect incorrect infobox usage
-----------------------------------------------------------------------
function p.getDisambiguationTypeList()
function p.getDisambiguationTypeList()
return removeFromArray(validDisambiguationTypeList, "TV series")
return removeFromArray(mw.clone(validDisambiguationTypeList), "TV series")
end
end


-----------------------------------------------------------------------
-- Test entry point (returns debug string)
-----------------------------------------------------------------------
function p.test(frame)
function p.test(frame)
local args = getArgs(frame)
local args = getArgs(frame)
local category, debugString = _main(args)
local _, debugString = _main(args)
return debugString
return debugString
end
end


return p
return p