Module:TCWdates

local p = {}

local function makeCategoryLink(cat) -- "Category" is split out here so that the module isn't put into the -- category "%s" when the page is saved. return string.format('%s:%s', 'Category', cat) end local function makeWikitextError(msg) local ret = '' ret = ret .. string.format(		' Template:TCWdates error: %s. ',		msg	) if mw.title.getCurrentTitle.namespace == 0 then ret = ret .. makeCategoryLink('Articles with template errors') end return ret end

function p.citation(arg, data) local messages = data.messages local episode_list = data.episodes -- Check for invalid episode number if not episode_list[tostring(arg)] then -- return makeWikitextError(string.format('invalid episode number %d', arg)) end -- Return custom message if the episode doesn't use one of the presets if not episode_list[tostring(arg)].templ then return episode_list[tostring(arg)].msg end local episode_name = episode_list[tostring(arg)].episode local temp = episode_list[tostring(arg)].templ -- Create the message from the presets. result = messages[temp][1] .. episode_name if temp == "error" then result = result .. messages.temp[2] -- Checks for pipelinks, and add them if necessary elseif episode_list[tostring(arg)].episode2 then result = result .. "|" .. episode_list[tostring(arg)].episode2 result = result .. messages[temp][2] .. episode_list[tostring(arg)].episode2 result = result .. messages[temp][3] else result = result .. messages[temp][2] .. episode_name result = result .. messages[temp][3] end return result end

function p.main(frame) local data = mw.loadData('Module:TCWdates/data') local args = {} for k, v in pairs(frame:getParent.args) do		v = v:match('^%s*(.-)%s*$') -- trim whitespace if v ~= '' then args[k] = v		end end return p.citation(args[1], data) or '' end

return p