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

Module:Citation

De ProleWiki
local p = {}

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

local function italiques(var)
	return "<i>" .. var .. "</i>"
end

local function parentheses(var)
	return "(" .. var .. ")"
end

function p.cite(frame)
	local pframe = frame:getParent()
	local Auteur = pframe.args.auteur
	local Annee = pframe.args['année'] or pframe.args['date']
	local Chapitre = pframe.args.chapitre
	local URLChapitre = pframe.args['url-chapitre']
	local Section = pframe.args.section
	local Titre = pframe.args.titre
	local URLTitre = pframe.args['url-titre']
	local TitreBibliotheque = pframe.args['titre-bibliotheque']
	local Volume = pframe.args.volume
	local Serie = pframe.args['série'] or pframe.args.journal
	local Traduction = pframe.args['titre-traduction']
	local LangueTrad = pframe.args['langue-traduction']
	local Page = pframe.args.page or pframe.args.pages
	local PDF = pframe.args.pdf
	local Ville = pframe.args.ville
	local Editeur = pframe.args['éditeur'] or pframe.args.via
	local ISBN = pframe.args.isbn or pframe.args.issn
	local ISSN = false
	if est_defini(pframe.args.issn) then
		ISSN = true
	end
	local DOI = pframe.args.doi
	local LG = pframe.args.lg
	local MIA = pframe.args.mia
	local Citation = pframe.args.citation
	local Image = pframe.args.image
	local LegendeImage = pframe.args['legende-image']
	local SansPointFinal = pframe.args.sans_point_final

	local premiere_partie = ''

	if est_defini(Auteur) then
		if est_defini(Annee) then
			premiere_partie = Auteur .. " " .. parentheses(Annee) .. "."
		else
			premiere_partie = Auteur .. "."
		end
	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(Image) then
		local span = mw.html.create('span')
		span
			:wikitext('[[Fichier:' .. Image .. '|center|300px|sans_cadre]]')

		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

	-- deuxième partie: Titre(URL), Série, Volume, URLChapitre, Année, Page, Traduction(Langue), PDF
	local deuxieme_partie = ''

	if est_defini(Titre) then
		if est_defini(URLTitre) then
			Titre = "[" .. URLTitre .. " " .. Titre .. "]"
		else
			if est_defini(TitreBibliotheque) then
				Titre = "[[Bibliothèque:" .. TitreBibliotheque .. "|" .. Titre .. "]]"
			end
		end
		Titre = italiques(Titre)
		if not est_defini(Serie) then
			if est_defini(Volume) then
				Titre = Titre .. ", vol. " .. Volume
			end
		end
		deuxieme_partie = Titre
		if est_defini(Chapitre) then
			if est_defini(URLChapitre) then
				Chapitre = "[" .. URLChapitre .. " " .. Chapitre .. "]"
			end
			if est_defini(Section) then
				Chapitre = Chapitre .. "; " .. Section
			end
			deuxieme_partie = deuxieme_partie .. ": " .. "'" .. Chapitre .. "'"
		end

		if not est_defini(Auteur) then
			if est_defini(Annee) then
				deuxieme_partie = deuxieme_partie .. " " .. parentheses(Annee)
			end
		end

		if est_defini(Traduction) then
			if est_defini(LangueTrad) then
				deuxieme_partie = deuxieme_partie .. " " .. "(" .. LangueTrad .. ": " .. Traduction .. ")"
			else
				deuxieme_partie = deuxieme_partie .. " " .. parentheses(Traduction)
			end
		end
		if est_defini(Page) and not est_defini(Volume) then
			if tonumber(Page) ~= nil then
				Page = "p." .. " " .. Page
			else
				Page = "pp." .. " " .. Page
			end
			deuxieme_partie = deuxieme_partie .. " " .. parentheses(Page) .. "."
		else
			deuxieme_partie = deuxieme_partie .. "."
		end
	end

	if est_defini(Serie) then
		if est_defini(Volume) then
			Serie = Serie .. ", vol." .. Volume
		end

		if est_defini(Page) and est_defini(Volume) and est_defini(Serie) then
			if tonumber(Page) ~= nil then
				Page = "p." .. " " .. Page
			else
				Page = "pp." .. " " .. Page
			end
			deuxieme_partie = deuxieme_partie .. " " .. Serie .. " " .. parentheses(Page) .. "."
		else
			deuxieme_partie = deuxieme_partie .. " " .. Serie .. "."
		end
	end

	if est_defini(PDF) then
		local span = mw.html.create('span')
		span
			:attr('title', 'Télécharger en PDF')
			:addClass('plainlinks')
			:tag('small')
			:wikitext('[' .. PDF .. " " .. mw.text.nowiki('[PDF]') .. ']')
		deuxieme_partie = deuxieme_partie .. " " .. tostring(span)
	end

	-- troisième partie: Ville, Éditeur
	local troisieme_partie = ''

	if est_defini(Ville) then
		if est_defini(Editeur) then
			troisieme_partie = Ville .. ": " .. Editeur .. "."
		else
			troisieme_partie = Ville .. "."
		end
	end

	if not est_defini(Ville) then
		if est_defini(Editeur) then
			troisieme_partie = Editeur .. "."
		else
			troisieme_partie = ''
		end
	end

	-- quatrième partie: ISBN, DOI, Library Genesis, Marxists Internet Archive
	local quatrieme_partie = ''

	if est_defini(ISBN) then
		local span = mw.html.create('span')
		span
			:addClass('plainlinks')
		if (ISSN) then
			span
				:tag('small')
				:attr('title', 'Portail ISSN')
				:wikitext('[' .. "https://portal.issn.org/resource/ISSN/" .. ISBN .. " " .. "ISSN " .. ISBN .. ']')
		else
			span
				:tag('small')
				:attr('title', 'WorldCat')
				:wikitext('[' .. "https://www.worldcat.org/search?qt=worldcat_org_all&q=" .. ISBN .. " " .. "ISBN " .. ISBN .. ']')
		end
		quatrieme_partie = quatrieme_partie .. tostring(span)
	end

	if est_defini(DOI) then
		local doispan = mw.html.create('span')
		doispan
			:tag('small')
			:wikitext("doi: " .. DOI)
		quatrieme_partie = quatrieme_partie .. " " .. tostring(doispan)
		local span = mw.html.create('span')
		span
			:attr('title', 'Lien Sci-Hub')
			:addClass('plainlinks')
			:tag('small')
			:wikitext('[' .. "https://sci-hub.se/" .. DOI .. " " .. mw.text.nowiki('[HUB]') .. ']')
		quatrieme_partie = quatrieme_partie .. " " .. tostring(span)
	end

	if est_defini(LG) then
		local span = mw.html.create('span')
		span
			:attr('title', 'Lien Library Genesis')
			:addClass('plainlinks')
			:tag('small')
			:wikitext('[' .. LG .. " " .. mw.text.nowiki('[LG]') .. ']')
		quatrieme_partie = quatrieme_partie .. " " .. tostring(span)
	end

	if est_defini(MIA) then
		local span = mw.html.create('span')
		span
			:attr('title', 'Lien Marxists Internet Archive')
			:addClass('plainlinks')
			:tag('small')
			:wikitext('[' .. MIA .. " " .. mw.text.nowiki('[MIA]') .. ']')
		quatrieme_partie = quatrieme_partie .. " " .. tostring(span)
	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

	-- supprimer les espaces au début et à la fin
	rendu = string.gsub(rendu, "^%s*(.-)%s*$", "%1")

	if SansPointFinal then
		rendu = rendu:sub(1, -2)
	end

	return rendu
end

return p