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

Content deleted Content added
Undid revision 1212216491 by Gonnym (talk)
No edit summary
Line 1:
require('strict')
local match = require("Module:String")._match
 
Line 52 ⟶ 53:
return "season"
end
 
--TODO: validate this works
--Space after series name
--The Simpsons season 8
--Hawaii Five-0 (2010 TV series) season 10
--Dancing with the Stars (South Korean TV series) season 3
 
--- Returns the season number from the title.
Line 64 ⟶ 59:
local function getSeasonNumberNew(title)
return match(title , "%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)
returnlocal disambiguation = match(title, "%s%((.-)%)", 1, -1, false, "")
if disambiguation and disambiguation == "" then
return nil
end
return disambiguation
end
 
Line 70 ⟶ 76:
--- @return string | nil
local function getTitleWithoutDisambiguation(title)
local disambiguation = matchgetDisambiguation(title, "%s%((.-)%)", 1, -1, false, "")
if disambiguation ~= "" then
return string.gsub(title, "%(" .. disambiguation .. "%)", "")
end
return title
end
 
--TODO: keep for now
local function getDisambiguation(title)
return match(title, "%s%((.-)%)", 1, -1, false, "")
end
 
Line 128 ⟶ 129:
--- @return string
local function getShowName(title)
local name, _ = mw.ustring.gsub(title, "season %s+%b()d*$", "")
name, _ = mw.ustring.gsub(name, "series %d*$", "")
name, _ = mw.ustring.gsub(name, "specials", "")
name = string.match(name, "^%s*(.-)%s*$") -- Trim spaces.
return name
end
Line 184 ⟶ 188:
--- -- Style: <showName> (<year> TV series) <seasonType> <seasonNumber>
--- Example: Love Island (2015 TV series) series 2
--- -- Style: <showName> (<country> <seasonType>) -- TODO: how will this look?
--- Example: Big Brother 2 (American season).
 
Line 198 ⟶ 202:
seasonNumber = seasonNumber + seasonNumberDiff
local modifiedTitle = string.gsub(title, "%d+$", seasonNumber)
local pipedLink = seasonType:gsub("^%l", string.upper) .. " " .. seasonNumber
 
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 213 ⟶ 217:
 
-- 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 301 ⟶ 305:
title = getTitleWithoutDisambiguation(title)
local seasonType = getSeasonType(title)
if seasonType == "specials" then
seasonType = "season"
end
 
return seasonType
end
Line 330:
if not seasonNumber then
local title = getTitle(frame)
titlelocal titleWithoutDisambiguation = getTitleWithoutDisambiguation(title)
seasonNumber = getSeasonNumberNew(titletitleWithoutDisambiguation)
seasonType = getSeasonType(titletitleWithoutDisambiguation)
-- For pages like "Doctor Who specials (2008–2010)".
--TODO: need to check where this is used
if seasonType == "specials" then
return getDisambiguation(title) or "" .. " " .. seasonType
return shortDisambiguation
end
seasonType = seasonType:sub(1, 1):upper() .. seasonType:sub(2)
Line 371:
 
local title = getTitle(frame)
local showName = getShowName(getTitleWithoutDisambiguation(title))
mw.log(title)
 
mw.log(showName)
if showName then
local disambiguation = getDisambiguation(title)
if disambiguation then
local TVProgramDisambiguation = getTVProgramDisambiguation(disambiguation)
mw.log(showName)
local listOfEpisodesArticle = string.format("List of %s%s episodes", showName, TVProgramDisambiguation)
disambiguation = " (" .. disambiguation .. ")"
end
local listOfEpisodesArticle = string.format("List of %s%s episodes", showName, TVProgramDisambiguationdisambiguation or "")
return getListOfEpisodesLink(listOfEpisodesArticle)
end