Module:Ep ref/sandbox

local p = {} -- function to create and format the reference function p.epRef(frame) local reference = true -- receiving parameters local ep = frame.args["ep"] or "" local part = frame.args["part"] or nil local intro = frame.args["intro"] or nil local more = frame.args["more"] or nil local vod = frame.args["vod"] or nil local group = frame.args["group"] or nil local name = frame.args["name"] or nil local startTime = frame.args[1] or nil local endTime = frame.args[2] or nil local cite = frame.args["cite"] or nil local nsfw = frame.args["nsfw"] or nil -- convert the input into the standardized epCode local epMatcher = require('Module:Ep/Matcher') local epCode = epMatcher.matchCode(frame, reference) -- get the title and pagename for that epCode local epInfo = require('Module:Ep/Info') local epName = epInfo.title(epCode) local pageName = epInfo.pagename(epCode) local epValue if isnotempty(epCode) then if pageName ~= epName then epValue = pageName .. '|' .. epName elseif isnotempty(pageName) then epValue = pageName else epValue = '' end end

-- (epCode) local small = mw.html.create('small') small :wikitext("(" .. epCode .. ")")   if isnotempty(epCode) then fullEpValue = epName .. " " .. tostring(small) else fullEpValue = epName end -- Set empty epCode value to 0x00 for the purposes of the "Articles needing citations/0x00" category if not isnotempty(epCode) then epCode = "0x00" end -- get YouTube URL from Module:Ep/YTURLSwitcher/URLs local ytURL = mw.loadData('Module:Ep/YTURLSwitcher/URLs') local url if isnotempty(vod) then url = vod elseif isnotempty(part) then url = ytURL[epCode .. part] else url = ytURL[epCode] or ytURL["default"] end --add timestamp to youtube URL local timeSnippet local timedURL local longURL = false local timeLength if isnotempty(url) then longURL = string.find(url, "?") end -- split timestamp at colons if isnotempty(startTime) then timeSnippet = split(startTime, ":") end if isnotempty(timeSnippet) then timeLength = #timeSnippet end -- adding time to standard ("long") YouTube URLs if isnotempty(timeSnippet) and longURL and timeLength == 3 then timedURL = "[" .. url .. "&amp;t=0" .. timeSnippet[1] .. "h0" .. timeSnippet[2] .. "m0" .. timeSnippet[3] .. "s " .. startTime .. "] "   elseif isnotempty(timeSnippet) and longURL and timeLength == 2 then timedURL = "[" .. url .. "&amp;t=0" .. timeSnippet[1] .. "m0" .. timeSnippet[2] .. "s " .. startTime .. "] "   elseif isnotempty(timeSnippet) and longURL and timeLength == 1 then timedURL = "[" .. url .. "&amp;t=0" .. timeSnippet[1] .. "s " .. startTime .. "] " end -- adding time to shortened URLS if isnotempty(url) and isnotempty(timeSnippet) and not longURL and timeLength == 3 then timedURL = "[" .. url .. "?t=0" .. timeSnippet[1] .. "h0" .. timeSnippet[2] .. "m0" .. timeSnippet[3] .. "s " .. startTime .. "] "   elseif isnotempty(url) and isnotempty(timeSnippet) and not longURL and timeLength == 2 then timedURL = "[" .. url .. "?t=0" .. timeSnippet[1] .. "m0" .. timeSnippet[2] .. "s " .. startTime .. "] "   elseif isnotempty(url) and isnotempty(timeSnippet) and not longURL and timeLength == 1 then timedURL = "[" .. url .. "?t=0" .. timeSnippet[1] .. "s " .. startTime .. "] " end if isnotempty(timedURL) then startTime = timedURL end local refText = 'See ' .. fullEpValue if isnotempty(part) then refText = refText .. ", part " .. part end if isnotempty(part) and isnotempty(startTime) then refText = refText .. "," end if isnotempty(startTime) and isnotempty(endTime) then refText = refText .. " from " .. startTime .. " through " .. endTime .. "."   elseif isnotempty(startTime) then refText = refText .. " at " .. startTime .. "."   else refText = refText .. "." end -- citation format local supCite = mw.html.create('sup') supCite :wikitext("[citation needed]") local citeCategory if isnotempty(cite) then citeCategory = "" end if isnotempty(intro) then refText = intro .. " " .. refText end if isnotempty(cite) then refText = refText .. tostring(supCite) .. citeCategory end if isnotempty(more) then refText = refText .. " " .. more end if isnotempty(nsfw) then nsfw = " NSFW ." end if isnotempty(nsfw) then refText = refText .. nsfw end -- create wikitext reference local reference = "" .. refText .. " "   return frame:preprocess(reference) end -- function to split a string at a specified character function split(s, delimiter) result = {}; for match in (s..delimiter):gmatch("(.-)"..delimiter) do       table.insert(result, match); end return result; end -- function to determine that a string is not empty function isnotempty(s) return s ~= nil and s~= '' end return p