Halo Esports Wiki
Advertisement

To edit the documentation or categories for this module, click here.


local lang = mw.getLanguage('en')
local util_time = require('Module:TimeUtil')
local util_vars = require("Module:VarsUtil")
local Stat = require('Module:Stat')

local p = {}
local h = {}
function p.makeBday(y, m, d, death)
	-- expect death to be a string yyyy-mm-dd
	if not ((m and d) or death) then
		return {}
	end
	if not m then m = '1' end
	if not d then d = '1' end
	local m = tostring(util_time.monthNameToNumber[m])
	if #m == 1 then
		m = '0' .. m
	end
	if #d == 1 then
		d = '0' .. d
	end
	local full = y and m and d
	if not full then
		y = 2014 -- we won't print this, just a random year so that the formatting works
	end
	local str = ('%s-%s-%s'):format(y,m,d)
	local tbl = {
		full = full,
		age = full and util_time.age(str, death),
		display = h.pickAndGetDisplay(full, str, death),
		store = death or (full and str) or ''
	}
	tbl.displayandage = tbl.display .. (full and (' (age %s)'):format(tbl.age) or '')
	return tbl
end

function h.pickAndGetDisplay(full, str, death)
	if death then return h.getDisplay(death, true) end
	return h.getDisplay(str, full)
end

function h.getDisplay(time, full)
	return full and lang:formatDate('F j, Y', time) or lang:formatDate('F j', time)
end

function p.getFile(arg, default)
	local title = arg and mw.title.makeTitle('Media', arg or '')
	if title and title.exists then
		p.setFeaturedImage(arg)
		return arg
	end
	return default
end

function p.getFileNoExistenceCheck(image, default)
	if image then
		p.setFeaturedImage(image)
		return image
	end
	return default
end

function p.statDisplays(tbl)
	local ret = {}
	for _, v in ipairs(tbl) do
		local stat = Stat(v)
		if not stat.unknown then
			ret[v] = stat:flair()
		end
	end
	return ret
end

function p.setFeaturedImage(file)
	-- note this does not work because OGM is disabled in main ns currently
	mw.getCurrentFrame():callParserFunction{
		name = '#setmainimage',
		args = { file:gsub('File:', '') },
	}
end

function p.printLowContentNoticeIfNeeded(output, text)
	if not util_vars.getBool('isLowContent') then return end
	if not output then output = mw.html.create() end
	output:tag('div')
		:addClass('low-content-notice-wrapper')
		:tag('div')
			:addClass('low-content-notice')
			:wikitext(text)
	return output
end

return p
Advertisement