모듈:Infobox television season name
Jump to navigation
Jump to search
이 틀은 루아를 사용합니다: |
이 모듈은 텔레비전 시즌 정보 틀에서 양식화된 시즌 문서 링크의 생성을 위해 사용됩니다.
사용법[edit source]
{{#invoke:Infobox television season name|checkAll}}
{{#invoke:Infobox television season name|checkPrevSeason}}
{{#invoke:Infobox television season name|checkNextSeason}}
{{#invoke:Infobox television season name|getPrevSeasonArticle}}
{{#invoke:Infobox television season name|getNextSeasonArticle}}
매개 변수[edit source]
변수 | 설명 | 의무 사용 |
---|---|---|
title
|
프로그램 제목. 입력하지 않으면 변수에 문서의 제목이 사용됩니다. | 아니오 |
기능[edit source]
기능 | 설명 |
---|---|
checkAll
|
이전 및 다음 시즌 문서의 존재 여부를 확인합니다. |
checkPrevSeason
|
이전 시즌 문서의 존재 여부를 확인합니다. |
checkNextSeason
|
다음 시즌 문서의 존재 여부를 확인합니다. |
getPrevSeasonArticle
|
이전 시즌 문서의 제목을 검색합니다. |
getNextSeasonArticle
|
다음 시즌 문서의 제목을 검색합니다. |
getSeasonWord
|
문서 제목에 포함된 단어 "시즌" 또는 "시리즈"를 반환합니다. |
getInfoboxSubHeader
|
하위 머릿글 입력란에 적절한 문자를 반환합니다. 문자는 문서 제목에 괄호로 표기된 부분이나, 정보상자에 직접 입력된 변수에 따라 시리즈 # 또는 시즌 # 형태로 반환됩니다.
|
용례[edit source]
checkAll[edit source]
- 코드:
{{#invoke:Infobox television season name|checkAll|title=닥터 후 (시리즈 1)}}
- 출력:
58번째 줄에서 Lua 오류: attempt to call upvalue 'match' (a nil value).
getPrevSeasonArticle[edit source]
- 코드:
{{#invoke:Infobox television season name|getPrevSeasonArticle|title=네모바지 스폰지밥 (시즌 12)}}
- 출력:
58번째 줄에서 Lua 오류: attempt to call upvalue 'match' (a nil value).
getNextSeasonArticle[edit source]
- 코드:
{{#invoke:Infobox television season name|getNextSeasonArticle|title=로스트 (시즌 3)}}
- 출력:
58번째 줄에서 Lua 오류: attempt to call upvalue 'match' (a nil value).
local match = require("Module:String")._match
local p = {}
--[[
Local function which is used to create an pipped article link.
--]]
local function createArticleTitleWithPipedLink(article, pipedLink)
if (pipedLink == nil or pipedLink == "") then
return "[[" .. article .. "]]"
else
return "[[" .. article .. "|" .. pipedLink .. "]]"
end
end
--[[
Local helper function which is used to get the current season number and modified show name
from the show name.
--]]
local function getModifiedShowNameAndCurrentSeasonNumberFromShowName(showName)
local _, _, showNameModified, seasonNumber = string.find(showName, "(.*)%s+(%d+)")
return showNameModified, seasonNumber
end
--[[
Local helper function which is used to get the current season number from the disambiguation.
--]]
local function getCurrentSeasonNumberFromDisambiguation(shortDisambiguation)
return match(shortDisambiguation , "%d+", 1, -1, false, "")
end
--[[
Local helper function which is used to get the type of word used for "season"
in the disambiguation.
--]]
local function getSeasonType(shortDisambiguation)
local seasonType = string.find(shortDisambiguation , "시리즈")
if (seasonType) then
seasonType = "시리즈"
else
seasonType = "시즌"
end
return seasonType
end
--[[
Local helper function which is used to get the short disambiguation,
without the "(년도) 텔레비전 프로그램," part, which can cause issues later on.
--]]
local function getShortDisambiguation(disambiguation)
return string.gsub(disambiguation, "%d+년 텔레비전 프로그램, ", "")
end
--[[
Local helper function which is used to get the disambiguation from the title.
--]]
local function getDisambiguation(title)
local disambiguation = match(title, "%s%((.-)%)", 1, -1, false, "")
if (disambiguation == "") then
return nil
else
return disambiguation
end
end
--[[
Local helper function which is used to get the show name from the title.
--]]
local function getShowName(title)
return mw.ustring.gsub(title, "%s+%b()$", "")
end
--[[
Local function which is used to check if the given article exists.
The function returns "true" in the following cases:
-- A season article exists.
-- A redirect exists to a season section.
The function returns nil 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.
]]--
local function checkArticle(articleTitle)
local article = mw.title.new(articleTitle)
if (article ~= nil and article.exists) then
local redirectTarget = article.redirectTarget
if (redirectTarget) then
local fullLink = redirectTarget.fullText
local isSection = fullLink:find("#")
if (isSection) then
return "true" -- Article is a section redirect; Valid link.
else
return nil -- Article is a general redirect; Not a valid link.
end
else
return "true" -- Article exists and is not a redirect; Valid link.
end
else
return nil -- Article or redirect do not exist; Not a valid link.
end
end
--[[
Local function which returns a season article title and a piped link.
The following are the supported season naming styles:
-- <showName> (<seasonType> <seasonNumber>)
Example: Lost (season 2).
-- <showName> (<country> <seasonType> <seasonNumber>)
Example: The Office (American season 2).
Example: X Factor (British series 2).
-- <showName> (<country> <seasonType>)
Example: Big Brother 2 (American season).
-- <showName> (<year> TV series, <seasonType> <seasonNumber>)
Example: Teenage Mutant Ninja Turtles (1987 TV series, season 2)
-- <showName> (<country> TV series, <seasonType> <seasonNumber>)
Example: Love Island (British TV series, series 2)
--]]
local function getArticleTitle(title, prevOrNextSeasonNumber)
local showName = getShowName(title)
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 showNameModified
if (seasonNumber == "") then
if (string.match(showName , "%s+(%d+)")) then
showNameModified, seasonNumber = getModifiedShowNameAndCurrentSeasonNumberFromShowName(showName)
else
return "" -- Not a valid next/prev season link
end
end
if (tonumber(seasonNumber) == nil) then
return ""
else
seasonNumber = seasonNumber + prevOrNextSeasonNumber
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
disambiguation = string.gsub(disambiguation, "%d+$", seasonNumber)
return showName .. " (" .. disambiguation .. ")", pipedLink
end
end
end
--[[
Local helper function which is used to get the title,
either from args (usually from /testcases) or from the page itself.
--]]
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
--[[
Local helper function which is called to create a TV season title for the next or previous season.
Passes the value "1" or -1" to increment or decrement the current season number.
--]]
local function createArticleTitleHelper(frame, number)
local title = getTitle(frame)
return getArticleTitle(title, number)
end
--[[
Local helper function which is used to check if a season article exists.
--]]
local function checkSeason(frame, number)
local articleTitle = createArticleTitleHelper(frame, number)
return checkArticle(articleTitle)
end
--[[
Local helper function which is used to create a season article link.
--]]
local function getSeasonArticleLink(frame, number)
local articleTitle, pipedLink = createArticleTitleHelper(frame, number)
return createArticleTitleWithPipedLink(articleTitle, pipedLink)
end
--[[
Public function which is used to check if the next season has
a valid created article or redirect.
--]]
function p.checkNextSeason(frame)
return checkSeason(frame, 1)
end
--[[
Public function which is used to check if the previous season has
a valid article or redirect.
--]]
function p.checkPrevSeason(frame)
return checkSeason(frame, -1)
end
--[[
Public function which is used to check if the next or previous season have
a valid article or redirect.
Parameters:
--]]
function p.checkAll(frame)
if (p.checkPrevSeason(frame) == "true") then
return "true"
else
return p.checkNextSeason(frame)
end
end
--[[
Public function which is used to get the next season article title.
--]]
function p.getNextSeasonArticle(frame)
return getSeasonArticleLink(frame, 1)
end
--[[
Public function which is used to get the previous season article title.
--]]
function p.getPrevSeasonArticle(frame)
return getSeasonArticleLink(frame, -1)
end
--[[
Public function which is used to get the type of season word used - "season" or "series".
--]]
function p.getSeasonWord(frame)
local title = getTitle(frame)
local disambiguation = getDisambiguation(title)
if (disambiguation) then
local shortDisambiguation = getShortDisambiguation(disambiguation)
return getSeasonType(shortDisambiguation)
else
return ""
end
end
--[[
Public function which is used to return the relevant text for the sub-header field.
The text is returned in the format of <code>Season #</code> or <code>Series #</code>,
depending on either what the article disambiguation uses, or on manually entered parameters of the infobox.
--]]
function p.getInfoboxSubHeader(frame)
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame)
local title = getTitle(frame)
local showName = getShowName(title)
local disambiguation = getDisambiguation(title)
if (not seasonNumber and disambiguation) then
local shortDisambiguation = getShortDisambiguation(disambiguation)
seasonType = getSeasonType(shortDisambiguation)
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
return p