Module:Archive header

Module documentation

This module determines if the current page is (likely to be) a yearly/monthly archive. It is used by {{Archive header}}.

local p = {}

local function isGoodYear(candidate)
	return (candidate and candidate >= 2002 and candidate <= tonumber(os.date('%Y')))
end

function p._getArchiveType(subpageName)
	if isGoodYear(tonumber(subpageName)) then
		return 'year'
	end
	local year, month = string.match(subpageName, '(%d%d%d%d)%-(%d%d)')
	if isGoodYear(tonumber(year)) and tonumber(month) >= 1 and tonumber(month) <= 12 then
		return 'month'
	end
	local year, week = string.match(subpageName, '(%d%d%d%d)%-w(%d%d?)')
	if isGoodYear(tonumber(year)) and tonumber(week) >= 1 and tonumber(week) <= 53 then
		return 'week'
	end
	return nil
end

function p.getArchiveType(frame)
	return p._getArchiveType(mw.title.getCurrentTitle().subpageText)
end

return p