Module:Updates

This module does not have any documentation. Please consider adding documentation at Module:Updates/doc. [edit]
Module:Updates requires Module:Array.

local contains = require('Module:Array').contains

local p = {}

local lang = mw.getContentLanguage()

local looporder = {
	{ 'December', 31 },
	{ 'November', 30 },
	{ 'October', 31 },
	{ 'September', 30 },
	{ 'August', 31 },
	{ 'July', 31 },
	{ 'June', 30},
	{ 'May', 31 },
	{ 'April', 30 },
	{ 'March', 31 },
	{ 'February', 29 },
	{ 'January', 31 }
}

function sortFunc(a,b)
	return a[2] < b[2]
end

function lookup(cat)
	local r = mw.getCurrentFrame():preprocess(string.format([=[
{{#dpl:
|namespace=Update
|category=%s
|include={Update}:date,{Patch Notes}:date,{DevBlog}:date
|format=,¦UD¦%%PAGE%%@D@,,
|ordermethod=sortkey
}}
]=], cat))
	local ret = { }
	local keys = {}
	for v in mw.text.gsplit(r, '|UD|', true) do
		if v:find('@') then
			local u,_d = unpack(mw.text.split(v, '@D@'))
			u = mw.text.trim(u)
			u = string.sub(u, 8, -1)
			_d = mw.text.trim(_d)
			local y,m,d = unpack(mw.text.split(lang:formatDate('Y-F-j', _d), '-', true))
			y = tonumber(y)
			d = tonumber(d)
			if not ret[y] then
				ret[y] = {}
			end
			if not ret[y][m] then
				ret[y][m] = {}
			end
			if not ret[y][m][d] then
				ret[y][m][d] = {u}
			else
				table.insert(ret[y][m][d], u)
			end
		end
	end
	return ret
end

function p.year(frame)
	return p._year(frame:getParent().args)
end
function p._year(args)
	local year = args[1] or mw.title.getCurrentTitle().text
	local data = lookup(year..' updates')
	data = data[tonumber(year)]
	local gameUpdQ = mw.smw.ask{ '[[Category:' .. year .. ' updates]][[Category:Game updates]]', '?#-'}
	local gameUpdates = {}
	if gameUpdQ == nil then
		return '\n\'\'No updates have been released this year so far. If you believe this is a mistake, leave a message in [[Module talk:Updates|this talk page]].\'\''
	end
	for _,v in ipairs(gameUpdQ) do
		table.insert(gameUpdates, v[1])
	end
	local ret = {'Titles in bold indicate a [[Game updates|game update]].'}
	local data_m, data_d
	for _,m in ipairs(looporder) do
		data_m = data[m[1]]
		if data_m then
			table.insert(ret, '\n\n=='..m[1]..'==')
			for d = m[2], 1, -1 do
				data_d = data_m[d]
				if data_d then
					table.insert(ret, string.format('\n* [[%s %s]]', tostring(d), m[1]))
					table.sort(data_d)
					for _,u in ipairs(data_d) do
						-- bold game updates
						local updBullet = contains(gameUpdates, 'Update:' .. u) and string.format('\n** \'\'\'[[Update:%s|%s]]\'\'\'', u, u) or string.format('\n** [[Update:%s|%s]]', u, u)
						table.insert(ret, updBullet)
					end
				end
			end
		end
	end
	return mw.text.trim(table.concat(ret, ''))
end

return p