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

« Module:Citation » : différence entre les versions

De ProleWiki
CriticalResist (discussion | contributions)
Page créée avec « local p = {} local function is_set(var) return not (var == nil or var == ''); end local function italics(var) return "<i>" .. var .. "</i>" end local function parenthesis(var) return "(" .. var .. ")" end function p.cite(frame) local pframe = frame:getParent() local Auteur = pframe.args.author local Annee = pframe.args.year or pframe.args['date'] local Chapitre = pframe.args.chapter local URLChapitre = pframe.args['chapter-url'] local Section = pfram... »
 
CriticalResist (discussion | contributions)
test 3
 
Ligne 1 : Ligne 1 :
local p = {}
local p = {}


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


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


local function parenthesis(var)
local function parentheses(var)
return "(" .. var .. ")"
return "(" .. var .. ")"
end
end
Ligne 15 : Ligne 15 :
function p.cite(frame)
function p.cite(frame)
local pframe = frame:getParent()
local pframe = frame:getParent()
local Auteur = pframe.args.author
local Auteur = pframe.args.auteur
local Annee = pframe.args.year or pframe.args['date']
local Annee = pframe.args['année'] or pframe.args['date']
local Chapitre = pframe.args.chapter
local Chapitre = pframe.args.chapitre
local URLChapitre = pframe.args['chapter-url']
local URLChapitre = pframe.args['url-chapitre']
local Section = pframe.args.section
local Section = pframe.args.section
local Titre = pframe.args.title
local Titre = pframe.args.titre
local URLTitre = pframe.args['title-url']
local URLTitre = pframe.args['url-titre']
local TitreBibliotheque = pframe.args['library-title']
local TitreBibliotheque = pframe.args['titre-bibliotheque']
local Volume = pframe.args.volume
local Volume = pframe.args.volume
local Serie = pframe.args.series or pframe.args.journal
local Serie = pframe.args['série'] or pframe.args.journal
local Traduction = pframe.args['trans-title']
local Traduction = pframe.args['titre-traduction']
local LangueTrad = pframe.args['trans-lang']
local LangueTrad = pframe.args['langue-traduction']
local Page = pframe.args.page or pframe.args.pages
local Page = pframe.args.page or pframe.args.pages
local PDF = pframe.args.pdf
local PDF = pframe.args.pdf
local Ville = pframe.args.city
local Ville = pframe.args.ville
local Editeur = pframe.args.publisher or pframe.args.via
local Editeur = pframe.args['éditeur'] or pframe.args.via
local ISBN = pframe.args.isbn or pframe.args.issn
local ISBN = pframe.args.isbn or pframe.args.issn
local ISSN = false
local ISSN = false
if is_set(pframe.args.issn) then
if est_defini(pframe.args.issn) then
ISSN = true
ISSN = true
end
end
Ligne 39 : Ligne 39 :
local LG = pframe.args.lg
local LG = pframe.args.lg
local MIA = pframe.args.mia
local MIA = pframe.args.mia
local Citation = pframe.args.quote
local Citation = pframe.args.citation
local Image = pframe.args.image
local Image = pframe.args.image
local LegendeImage = pframe.args['image-caption']
local LegendeImage = pframe.args['legende-image']
local SansPointFinal = pframe.args.dotless
local SansPointFinal = pframe.args.sans_point_final


local premiere_partie = ''


if is_set(Auteur) then
if est_defini(Auteur) then
if is_set(Annee) then
if est_defini(Annee) then
first_part = Auteur .. " " .. parenthesis(Annee) .. "."
premiere_partie = Auteur .. " " .. parentheses(Annee) .. "."
else
else
first_part = Auteur .. "."
premiere_partie = Auteur .. "."
end
end
else
first_part = ''
end
end


if is_set(Citation) then
if est_defini(Citation) then
Citation = string.gsub(Citation, "\n", "<br>")
Citation = string.gsub(Citation, "\n", "<br>")
Citation = "“" .. Citation .. "”"
Citation = "« " .. Citation .. " »"
local div = mw.html.create('div')
local div = mw.html.create('div')
div
div
Ligne 63 : Ligne 62 :
:wikitext(Citation)
:wikitext(Citation)
local br = mw.html.create('br', selfClosing)
local br = mw.html.create('br', selfClosing)
first_part = italics(tostring(div)) .. tostring(br) .. first_part
premiere_partie = italiques(tostring(div)) .. tostring(br) .. premiere_partie
end
end


if is_set(Image) then
if est_defini(Image) then
local span = mw.html.create('span')
local span = mw.html.create('span')
span
span
:wikitext('[[File:' .. Image .. '|center|300px|frameless]]')
:wikitext('[[Fichier:' .. Image .. '|center|300px|sans_cadre]]')


if is_set(LegendeImage) then
if est_defini(LegendeImage) then
local caption = mw.html.create('div')
local legende = mw.html.create('div')
caption
legende
:attr("style", "text-align:center;font-size:85%;")
:attr("style", "text-align:center;font-size:85%;")
:wikitext(LegendeImage)
:wikitext(LegendeImage)
first_part = tostring(span) .. tostring(caption) .. first_part
premiere_partie = tostring(span) .. tostring(legende) .. premiere_partie
else
else
first_part = tostring(span) .. first_part
premiere_partie = tostring(span) .. premiere_partie
end
end
end
end


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


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


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


if is_set(Traduction) then
if est_defini(Traduction) then
if is_set(LangueTrad) then
if est_defini(LangueTrad) then
deuxieme_partie = deuxieme_partie .. " " .. "(" .. LangueTrad .. ": " .. Traduction .. ")"
deuxieme_partie = deuxieme_partie .. " " .. "(" .. LangueTrad .. ": " .. Traduction .. ")"
else
else
deuxieme_partie = deuxieme_partie .. " " .. parenthesis(Traduction)
deuxieme_partie = deuxieme_partie .. " " .. parentheses(Traduction)
end
end
end
end
if is_set(Page) and not is_set(Volume) then
if est_defini(Page) and not est_defini(Volume) then
if tonumber(Page) ~= nil then
if tonumber(Page) ~= nil then
Page = "p." .. " " .. Page
Page = "p." .. " " .. Page
Ligne 130 : Ligne 128 :
Page = "pp." .. " " .. Page
Page = "pp." .. " " .. Page
end
end
deuxieme_partie = deuxieme_partie .. " " .. parenthesis(Page) .. "."
deuxieme_partie = deuxieme_partie .. " " .. parentheses(Page) .. "."
else
else
deuxieme_partie = deuxieme_partie .. "."
deuxieme_partie = deuxieme_partie .. "."
Ligne 136 : Ligne 134 :
end
end


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


if is_set(Page) and is_set(Volume) and is_set(Serie) then
if est_defini(Page) and est_defini(Volume) and est_defini(Serie) then
if tonumber(Page) ~= nil then
if tonumber(Page) ~= nil then
Page = "p." .. " " .. Page
Page = "p." .. " " .. Page
Ligne 147 : Ligne 145 :
Page = "pp." .. " " .. Page
Page = "pp." .. " " .. Page
end
end
deuxieme_partie = deuxieme_partie .. " " .. Serie .. " " .. parenthesis(Page) .. "."
deuxieme_partie = deuxieme_partie .. " " .. Serie .. " " .. parentheses(Page) .. "."
else
else
deuxieme_partie = deuxieme_partie .. " " .. Serie .. "."
deuxieme_partie = deuxieme_partie .. " " .. Serie .. "."
Ligne 153 : Ligne 151 :
end
end


if is_set(PDF) then
if est_defini(PDF) then
local span = mw.html.create('span')
local span = mw.html.create('span')
span
span
:attr('title', 'Telecharger en PDF')
:attr('title', 'Télécharger en PDF')
:addClass('plainlinks')
:addClass('plainlinks')
:tag('small')
:tag('small')
Ligne 163 : Ligne 161 :
end
end


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


if is_set(Ville) then
if est_defini(Ville) then
if is_set(Editeur) then
if est_defini(Editeur) then
troisieme_partie = Ville .. ": " .. Editeur .. "."
troisieme_partie = Ville .. ": " .. Editeur .. "."
else
else
Ligne 175 : Ligne 172 :
end
end


if not is_set(Ville) then
if not est_defini(Ville) then
if is_set(Editeur) then
if est_defini(Editeur) then
troisieme_partie = Editeur .. "."
troisieme_partie = Editeur .. "."
else
else
Ligne 183 : Ligne 180 :
end
end


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


if is_set(ISBN) then
if est_defini(ISBN) then
local span = mw.html.create('span')
local span = mw.html.create('span')
span
span
Ligne 205 : Ligne 201 :
end
end


if is_set(DOI) then
if est_defini(DOI) then
local doispan = mw.html.create('span')
local doispan = mw.html.create('span')
doispan
doispan
Ligne 220 : Ligne 216 :
end
end


if is_set(LG) then
if est_defini(LG) then
local span = mw.html.create('span')
local span = mw.html.create('span')
span
span
Ligne 230 : Ligne 226 :
end
end


if is_set(MIA) then
if est_defini(MIA) then
local span = mw.html.create('span')
local span = mw.html.create('span')
span
span
Ligne 240 : Ligne 236 :
end
end


 
if est_defini(deuxieme_partie) then
if is_set(deuxieme_partie) then
deuxieme_partie = " " .. deuxieme_partie
deuxieme_partie = " " .. deuxieme_partie
end
end


if is_set(troisieme_partie) then
if est_defini(troisieme_partie) then
troisieme_partie = " " .. troisieme_partie
troisieme_partie = " " .. troisieme_partie
end
end


if is_set(quatrieme_partie) then
if est_defini(quatrieme_partie) then
quatrieme_partie = " " .. quatrieme_partie
quatrieme_partie = " " .. quatrieme_partie
end
end


local rendu = first_part .. deuxieme_partie .. troisieme_partie .. quatrieme_partie
local rendu = premiere_partie .. deuxieme_partie .. troisieme_partie .. quatrieme_partie


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


Ligne 264 : Ligne 259 :
return rendu
return rendu
end
end
return p
return p

Dernière version du 15 novembre 2025 à 20:15

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