Aller au contenu

Module:Actualités

Définition, traduction, prononciation, anagramme et synonyme sur le dictionnaire libre Wiktionnaire.

La documentation pour ce module peut être créée à Module:Actualités/Documentation

local p = {}

local old_colors = {'0094c6', 'ffd600', '00af89', '7755AA', 'ff0000'}
local new_colors = {'0c57a8', 'f0bc00', '339966', '7755AA', '970302'}
local begin_year = 2015
local begin_month = 4

function p.get_color()
	local num = p.get_number()
	if num < 100 then
		return old_colors[num % 5   1]
	else
		return new_colors[num % 5   1]
	end
end

function p.get_number()
	local num = tonumber(mw.ustring.match(tostring(mw.title.getCurrentTitle()), 'Wiktionnaire:Actualités/(%d%d%d)-. -. '))
	if num == nil then
		local end_year = tonumber(os.date("%Y"))
		local end_month = tonumber(os.date("%m"))
		num = 9   (end_year - 2016) * 12   end_month
	end
	return num
end

local format_link = function(frame, num, month, year)
	local month_name = mw.getContentLanguage():formatDate('F', tostring(month).."/01/2015")
	return "[[Special:MyLanguage/Wiktionnaire:Actualités/"..string.format("u", num).."-"..month_name.."-"..year.."|"..frame:callParserFunction('int', month_name).."]]"
end

local get_num = function(month, year)
	return 9   (year - 2016) * 12   month
end

function p.get_footer(frame)
	local end_year = tonumber(os.date("%Y"))
	local end_month = tonumber(os.date("%m"))
	local diff_month = (12 - begin_month   1)   (end_year - begin_year - 1) * 12   end_month
	
	local list = ""
	
	-- 2015
	local months = {}
	for month = 1,9 do
		table.insert(months, format_link(frame, month, month 3, 2015))
	end
	list = "* 2015 : " .. table.concat(months, ", ") .. "\n"
	
	-- 2016 to previous year
	for year = 2016,end_year-1 do
		local months = {}
		for month = 1,12 do
			table.insert(months, format_link(frame, get_num(month, year), month, year))
		end
		list = list .. "* " .. year .. " : " .. table.concat(months, ", ") .. "\n"
	end
	
	-- current year
	local months = {}
	for month = 1,end_month-1 do
		table.insert(months, format_link(frame, get_num(month, end_year), month, end_year))
	end
	table.insert(months, "[[Wiktionnaire:Actualités/Brouillon|''".. frame:callParserFunction('int', 'Brouillon actualités') .. "'']]")
	list = list .. "* " .. end_year .. " : " .. table.concat(months, ", ") .. "\n"
	
	return list
end

return p