모듈:Infobox television season name
보이기
![]() | 이 모듈은 다음의 다른 모듈에 의존합니다: |
이 모듈은 텔레비전 시즌 정보 틀에서 양식화된 시즌 문서 링크의 생성을 위해 사용됩니다.
사용법
[편집]{{#invoke:Infobox television season name|isPrevOrNextSeasonLinkValid}}
{{#invoke:Infobox television season name|isPrevSeasonLinkValid}}
{{#invoke:Infobox television season name|isNextSeasonLinkValid}}
{{#invoke:Infobox television season name|getPrevSeasonArticle}}
{{#invoke:Infobox television season name|getNextSeasonArticle}}
{{#invoke:Infobox television season name|getSeasonWord}}
{{#invoke:Infobox television season name|getInfoboxSubHeader}}
{{#invoke:Infobox television season name|getListOfEpisodes|link}}
매개 변수
[편집]변수 | 설명 | 의무 사용 |
---|---|---|
title
|
프로그램 제목. 입력하지 않으면 변수에 문서의 제목이 사용됩니다. | 아니오 |
기능
[편집]기능 | 설명 |
---|---|
isPrevOrNextSeasonLinkValid
|
이전 및 다음 시즌 문서의 존재 여부를 확인합니다. |
checkPrevSeason
|
이전 시즌 문서의 존재 여부를 확인합니다. |
checkNextSeason
|
다음 시즌 문서의 존재 여부를 확인합니다. |
getPrevSeasonArticle
|
이전 시즌 문서의 제목을 검색합니다. |
getNextSeasonArticle
|
다음 시즌 문서의 제목을 검색합니다. |
getSeasonWord
|
문서 제목에 포함된 단어 "시즌" 또는 "시리즈"를 반환합니다. |
getInfoboxSubHeader
|
하위 머릿글 입력란에 적절한 문자를 반환합니다. 문자는 문서 제목에 괄호로 표기된 부분이나, 정보상자에 직접 입력된 변수에 따라 시리즈 # 또는 시즌 # 형태로 반환됩니다.
|
getListOfEpisodes
|
에피소드 목록 문서가 존재하는 경우 해당 문서를 링크하는 "에피소드 목록"을 반환합니다. |
용례
[편집]isPrevOrNextSeasonLinkValid
[편집]- 코드:
{{#invoke:Infobox television season name|isPrevOrNextSeasonLinkValid|title=닥터 후 (시리즈 1)}}
- 출력:
getPrevSeasonArticle
[편집]- 코드:
{{#invoke:Infobox television season name|getPrevSeasonArticle|title=네모바지 스폰지밥 (시즌 12)}}
- 출력:
시즌 11
getNextSeasonArticle
[편집]- 코드:
{{#invoke:Infobox television season name|getNextSeasonArticle|title=로스트 (시즌 3)}}
- 출력:
시즌 4
local match = require("Module:String")._match
local p = {}
--- Returns a formatted link to the list of episodes article.
--- @param listOfEpisodesArticle string
--- @return string
local function getListOfEpisodesLink(listOfEpisodesArticle)
local listOfEpisodesPage = mw.title.new(listOfEpisodesArticle, 0)
if listOfEpisodesPage and listOfEpisodesPage.exists and listOfEpisodesPage.redirectTarget ~= mw.title.getCurrentTitle() then
return string.format("[[%s|에피소드 목록]]", listOfEpisodesArticle)
end
end
--- Returns an article link.
--- @param article string The article's title.
--- @param pipedLink string The piped link.
--- @return string
local function getArticleLink(article, pipedLink)
if (pipedLink == nil or pipedLink == "") then
return "[[" .. article .. "]]"
end
return "[[" .. article .. "|" .. pipedLink .. "]]"
end
--- Returns the show name and season number from a title.
--- @param showName string The show's title.
--- @return nil | number | string, nil | number | string
local function getShowNameAndSeasonNumberFromShowName(showName)
local _, _, showNameModified, seasonNumber = string.find(showName, "(.*)%s+(%d+)$")
return showNameModified, seasonNumber
end
--- Returns the current season number from the disambiguation.
--- @param disambiguation string The article's disambiguation.
--- @return string
local function getCurrentSeasonNumberFromDisambiguation(disambiguation)
return match(disambiguation , "%d+", 1, -1, false, "")
end
--- Returns the type of word used for "season" in the disambiguation.
---
--- The returned value can be one of three options: "season", "series", "story arc" or "specials".
--- @param disambiguation string The article's disambiguation.
--- @return string
local function getSeasonType(disambiguation)
for _, seasonType in pairs({"시즌", "시리즈", "특집", "스페셜"}) do
if (string.find(disambiguation, seasonType)) then
return seasonType
end
end
return "시즌"
end
--- Returns the disambiguation without the "(year) TV series," part.
--- @param disambiguation string The article's disambiguation.
--- @return string
local function getShortDisambiguation(disambiguation)
local shortDisambiguation, _ = string.gsub(disambiguation, "%d+년 텔레비전 프로그램, ", "")
return shortDisambiguation
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 TV program's disambiguation.
--- @param disambiguation string The disambiguation used in the season's article title.
--- @return string
local function getTVProgramDisambiguation(disambiguation)
if (not disambiguation) then
return ""
end
-- Check if the disambiguation is normal 'season #' or 'series #'.
-- If so, remove disambiguation.
if string.match(disambiguation, "^시즌 %d*$") or string.match(disambiguation, "^시리즈 %d*$") then
return ""
end
local disambiguationStyle = " (%s)"
-- Check if the disambiguation is extended and has 'TV series' and isn't just season #.
-- Only leave the TV series disambiguation, not including the season #.
-- Example: Teenage Mutant Ninja Turtles (1987 TV series, season 5) will return '1987 TV series'.
if (string.find(disambiguation, "텔레비전 프로그램")) then
local shortDisambiguation, _ = disambiguation:match("^(.*),")
if shortDisambiguation then
return string.format(disambiguationStyle, shortDisambiguation)
end
end
-- Check if the disambiguation is extended with country adjective.
-- Example: The Office (American season 2) will return "American season 2".
-- Keep only country adjective.
local countryDisambiguation = disambiguation:match("^(.*) 시즌 %d*") or disambiguation:match("^(.*) 시리즈 %d*")
local data = mw.loadData("Module:Country adjective")
local valid_result = data.getCountryFromAdj[countryDisambiguation]
-- Check if the country adjective is valid.
if (valid_result) then
-- Add 'TV series' suffix
return string.format(disambiguationStyle, countryDisambiguation .. " TV series")
end
-- Not a known disambiguation style. Use whatever was used in the title or manually added.
-- Note: might not be a valid style link.
return string.format(disambiguationStyle, disambiguation)
end
--- Returns the show's name from the title.
--- @param title string The article's title.
--- @return string
local function getShowName(title)
local name, _ = mw.ustring.gsub(title, "%s+%b()$", "")
return name
end
--- Returns "true" if the given link is valid; nil otherwise.
--- A link is valid in the following cases:
--- -- A season article exists.
--- -- A redirect exists to a season section.
---
--- A link is invalid in the following cases:
--- -- A season article or redirect do not exist.
--- -- A redirect exists, but it is a general redirect and not for any specific season section.
---
--- Note: Return values are not booleans as the returned value is used in template space.
--- @param title string The article's title.
--- @return string | nil
local function isLinkValid(title)
local article = mw.title.new(title)
-- Article or redirect do not exist; Not a valid link.
if (article == nil or not article.exists) then
return nil
end
local redirectTarget = article.redirectTarget
-- Article exists and is not a redirect; Valid link.
if (not redirectTarget) then
return "true"
end
local fullLink = redirectTarget.fullText
local isSection = fullLink:find("#")
-- Article is a section redirect; Valid link.
if (isSection) then
return "true"
end
-- Article is a general redirect; Not a valid link.
return nil
end
--- Returns a season article title and a piped link.
---
--- The following are the supported season naming styles:
--- -- Style: <showName> (<seasonType> <seasonNumber>)
--- Example: Lost (season 2).
--- Example: Doctor Who (series 2).
--- -- Style: <showName> (<country> <seasonType> <seasonNumber>)
--- Example: The Office (American season 2).
--- Example: X Factor (British series 2).
--- -- Style: <showName> (<country> <seasonType>)
--- Example: Big Brother 2 (American season).
--- -- Style: <showName> (<year> TV series, <seasonType> <seasonNumber>)
--- Example: Teenage Mutant Ninja Turtles (1987 TV series, season 2)
--- -- Style: <showName> (<country> TV series, <seasonType> <seasonNumber>)
--- Example: Love Island (British TV series, series 2)
--- @param title string The article's title.
--- @param seasonNumberDiff number The number difference between the current season and the other season.
--- @return string, string
local function getArticleTitleAndPipedLink(title, seasonNumberDiff)
local disambiguation = getDisambiguation(title)
local shortDisambiguation
local seasonType
local seasonNumber
local pipedLink = ""
if (disambiguation) then
shortDisambiguation = getShortDisambiguation(disambiguation)
seasonType = getSeasonType(shortDisambiguation)
seasonNumber = getCurrentSeasonNumberFromDisambiguation(shortDisambiguation)
pipedLink = seasonType:gsub("^%l", string.upper) .. " "
end
local showName = getShowName(title)
local showNameModified
if (seasonNumber == nil or seasonNumber == "") then
-- Not a valid next/prev season link
if (not string.match(showName, "%s+(%d+)$")) then
return "", nil
end
showNameModified, seasonNumber = getShowNameAndSeasonNumberFromShowName(showName)
end
if (tonumber(seasonNumber) == nil) then
return "", nil
end
seasonNumber = seasonNumber + seasonNumberDiff
pipedLink = pipedLink .. seasonNumber
-- Titles such as "Big Brother 1 (American season)""
if (showNameModified and disambiguation) then
return showNameModified .. " " .. seasonNumber .. " (" .. disambiguation .. ")", pipedLink
-- Titles such as "Big Brother Brasil 1"
elseif (showNameModified) then
return showNameModified .. " " .. seasonNumber, nil
-- Standard titles such as "Lost (season 1)"
else
local newDisambiguation, _ = string.gsub(disambiguation, "%d+$", seasonNumber)
return showName .. " (" .. newDisambiguation .. ")", pipedLink
end
end
--- Returns the article's title either from args (usually from /testcases) or from the page itself.
--- @param frame table The frame invoking the module.
--- @return string
local function getTitle(frame)
local getArgs = require("Module:Arguments").getArgs
local args = getArgs(frame)
local title = args.title
if (not title) then
title = mw.title.getCurrentTitle().text
end
return title
end
--- Returns "true" if the given season link is valid; nil otherwise.
--- @param frame table The frame invoking the module.
--- @param seasonNumberDiff number The number difference between the current season and the other season.
--- @return string | nil
local function isSeasonLinkValid(frame, seasonNumberDiff)
local title = getTitle(frame)
local articleTitle, _ = getArticleTitleAndPipedLink(title, seasonNumberDiff)
return isLinkValid(articleTitle)
end
--- Returns a season article link.
--- @param frame table The frame invoking the module.
--- @param seasonNumberDiff number The number difference between the current season and the other season.
--- @return string
local function getSeasonArticleLink(frame, seasonNumberDiff)
local title = getTitle(frame)
local articleTitle, pipedLink = getArticleTitleAndPipedLink(title, seasonNumberDiff)
return getArticleLink(articleTitle, pipedLink)
end
--- Returns "true" if the season link for the next season is valid; nil otherwise.
--- @param frame table The frame invoking the module.
--- @return string | nil
function p.isNextSeasonLinkValid(frame)
return isSeasonLinkValid(frame, 1)
end
--- Returns "true" if the season link for the previous season is valid; nil otherwise.
--- @param frame table The frame invoking the module.
--- @return string | nil
function p.isPrevSeasonLinkValid(frame)
return isSeasonLinkValid(frame, -1)
end
--- Returns "true" if the season link for the previous or next season is valid; nil otherwise.
--- @param frame table The frame invoking the module.
--- @return string | nil
function p.isPrevOrNextSeasonLinkValid(frame)
if (p.isPrevSeasonLinkValid(frame) == "true") then
return "true"
end
return p.isNextSeasonLinkValid(frame)
end
--- Returns the next season article title.
--- @param frame table The frame invoking the module.
--- @return string
function p.getNextSeasonArticle(frame)
return getSeasonArticleLink(frame, 1)
end
--- Returns the previous season article title.
--- @param frame table The frame invoking the module.
--- @return string
function p.getPrevSeasonArticle(frame)
return getSeasonArticleLink(frame, -1)
end
--- Returns the type of season word used - "season" or "series".
--- @param frame table The frame invoking the module.
--- @return string
function p.getSeasonWord(frame)
local title = getTitle(frame)
local disambiguation = getDisambiguation(title)
if (not disambiguation) then
return ""
end
local shortDisambiguation = getShortDisambiguation(disambiguation)
local seasonType = getSeasonType(shortDisambiguation)
if (seasonType == "특집" or "스페셜") then
seasonType = "시즌"
end
return seasonType
end
--- Returns the relevant text for the sub-header field.
---
--- The text is returned in the format of "Season #" or "Series #",
--- depending on either what the article disambiguation uses, or on the manually entered parameters of the infobox.
--- @param frame table The frame invoking the module.
--- @return string | nil
function p.getInfoboxSubHeader(frame)
local getArgs = require("Module:Arguments").getArgs
local args = getArgs(frame)
local seasonType
local seasonNumber
if (args['시즌번호']) then
seasonType = "시즌"
seasonNumber = args['시즌번호']
elseif (args['시리즈번호']) then
seasonType = "시리즈"
seasonNumber = args['시리즈번호']
end
local title = getTitle(frame)
local disambiguation = getDisambiguation(title)
if (not seasonNumber and disambiguation) then
local shortDisambiguation = getShortDisambiguation(disambiguation)
seasonType = getSeasonType(shortDisambiguation)
if (seasonType == "특집" or "스페셜") then
return shortDisambiguation
end
seasonType = seasonType:sub(1, 1):upper() .. seasonType:sub(2)
seasonNumber = getCurrentSeasonNumberFromDisambiguation(shortDisambiguation)
end
if (seasonNumber and seasonNumber ~= "") then
return seasonType .. " " .. seasonNumber
end
return nil
end
--- Returns a formatted link to the list of episodes article.
---
--- The returned link is in the style of:
--- [List of <series name> <disambiguation, if present> episodes <range, if present>|List of episodes]
---
--- The link will only return if the page exists.
--- @param frame table The frame invoking the module.
--- @return string | nil
function p.getListOfEpisodes(frame)
local getArgs = require("Module:Arguments").getArgs
local args = getArgs(frame)
if (args.link) then
-- Parameter should be unformatted.
if (string.find(args.link, "%[")) then
local delink = require("Module:Delink")._delink
args.link = delink({args.link, wikilinks = "target"})
end
return getListOfEpisodesLink(args.link)
end
local title = getTitle(frame)
local showName = getShowName(title)
if (showName) then
local disambiguation = getDisambiguation(title)
local TVProgramDisambiguation = getTVProgramDisambiguation(disambiguation)
local listOfEpisodesArticle = string.format("%s%s의 에피소드 목록", showName, TVProgramDisambiguation)
return getListOfEpisodesLink(listOfEpisodesArticle)
end
end
return p