Aller au contenu

Module:Catégorie par date

Cette page fait l’objet d’une mesure de semi-protection étendue.
Une page de Wikipédia, l'encyclopédie libre.

 Documentation[créer] [purger]
local p = {}

function p.categorize(frame)
	local args1 = frame:getParent().args
	local args2 = frame.args
	
	local dateparam = args1[1]
	if (not dateparam) or dateparam == '' then return nil end
	
	local prefix = args2.prefix
	local suffix = args2.suffix
	if prefix then prefix = prefix .. ' ' else prefix = '' end
	if suffix then suffix = ' ' .. suffix else suffix = '' end
	local default = args2.default or 'Échec de Module:Catégorie par date'
	local datemin = tonumber(args2.datemin) or 2024
	local datemax = tonumber(args2.datemax) or 2024
	
	local catstring
	for datenum = datemin,datemax do
		local datestring = tostring(datenum)
		if mw.ustring.find(dateparam,datestring) then
			catstring = '[[Category:' .. prefix .. datestring .. suffix .. ']]'
			return catstring
		end
	end
	
	catstring = '[[Category:' .. default .. ']]'
	return catstring
end
 
return p