local descriptionList =
local validLinkList =
local seriesEntryList =
local errorMessages =
local errors =
local p =
--Local function which is used to create an error message.--local function createErrorMsg(errorText) local errorMsg = '
Error: ' .. errorText .. '.' table.insert(errors, errorMsg)end--Local function which is used to create a missing value error message.--local function createMissingValueError(link, season, episode, paramNumber) if (not link) then createErrorMsg(string.format(errorMessages["MISSING_VALUE"], "link" .. paramNumber)) end if (not season) then createErrorMsg(string.format(errorMessages["MISSING_VALUE"], "season" .. paramNumber)) end if (not episode) then createErrorMsg(string.format(errorMessages["MISSING_VALUE"], "episode" .. paramNumber)) endend
--Local function which is used to retrieve the series name without the disambiguation.--local function getSeriesNameWithoutDisambiguation(seriesName) return mw.ustring.gsub(seriesName, "%s+%b$", "")end
--Local function which is used to retrieve the series name from the episode link.--local function getSeriesNameFromLink(link) for i = 1, #validLinkList do -- Get series name with possibile disambiguation from link. local _, _, seriesName = string.find(link, validLinkList[i]) if (seriesName and ((i < 3) or ((i
return nilend
--Local function which is used to create a series entry of a consistent style fromthe crossover episode parameters.--local function createSeriesEntryFromMultiParameters(link, season, episode) local seriesName = getSeriesNameFromLink(link) if (seriesName) then if (episode
--Local function which is used to create a series entry of a consistent style fromthe crossover episode parameters.--local function createSeriesEntryFromSeriesParameter(seriesArticle) local seriesName = getSeriesNameWithoutDisambiguation(seriesArticle) if (seriesName) then return string.format(seriesEntryList["SHORT"], seriesArticle, seriesName) else return nil endend
--Local function which gets the series list from either the numbered (positional) or named parameters,and checks if the number of series parameters match the value of parts - creates an error message if they aren't.Returns the series list or nil.--local function getSeriesList(parts, args) local seriesList =
-- This parameter is used for a general crossover that happens in 1 episode. if (args.series) then local series = createSeriesEntryFromSeriesParameter(args.series) if (series) then seriesList[1] = series return seriesList else createErrorMsg(string.format(errorMessages["INCORRECT_LINK_SERIES"])) return nil end end
-- Multi-episode crossovers.
parts = parts - 1 if (parts < 1) then parts = 1 end
for i = 1, parts do local link = args["link" .. i] local season = args["season" .. i] local episode = args["episode" .. i]
if (link and episode and (season or (episode
--Local function which checks if the parameters used are correct.Creates an error message if they aren't.--local function isArgValidNumber(name, value) if (value) then if (tonumber(value)) then return tonumber(value) else createErrorMsg(string.format(errorMessages["NOT_A_NUMBER"], name)) return nil end else createErrorMsg(string.format(errorMessages["MISSING_VALUE"], name)) return nil endend
--Local function which is used to handle the actual main process.--local function _main(args) local parts = isArgValidNumber("parts", args.parts) local currentPart = isArgValidNumber("part", args.part)
-- If missing parts or current part values, show an error. if (not parts or not (currentPart or parts
local seriesList = getSeriesList(parts, args)
-- If missing series parts, show an error. if (not seriesList) then -- Error message handling. return table.concat(errors) end
if (parts
local text = string.format(descriptionList[parts][currentPart], seriesList[1], seriesList[2], seriesList[3], seriesList[4], seriesList[5]) if (args.no_hr) then return text else return "
--part= — required; The crossover part number of the current episode. -- |parts= — required; The number of total crossover episodes. -- |no_hr= — optional; Any value will disable the addition of the
return p