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

Content deleted Content added
Undid revision 1212216491 by Gonnym (talk)
No edit summary
 
(6 intermediate revisions by the same user not shown)
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.
--- @param title string The article's title.
--- @return string | nil
local function getSeasonNumberNewgetSeasonNumber(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, _ = mw.ustring.gsub(name, "story arc %d*$", "")
name = string.match(name, "^%s*(.-)%s*$") -- Trim spaces.
return name
end
Line 184 ⟶ 189:
--- -- 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 192 ⟶ 197:
local function getArticleTitleAndPipedLink(title, seasonNumberDiff)
local seasonType = getSeasonType(title)
local seasonNumber = getSeasonNumberNewgetSeasonNumber(title)
if tonumber(seasonNumber) == nil then
return "", nil
Line 198 ⟶ 203:
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 ⟶ 218:
 
-- 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 228 ⟶ 233:
local getArgs = require("Module:Arguments").getArgs
local args = getArgs(frame)
if args.italic_title then
return "no"
end
local title = args.title
 
if not title then
title = mw.title.getCurrentTitle().text
Line 301 ⟶ 309:
title = getTitleWithoutDisambiguation(title)
local seasonType = getSeasonType(title)
ifreturn seasonType == "specials" then
end
seasonType = "season"
 
--- Returns an {{Italic title}} instance if title qualifies or a blank string.
 
--- @param frame table
--- @return string
function p.getItalicTitle(frame)
local getArgs = require("Module:Arguments").getArgs
local args = getArgs(frame)
-- If italic_title is set then "no" is the only valid value.
-- Don't set an italic title.
if args.italic_title then
return ""
end
 
local title = getTitle(frame)
return seasonType
title = getShowName(getTitleWithoutDisambiguation(title))
 
-- If the infobox is used on List of articles don't set an italic title.
-- TODO: this can be fixed in the future but current usages use a manual display title.
if string.find(title, "List of") then
return ""
end
 
return frame:expandTemplate{title = "Italic title", args = {string = title}}
end
 
--- Returns the text used for the |above= field of the infobox.
---
--- @param frame table
--- @return string
function p.getAboveTitle(frame)
local getArgs = require("Module:Arguments").getArgs
local args = getArgs(frame)
local title = getTitle(frame)
title = getShowName(getTitleWithoutDisambiguation(title))
return seasonTypetitle
end
 
--- Returns the relevant text used for the sub-header|subheader= field of the infobox.
---
--- The text is returned in the format of "Season #" or "Series #",
Line 314 ⟶ 356:
--- @param frame table The frame invoking the module.
--- @return string | nil
function p.getInfoboxSubHeadergetSubHeader(frame)
local getArgs = require("Module:Arguments").getArgs
local args = getArgs(frame)
Line 330 ⟶ 372:
if not seasonNumber then
local title = getTitle(frame)
titlelocal titleWithoutDisambiguation = getTitleWithoutDisambiguation(title)
seasonNumber = getSeasonNumberNewgetSeasonNumber(titletitleWithoutDisambiguation)
seasonType = getSeasonType(titletitleWithoutDisambiguation)
-- For pages like "Doctor Who specials (2008–2010)".
--TODO: need to check where this is used
if seasonType == "specials" then
local disambiguation = getDisambiguation(title) or ""
return shortDisambiguation
return disambiguation .. " " .. seasonType
end
seasonType = seasonType:sub(1, 1):upper() .. seasonType:sub(2)
Line 371 ⟶ 414:
 
local title = getTitle(frame)
local showName = getShowName(getTitleWithoutDisambiguation(title))
 
if showName then
local disambiguation = getDisambiguation(title)
if disambiguation then
local TVProgramDisambiguation = getTVProgramDisambiguation(disambiguation)
disambiguation = " (" .. disambiguation .. ")"
local listOfEpisodesArticle = string.format("List of %s%s episodes", showName, TVProgramDisambiguation)
end
local listOfEpisodesArticle = string.format("List of %s%s episodes", showName, TVProgramDisambiguationdisambiguation or "")
return getListOfEpisodesLink(listOfEpisodesArticle)
end