Module:Wikiprojet/Wikiconcours

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

 Documentation[voir] [modifier] [historique] [purger]

Module remplaçant {{Wikiprojet/Wikiconcours}}, notamment afin de centraliser et simplifier les ajouts de concours.

local p = {}

local data = {
	{ edition = '2006'          , from = '15 novembre 2006'  , to = '15 décembre 2006' , background = '#cfcf00' },
	{ edition = '2007'          , from = '7 mai 2007'        , to = '1er juillet 2007' , background = '#772f99', color = '#ffffff' },
	{ edition = 'mars 2008'     , from = '1er mars 2008'     , to = '30 avril 2008'    , background = '#009933', color = '#ffffff' },
	{ edition = 'septembre 2008', from = '1er septembre 2008', to = '31 octobre 2008'  , background = '#ff6000' },
	{ edition = 'mars 2009'     , from = '1er mars 2009'     , to = '30 avril 2009'    , background = '#80d0d0' },
	{ edition = 'septembre 2009', from = '1er septembre 2009', to = '15 septembre 2009', background = '#b82010', color = '#ffffff' },
	{ edition = 'mars 2010'     , from = '1er mars 2010'     , to = '30 avril 2010'    , background = '#c8ad7f' },
	{ edition = 'septembre 2010', from = '15 septembre 2010' , to = '14 novembre 2010' , background = '#40e0d0' },
	{ edition = 'mars 2011'     , from = '1er mars 2011'     , to = '15 mars 2011'     , background = '#ff69b4' },
	{ edition = 'septembre 2011', from = '15 septembre 2011' , to = '14 novembre 2011' , background = '#868686', color = '#ffffff' },
	{ edition = 'mars 2012'     , from = '1er mars 2012'     , to = '30 avril 2012'    , background = '#f6ffbf' },
	{ edition = 'octobre 2012'  , from = '1er octobre 2012'  , to = '15 octobre 2012'  , background = '#dcb9dc' },
	{ edition = 'mars 2013'     , from = '1er mars 2013'     , to = '30 avril 2013'    , background = '#81b381' },
	{ edition = 'septembre 2013', from = '15 septembre 2013' , to = '14 novembre 2013' , background = '#ffffd0' },
	{ edition = 'mars 2014'     , from = '1er mars 2014'     , to = '21 mars 2014'     , background = '#d9e5fb' },
	{ edition = 'septembre 2014', from = '19 septembre 2014' , to = '23 novembre 2014' , background = '#efb776' },
	{ edition = 'mars 2015'     , from = '1er mars 2015'     , to = '30 avril 2015'    , background = '#fbc5b3' },
	{ edition = 'octobre 2015'  , from = '3 octobre 2015'    , to = '1er novembre 2015', background = '#fbfcfa' },
	{ edition = 'mars 2016'     , from = '1er mars 2016'     , to = '30 avril 2016'    , background = '#82b395' },
	{ edition = 'octobre 2016'  , from = '1er octobre 2016'  , to = '30 novembre 2016' , background = '#F6DC12' },
	{ edition = 'mars 2017'     , from = '1er mars 2017'     , to = '21 mars 2017'     , background = '#BBD2E1' },
	{ edition = 'septembre 2017', from = '15 septembre 2017' , to = '19 novembre 2017' , background = '#F5A9A9' },
	{ edition = 'mars 2018'     , from = '1er mars 2018'     , to = '30 avril 2018'    , background = '#CECECE' },
	{ edition = 'septembre 2018', from = '22 septembre 2018' , to = '21 octobre 2018'  , background = '#F5DEB3' },
	{ edition = 'mars 2019'     , from = '1er mars 2019'     , to = '30 avril 2019'    , background = '#B2C6FF' },
	{ edition = 'septembre 2019', from = '21 septembre 2019' , to = '24 novembre 2019' , background = '#FFC080' },
	{ edition = 'mars 2020'     , from = '15 mars 2020'      , to = '14 avril 2020'    , background = '#FAF0E6' },
	{ edition = 'septembre 2020', from = '12 septembre 2020' , to = '8 novembre 2020'  , background = '#FCE5FF' },
	{ edition = 'mars 2021'     , from = '20 mars 2021'      , to = '2 mai 2021'       , background = '#66B3CC' },
	{ edition = 'septembre 2021', from = '18 septembre 2021' , to = '10 octobre 2021'  , background = '#D0FFE0' },
	{ edition = 'mars 2022'     , from = '1er mars 2022'     , to = '30 avril 2022'    , background = '#F6A3A8' },
	{ edition = 'septembre 2022', from = '19 septembre 2022' , to = '16 octobre 2022'  , background = '#EFCFE9' }, 
	{ edition = 'mars 2023'     , from = '1er mars 2023'     , to = '30 avril 2023'    , background = '#FFDBC1' }, 
	{ edition = 'septembre 2023', from = '1er septembre 2023', to = '31 octobre 2023'  , background = '#e2fcfb' },
	{ edition = 'mars 2024'     , from = '16 mars 2024'      , to = '19 avril 2024'    , background = '#d05f3e', color = '#ffd700' },
}

local moduleDate -- sera chargé lors de sa première utilisation

local function template( title, args )
	return mw.getCurrentFrame():expandTemplate{ title = title, args = args }
end

-- exemple de résultat : « s’est déroulé du {{date-|22 septembre 2018-}} au {{date-|21 octobre 2018}} »
local function periode( from, to )
	moduleDate = moduleDate or require 'Module:Date'

	local fromDay, fromMonth, fromYear = from:match( '(%S+) (%S+) (%S+)' )
	local toDay, toMonth, toYear = to:match( '(%S+) (%S+) (%S+)' )

	local fromISO = moduleDate.dateISO{ jour = fromDay, mois = fromMonth, annee = fromYear }
	local toISO = moduleDate.dateISO{ jour = toDay, mois = toMonth, annee = toYear }
	local todayISO = os.date( '%F' )

	local verbe
	if toISO < todayISO then
		verbe = 's’est déroulé'
	elseif todayISO < fromISO then
		verbe = 'se déroulera'
	else
		verbe = 'se déroule'
	end

	local fromText = moduleDate.modeleDate{
		fromDay,
		fromMonth .. ( fromMonth == toMonth and '-' or '' ),
		fromYear .. ( fromYear == toYear and '-' or '' ),
		nolinks = true
	}

	local toText = moduleDate.modeleDate{
		toDay,
		toMonth,
		toYear,
		nolinks = true
	}

	return verbe .. ' du ' .. fromText .. ' au ' .. toText
end

local function row( concours, param )
	local edition = concours[ 'edition' ]

	local equipe
	if edition == '2006' then
		equipe = template( "u'", { param } ) -- cas particulier édition 2006
	else
		equipe = 'l’[[Wikipédia:Wikiconcours/' .. edition .. '/Équipes/Équipe ' .. param .. '|équipe ' .. template( 'numéro' ) .. param .. ']]'
	end

	local background = ' background:' .. concours[ 'background' ] .. ';'
	local color = ( concours[ 'color' ] and ' color:' .. concours[ 'color' ] .. ';' or '' )

	return '<tr>'
			.. '<td style="width:10%; text-align:center; font-weight:bold;' .. background .. color .. '">'
				.. edition
			.. '</td>'
			.. '<td style="font-size:italic">'
				.. 'Il a été choisi par ' .. equipe
				.. " pour le '''[[Wikipédia:Wikiconcours/" .. edition .. "|Wikiconcours " .. edition .. "]]'''"
				.. ' qui ' .. periode( concours[ 'from' ], concours[ 'to' ] ) .. '.'
			.. '</td>'
		.. '</tr>'
end

local function tableau( rows )
	if #rows > 0 then
		return '<table style="background:#ededed; width:100%; margin-top:1.2em; border-spacing:0.6em 2px; padding:0.4em 0; border:1px solid #a7d7f9; border-radius:10px; border-collapse:separate;">'
				.. '<caption style="padding-bottom:5px">'
					.. '[[Fichier:Goldenwiki nostand.png|20px|Wikiconcours]]'
					.. ' Cet article a été sélectionné lors ' .. ( #rows == 1 and 'd’un' or 'de plusieurs' ) .. ' [[Wikipédia:Wikiconcours|Wikiconcours]] :'
				.. '</caption>'
				.. table.concat( rows )
			.. '</table>'
	else
		return ''
	end
end

function p.main( frame )
	local args = frame:getParent().args
	local rows = {}
	local categories = {}
	local nocat = ( args.nocat and args.nocat ~= '' )

	for i = 1, #data do
		local concours = data[ i ]

		local edition = concours[ 'edition' ]
		local param = args[ 'wikiconcours ' .. edition ]

		if param and param ~= '' then
			rows[ #rows + 1 ] = row( concours, param )
			categories[ #categories + 1 ] = '[[Catégorie:Article Wikiconcours/' .. edition .. ']]'
		end
	end

	if #rows > 0 then
		return tableau( rows ) .. ( nocat and '' or table.concat( categories ) )
	else
		return ''
	end
end

function p.showcase( frame )
	local rows = {}

	for i = 1, #data do
		local concours = data[ i ]

		local param
		if concours[ 'edition' ] == '2006' then
			param = 'Exemple' -- Utilisateur:Exemple
		else
			param = '1' -- Équipe n° 1
		end

		rows[ #rows + 1 ] = row( concours, param )
	end

	return tableau( rows )
end

return p