Module:Infobox television season name/sandbox2: Difference between revisions

Content deleted Content added
No edit summary
Tag: Reverted
Undid revision 1212216491 by Gonnym (talk)
Line 37:
local function getCurrentSeasonNumberFromDisambiguation(disambiguation)
return match(disambiguation , "%d+", 1, -1, false, "")
end
 
--- Returns the disambiguation from the title.
--- @param title string The article's title.
--- @return string | nil
local function getDisambiguation(title)
local disambiguation = match(title, "%s%((.-)%)", 1, -1, false, "")
if disambiguation == "" then
return nil
end
return disambiguation
end
 
--- Returns the title without its disambiguation.
--- @param title string The article's title.
--- @return string | nil
local function getTitleWithoutDisambiguation(title)
local disambiguation = match(title, "%s%((.-)%)", 1, -1, false, "")
if disambiguation ~= "" then
return string.gsub(title, "%(" .. disambiguation .. "%)", "")
end
return title
end
 
Line 67 ⟶ 45:
--- @return string
local function getSeasonType(title)
seasonTypesfor =_, seasonType in pairs({"season", "series", "story arc", "specials"}) do
for if _string.find(title, seasonType in pairs(seasonTypes) dothen
if string.find(getTitleWithoutDisambiguation(title), seasonType) then
return seasonType
end
end
-- Since rare cases exist such as "Doctor Who (2008–2010 specials)" and "Ben 10: Omniverse (story arc 1)"
-- if the default season type "season" is used at this point, do an extra validation to make sure the dismabiguation isn't used for these titles.
local disambiguation = getDisambiguation(title)
if disambiguation then
for _, seasonType in pairs(seasonTypes) do
if string.find(disambiguation, seasonType) then
return seasonType
end
end
end
 
return "season"
end
Line 99 ⟶ 64:
local function getSeasonNumberNew(title)
return match(title , "%d+", 1, -1, false, "")
end
 
--- Returns the title without its disambiguation.
--- @param title string The article's title.
--- @return string | nil
local function getTitleWithoutDisambiguation(title)
local disambiguation = match(title, "%s%((.-)%)", 1, -1, false, "")
if disambiguation =~= "" then
return string.gsub(title, "%(" .. disambiguation .. "%)", "")
end
return niltitle
end
 
--TODO: keep for now
local function getDisambiguation(title)
local disambiguation =return match(title, "%s%((.-)%)", 1, -1, false, "")
end
 
Line 220 ⟶ 201:
 
local disambiguation = getDisambiguation(title)
 
-- Titles such as "Big Brother 2 (American season) and Teenage Mutant Ninja Turtles (1987 TV series) season 2".
if disambiguation and disambiguation ~= "" then
local titleWithoutDisambiguation = string.gsub(title, disambiguation, "_DAB_")
modifiedTitle = string.gsub(titleWithoutDisambiguation, "%d+", seasonNumber)
Line 233 ⟶ 213:
 
-- Invalid usages of TV series articles with the television season infobox.
elseif disambiguation and (string.find(disambiguation, "TV series") and not (string.find(disambiguation, ", season") or string.find(disambiguation, ", series"))) then
return "", nil
 
Line 319 ⟶ 299:
function p.getSeasonWord(frame)
local title = getTitle(frame)
if title = string.find(getTitleWithoutDisambiguation(title), seasonType) then
local seasonType = getSeasonType(title)
if seasonType == "specials" then
Line 349 ⟶ 330:
if not seasonNumber then
local title = getTitle(frame)
titleNoDabtitle = getTitleWithoutDisambiguation(title)
seasonNumber = getSeasonNumberNew(titleNoDabtitle)
seasonType = getSeasonType(title)
--TODO: need to check where this is used
if seasonType == "specials" then
return getDisambiguation(title)shortDisambiguation
end
seasonType = seasonType:sub(1, 1):upper() .. seasonType:sub(2)