Module:MiniEvent

-- Test LUA script to get Mini Event information --

local p = {}

local meData = mw.loadData( 'Module:MiniEvent/data' ) --local date = require('Dev:Date')

Local Functions local function getArgs(frame) local tArgs

if frame == mw.getCurrentFrame then fParent = frame:getParent tArgs = fParent.args

if (fParent.args[1]) then tArgs = fParent.args else tArgs = frame.args end else tArgs = frame end return tArgs end

local function strDate(mon_day) local months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}

local mon = months[math.floor(mon_day/100)] local day = math.fmod(mon_day, 100) local idd = math.fmod(mon_day, 10) local nth = (idd==1 and day~=11 and "st ") or (idd==2 and day~=12 and "nd ") or (idd==3 and day~=13 and "rd ") or "th " return (day .. nth .. mon) end

local function singleEvent(sName, eType, outType, altText) local eventName = "Work In Progress" local collection = "Unknown Event" local eventYear = nil

local outText = eventName local dispText = "" local dateText = ""

if meData[eType] and meData[eType][sName] then eventName = meData[eType][sName][2] eventYear = meData[eType][sName][3] eventDate = meData[eType][sName][4] collection = meData[eType][sName][5] or meData[eType][sName][2] outText = eventName .. " Mini Event" end

if outType:match("^[ACSD]$") then if outType == "A" then dispText = altText elseif outType == "C" then dispText = collection elseif outType == "S" then dispText = eventName elseif outType == "D" then if altText ~= "" then dispText = altText elseif eType == "N" then dispText = eventName .. " Mini Event" else dispText = eventName .. "'s Tower Challenge Event" end dateText = " on " .. strDate(eventDate) .. " " .. eventYear end end

if outType ~= "T" then if eventYear then outText = outText end if dispText and dispText ~="" then outText = outText .. "|" .. dispText end

outText = "" .. outText .. ""

if dateText and dateText ~="" then outText = outText .. dateText end end return outText end

local function multiEvent(eType, outType, year) local tIndex = {} local tOutput = {}

if meData[eType] then if year and year ~= 0 then for k, v in pairs(meData[eType]) do               if year == v[3] then table.insert(tIndex,v[1]) tOutput[v[1]] = v               end end else for k, v in pairs(meData[eType]) do               table.insert(tIndex,v[1]) tOutput[v[1]] = v           end end end

table.sort(tIndex)

local outText = "" local sDot   = ""

for _, idx in ipairs(tIndex) do

if eType == "T" then outText = outText .. sDot .. "[[The Tower Challenge ("                       .. tOutput[idx][2]                        .. ") Event "                        .. tOutput[idx][3]        else            outText = outText .. sDot                         .. "[["                        .. tOutput[idx][2]                        .. " Mini Event "                        .. tOutput[idx][3]        end

if outType == "S" then outText = outText .. "|" .. tOutput[idx][2] elseif outType == "C" then if tOutput[idx][5] then outText = outText .. "|" .. tOutput[idx][5] else outText = outText .. "|" .. tOutput[idx][2] end end outText = outText .. "]]"

sDot = " · " end return outText end

-- function get Limited Time Event function p.getME(frame)

local tArgs = getArgs(frame)

local sName   = tArgs[1] or "" local eType   = tArgs[2] local outType = tArgs[3] or "N" local altText = tArgs[4] or ""

sName = sName:lower:gsub("^%s*(.-)%s*$", "%1") or ''

if not eType or eType == "" then eType = "N" end

eType = eType:upper outType = outType:upper

local multi, year = sName:match("^(multi)(%d*)$")

if multi then return multiEvent(eType, outType, tonumber(year)) else return singleEvent(sName, eType, outType, altText) end end

-- function get Last X events function p.getLast(frame) local tArgs = getArgs(frame)

if frame == mw.getCurrentFrame then fParent = frame:getParent tArgs = fParent.args

if (fParent.args[1]) then tArgs = fParent.args else tArgs = frame.args end else tArgs = frame end

local count = tArgs[1] count = tonumber(count) or 5 local allEvents = {}

for k, t in pairs(meData) do       for _, v in pairs(t) do            local event = {} --event[1] = (v[3] * 10000) + v[4] event[1] = os.time({year = v[3],                       month= math.floor(v[4]/100),                        day= math.fmod(v[4], 100)}) event[2] = k           event[3] = v[2] event[4] = v[3] if (event[1] <= os.time) then table.insert(allEvents, event) end end end

table.sort(allEvents, function(a,b) return a[1] > b[1] end)

local outText = ""

for i, v in ipairs(allEvents) do       local linkText  = "" local dateText = os.date("%e %B %Y", v[1]) dateText = dateText:gsub("^%s*(.-)%s*$", "%1") or ''

linkText = "* "                       .. mw.text.truncate(v[3], 43 - mw.ustring.len(dateText), nil, true)                        .. " " .. dateText .. " \n"

outText = outText .. linkText if i >= count then break end end return outText end return p

-- --