Module:Events

local p = {}

local event = mw.loadData('Module:Events/data')

function range(a, b, step) if not b then b = a   a = 1 end step = step or 1 local f = step > 0 and function(_, lastvalue) local nextvalue = lastvalue + step if nextvalue <= b then return nextvalue end end or   step < 0 and function(_, lastvalue) local nextvalue = lastvalue + step if nextvalue >= b then return nextvalue end end or     function(_, lastvalue) return lastvalue end return f, nil, a - step end

function compareLess(x, y)   return x[1] < y[1] end function compareMore(x, y)   return x[1] > y[1] end function tableSort(table1,table2,more) for i,v in ipairs(table1) do       table1[i] = {table1[i], table2[i]} end if more == 'less' then table.sort(table1, compareLess) else table.sort(table1, compareMore) end for i, v in ipairs(table1) do       table1[i] = v[1] table2[i] = v[2] end return table2 end function eventSorted(datas, var) local key = {} local keydata = {} local more for name, data in pairs(datas) do       if var == nil then table.insert(key, eventDate(data)) else table.insert(key, data.lvl) more='less' end table.insert(keydata, name) end return tableSort(key,keydata,more) end function eventDate(data) if data.ends[1] ~= nil then return ((((data.ends[3]*100)+data.ends[2])*100)+data.ends[1]) else return 0 end end function active local currentDate = ((((os.date('*t').year*100)+os.date('*t').month)*100)+os.date('*t').day) for name, data in pairs(event) do       if eventDate(data)-currentDate > 0 then return name end end return nil end

p.range = range p.tableSort = tableSort p.eventSorted = eventSorted p.eventDate = eventDate p.active = missingImage

function missingImage(picture) local img = '' if picture == "" or picture == nil then img = 'Missing.png' else img = picture end return img end

function p.infobox(frame) local event_data = event[mw.title.getCurrentTitle.text] local start_date = os.date("%a, %d %b %Y",os.time{year=event_data.starts[3], month=event_data.starts[2], day=event_data.starts[1]}) local end_date = os.date("%a, %d %b %Y",os.time{year=event_data.ends[3], month=event_data.ends[2], day=event_data.ends[1]}) local data = { image=missingImage(event_data.image), starts=start_date, ends=end_date, next=nil, prev=nil }   return  table.concat({frame:expandTemplate { title = 'Event infobox', args = data },event_data.text,}, "\n") end

function p.missions(frame) return end function p.rewards(frame) return end function p.events(frame) local typ = frame.args[1] local data = {' '} local sorted = eventSorted(event) local active = active local c = 0 if active ~= nil then table.insert(data, '==Current Event==') table.insert(data, '') end for name, dat in pairs(sorted) do       event_data=event[dat] if dat ~= active then if c == 0 then table.insert(data, '==Past Event==') end c = c + 1 if event_data.event_type ~= "OTHER" and true==(c < 9 or typ~='mainPage') then table.insert(data, '') end end end if typ == 'mainPage' then table.insert(data," Show more ") end table.insert(data,' ') for i, dat in pairs(data) do mw.log(dat) end return table.concat(data,"\n") end return p