Basculer le menu
Basculer le menu personnel
Non connecté(e)
Votre adresse IP sera visible au public si vous faites des modifications.

Module:Citation web

De ProleWiki
local p = {}

local function est_defini (var)
	return not (var == nil or var == '')
end

local function italiques (var)
	return "''" .. var .. "''"
end

function p.cite( frame )
	local pframe = frame:getParent()

	local Auteur = pframe.args.auteur
	if est_defini (pframe.args.journaliste) then
		Auteur = pframe.args.journaliste
	end
	local Date = pframe.args['date']
	local Titre = pframe.args.titre
	local URL = pframe.args.url
	local Site = pframe.args.journal or pframe.args.site
	local URLArchive = pframe.args['archive-url']
	local DateArchive = pframe.args['archive-date']
	local Recupere = pframe.args.recupere
	local Citation = pframe.args.citation
	local Image = pframe.args.image
	local LegendeImage = pframe.args['legende-image']
	
	local premiere_partie = ""
	
	if est_defini (Auteur) then
		if est_defini (Date) then
			premiere_partie = Auteur .. " (" .. Date .. ")."
		else
			premiere_partie = Auteur .. "."
		end
	end
	
	if est_defini (Image) then
		local span = mw.html.create ( 'span' )
		span
		:wikitext('[[Fichier:' .. Image .. '|center|300px|sans_cadre]]')
		local br = mw.html.create ('br', selfClosing)

		if est_defini(LegendeImage) then 
			local legende = mw.html.create ('div')
			legende
			:attr("style", "text-align:center;font-size:85%;")
			:wikitext(LegendeImage)
			premiere_partie = tostring(span) .. tostring(legende) .. premiere_partie
		else
			premiere_partie = tostring(span) .. premiere_partie
		end
	end
	
	local deuxieme_partie = ""
	
	if est_defini (Titre) then
		if est_defini (URL) then
			Titre = "[" .. URL .. " " .. "\"" .. Titre .. "\"" .. "]"
		end
		if not est_defini (Auteur) then
			if est_defini (Date) then
				Titre = Titre .. " (" .. Date .. ")."
			else
				Titre = Titre .. "."
			end
		end
		deuxieme_partie = Titre
	end
	
	local troisieme_partie = ""
	
	if est_defini(Site) then
		troisieme_partie = "''" .. Site .. "''."
	end
		
	local quatrieme_partie = ""
	
	if est_defini(URLArchive) then
		if est_defini(DateArchive) then
			quatrieme_partie = "[" .. URLArchive .. " " .. "Archivé" .. "]" .. " " .. "depuis l'original le" .. " " .. DateArchive .. "."
		else
			quatrieme_partie = "[" .. URLArchive .. " " .. "Archivé" .. "]" .. " depuis l'original."
		end
	end
			
	local cinquieme_partie = ""
	
	if est_defini (Recupere) then
		cinquieme_partie = "Récupéré le" .. " " .. Recupere .. "."
	end
		
	if est_defini (Citation) then
		Citation = string.gsub(Citation,"\n","<br>")
		Citation = "« " .. Citation .. " »"
		local div = mw.html.create ('div')
		div
		:attr("style", "width:80%; margin-left:10%;")
		:wikitext(Citation)
		local br = mw.html.create ('br', selfClosing)
		premiere_partie = italiques(tostring(div)) .. tostring(br) .. premiere_partie
	end

	if est_defini (premiere_partie) then
		premiere_partie = premiere_partie .. " "
	end
	
	if est_defini (deuxieme_partie) then
		deuxieme_partie = deuxieme_partie .. " "
	end
	
	if est_defini (troisieme_partie) then
		troisieme_partie = troisieme_partie .. " "
	end
	
	if est_defini (quatrieme_partie) then
		quatrieme_partie = quatrieme_partie .. " "
	end
	
	local Rendu = premiere_partie .. deuxieme_partie .. troisieme_partie .. quatrieme_partie .. cinquieme_partie
	
	return Rendu
end

return p