Chronos chronos left.png
Rusmed logo color.png
Chronos chronos right.png

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Différences entre les versions de « Module:Fo »

De Commission Historique
m
Balise : Révocation manuelle
 
(40 versions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
local p = {}
local p = {}
local bib = mw.ext.cargo.query('Zotero', '_pageName, ZoteroKey, TitleItem, Author, Editor, Date, Date__precision, Place, ItemType, Publisher, PublicationTitle, Volume, PublicationYear, Pages, Url, FilingDate, AccessDate, Type, Number, IssuingAuthority, Archive, Medium, Interviewer, AccessDate',{groupBy = 'ZoteroKey', orderBy = 'ZoteroKey', limit = 4000})
local bbib=mw.loadData( 'module:Fo/data' )
local bbib={}
 
for _,r in ipairs(bib) do
bbib[r['ZoteroKey']] = r
if r['Date__precision'] == '3' then
bbib[r['ZoteroKey']]['Date'] = mw.text.truncate(r['Date'],4,'')
end
end


local model = {
local model = {
Ligne 55 : Ligne 47 :
}
}


function modelRef (b,precision,field)
function p.tableRef(rr,refer) -- Place la référence Zref dans la table result dont les clefs sont les champs (ex. Nom, Prénom, Date de naissance...)(Ref[3]) et les valeurs des tables de tables contenant clef Zotero et précision.
local ref = mw.text.split(rr,'+')
if ref[3] then
if not refer[ref[3]] then refer[ref[3]] = '' end
refer[ref[3]] = refer[ref[3]] .. modelRef(ref[1],ref[2],ref[3])
end
end
 
function p.split2(frame)
local res,precision = '',''
local ref =  frame.args['ref']:gsub('(.-)%s*$','%1')
local precision = frame.args['precision']:gsub("[\n\r]","")
if #ref < 2 then
return ''
else
return modelRef(ref,precision,frame.args['field'])
end
end
 
function modelRef(ref,precision,field)
local content, pr = "", ""
local content, pr = "", ""
if #b.Author > 0 then
r = mw.text.truncate(ref,-8,'')
content = b.Author .. ". "
if bbib[r] then
else
b = bbib[r]
content = b.Editor .. "ed"
if #b.Author > 1 then
content = b.Author .. ". "
else
content = b.Editor .. "ed"
end
if #precision > 1 then
pr = ". " .. precision
end
content = content .. model[b["ItemType"]](b)
else
content = ref
end
end
if #precision > 0 then
local name = mw.hash.hashValue( 'sha1', content .. pr )
pr = ". " .. precision
end
content = content .. model[b["ItemType"]](b)
if field ~= "Publication" and field ~= "Reference" then
if field ~= "Publication" and field ~= "Reference" then
return '<ref name="' .. b.ZoteroKey .. precision .. '">' .. content .. pr .. '.</ref> '
return '<ref name="' .. name .. '">' .. content .. pr .. '.</ref>'
else
else
return "*" .. content .. pr .. "\n"
return "*" .. content .. pr .. "\n"
Ligne 74 : Ligne 93 :
end
end


 
function p.modelRefPub(rr)
function p.tableRef(Zref,result) -- Place la référence Zref dans la table result dont les clefs sont les champs (ex. Nom, Prénom, Date de naissance...)(Ref[3]) et les valeurs des tables de tables contenant clef Zotero et précision.
local ct, pr, r = '','', mw.text.truncate(rr[1],-8,'')
local Ref = mw.text.split(Zref,'+')
if bbib[r] then
local Zkey = mw.text.truncate(Ref[1],-8,'')
b = bbib[r]
if Ref[3] then
if #b.Author > 1 then
if not result[Ref[3]] then result[Ref[3]] = '' end
ct = string.gsub(b.Author,";"," ; ") .. ". "
precision = Ref[2] or ''
else
if bbib[Zkey] then  
ct = b.Editor .. "ed"
--result[Ref[3]] = result[Ref[3]] .. model[bbib[Zkey]["ItemType"]](bbib[Zkey],precision)
result[Ref[3]] = result[Ref[3]] .. modelRef(bbib[Zkey],precision,Ref[3])
end
end
if #rr[2] > 1 then
pr = ". " .. rr[2]
end
ct = ct .. model[b["ItemType"]](b)
else
ct = rr[1]
end
end
end
return "*" .. ct .. pr .. "\n"
end


function p.expandRef(refs,typeRef)
function p.modelRefNote(rr)
local result = ''
local ct, pr, r = '','', mw.text.truncate(rr[1],-8,'')
if refs then
if bbib[r] then
for _,ref in ipairs(refs) do
b = bbib[r]
if #ref['Note'] > 1 then
if #b.Author > 1 then
local Zkey = mw.text.truncate(ref['Note'],-8,'')
ct = string.gsub(b.Author,";"," ; ") .. ". "
if bbib[Zkey] then
else
local templ = 'ZoteroNote'
ct = b.Editor .. "ed"
if typeRef then templ = 'ZoteroPub' end
    bbib[Zkey]['Precisions'] = ref['Precisions'] or nil
result = result .. frame:expandTemplate{title = templ, args = bbib[Zkey]}
else
local note = ref['Note']
if #ref['Precisions'] > 1 then
note = note .. ', ' .. ref['Precisions']
end
if typeRef then
result = result .. '\n*' .. note
else
result = result .. frame:expandTemplate{title = 'Note', args = {note}}
end
end
end
end
end
if #rr[2] > 1 then
pr = ". " .. rr[2]
end
ct = ct .. model[b["ItemType"]](b)
else
ct = rr[1]
end
end
return result
local name = mw.hash.hashValue( 'sha1', ct .. pr )
return '<ref name="' .. name .. '">' .. ct .. pr .. '.</ref>'
end
end




function p.split(frame)
function p.split(frame)
if #frame.args['texte'] < 2 or string.sub(frame.args['texte'],1,3) == '[[:' then
local refer = ''
return ''
for _,rr in ipairs(mw.text.split(frame.args[1]:gsub("%s*#%s*","#"),'#')) do
refer = refer .. p.modelRefPub(mw.text.split(rr,'+'))
end
end
local texte,res,precision = '','',''
return refer
local texte_libre = mw.text.split(frame.args['texte'],'€€€')
end
if #texte_libre % 2 == 0 then
 
texte = '!!! ERREUR BALISES NOTES !!!\n\n'
function p.splitTextN(refs)
end
local refer = ''
for n, chunk in ipairs(texte_libre) do
if refs and #refs > 4 then
if (n % 2 == 0) then
for _,rr in ipairs(mw.text.split(refs:gsub("%s*#%s*","#"),'#')) do
local note = mw.text.split(chunk:gsub("[\n\r]",""),'£££')
if #rr > 4 then
local ref = mw.text.truncate(note[1],-8,'')
refer = refer .. p.modelRefNote(mw.text.split(rr,'+'))
local precision = ''
if #note > 1 then
precision = note[2]
end
if bbib[ref] then
--res = model[bbib[ref]["ItemType"]](bbib[ref],note[2])
res = modelRef(bbib[ref],precision,'')
else
local name = mw.text.truncate(note[1],50,'') .. precision
name = string.gsub(name, "%W",'_')
res = '<ref name="' .. name .. '">' .. note[1] .. ', ' .. precision .. '</ref> '
end
end
texte = texte .. res
else
texte = texte .. chunk
end
end
end
end
return texte
return refer
end
end


function p.ref(ref,precision)
function p.splitTextRP(refs)
local result = '<ref name="' .. ref .. precision .. '">' .. bbib[ref]["Author"] .. ', ' .. bbib[ref]["Editor"] .. pr .. '.</ref> '
local refer = ''
return result
if refs and #refs > 4 then
for _,rr in ipairs(mw.text.split(refs:gsub("%s*#%s*","#"),'#')) do
if #rr > 4 then
refer = refer .. p.modelRefPub(mw.text.split(rr,'+'))
end
end
end
return refer
end
end
return p
return p

Version actuelle datée du 25 mars 2022 à 16:08

La documentation pour ce module peut être créée à Module:Fo/doc

local p = {}
local bbib=mw.loadData( 'module:Fo/data' )

local model = {
	["book"] = function (b) 
		return b.TitleItem .. ". " .. b.Place .. " : " .. b.Publisher .. ", " .. mw.text.truncate(b.PublicationYear,4,'')
	end,
	["bookSection"] = function (b) 
		return b.TitleItem .. ". In:" .. b.PublicationTitle .. ", " .. b.Editor .. ", " .. b.Pages .. ". " .. b.Place .. " : " .. b.Publisher .. ", " .. mw.text.truncate(b.PublicationYear,4,'')
	end,
	["journalArticle"] = function (b) 
		return b.TitleItem .. ". " .. b.PublicationTitle .. " " .. b.Volume .. " (" ..  mw.text.truncate(b.PublicationYear,4,'') .. ") : " .. b.Pages
	end,
	["thesis"] = function (b) 
		return b.TitleItem .. ". " .. b.Type .. ". " .. b.Place .. ", " .. mw.text.truncate(b.PublicationYear,4,'')
	end,
	["magazineArticle"] = function (b) 
		return b.TitleItem .. ". " .. b.PublicationTitle .. ". " .. b.Date
	end,	
	["patent"] = function (b) 
		return b.TitleItem .. ". " .. b.IssuingAuthority .. " " .. b.Number .. ", " .. "{{int:Template-depose_le}} " .. b.FilingDate .. " {{int:Template-et_accorde_le}} " .. b.Date
	end,	
	["encyclopediaArticle"] = function (b) 
		return b.TitleItem .. ". In:" .. b.PublicationTitle .. ". " .. b.Publisher .. ", " .. mw.text.truncate(b.PublicationYear,4,'') .. ". " .. b.Url
	end,
	["report"] = function (b) 
		return b.TitleItem .. ". " .. b.ItemType .. " " .. b.Number .. ". " .. b.Place .. " : " .. b.Publisher .. ", "   .. mw.text.truncate(b.PublicationYear,4,'') .. ". " .. b.Url
	end,
	["interview"] = function (b) 
		return b.TitleItem .. ", {{int:Template-entretien_realise_par}}" .. b.Interviewer .. ". " .. b.Medium .. ", "   .. b.Date .. ". " .. b.Archive .. ". " .. b.Url
	end,
	["videoRecording"] = function (b) 
		return b.TitleItem .. ". " .. b.Place .. " : " .. b.Publisher .. ", " .. b.Date .. ". " .. b.Url .. ", {{int:Template-Page_consulte_le}}" .. b.AccessDate
	end,
	["presentation"] = function (b) 
		return b.TitleItem .. ". " .. b.Place .. ", " .. b.Date
	end,
	["newspaperArticle"] = function (b) 
		return b.TitleItem .. ". " .. b.PublicationTitle .. ", " .. b.Date .. ". " .. b.Url .. ", {{int:Template-Page_consulte_le}}" .. b.AccessDate
	end,
	["webpage"] = function (b) 
		return b.TitleItem .. ". " .. b.PublicationTitle .. ", " .. b.Date .. ". " .. b.Url .. ", {{int:Template-Page_consulte_le}}" .. b.AccessDate
	end,
	["blogPost"] = function (b) 
		return b.TitleItem .. ". " .. b.PublicationTitle .. ", " .. b.Date .. ". " .. b.Url .. ", {{int:Template-Page_consulte_le}}" .. b.AccessDate
	end,	
}

function p.tableRef(rr,refer) -- Place la référence Zref dans la table result dont les clefs sont les champs (ex. Nom, Prénom, Date de naissance...)(Ref[3]) et les valeurs des tables de tables contenant clef Zotero et précision.
	local ref = mw.text.split(rr,'+')
	if ref[3] then
		if not refer[ref[3]] then refer[ref[3]] = '' end
		refer[ref[3]] = refer[ref[3]] .. modelRef(ref[1],ref[2],ref[3])
	end
end	

function p.split2(frame)
	local res,precision = '',''
	local ref =  frame.args['ref']:gsub('(.-)%s*$','%1')
	local precision = frame.args['precision']:gsub("[\n\r]","")
	
	if #ref < 2 then
		return ''
	else
		return modelRef(ref,precision,frame.args['field'])
	
	end
end

function modelRef(ref,precision,field)
	local content, pr = "", ""
	r = mw.text.truncate(ref,-8,'')
	if bbib[r] then
		b = bbib[r]
		if #b.Author > 1 then
			content = b.Author .. ". "
		else
			content = b.Editor .. "ed"
		end
		if #precision > 1 then
			pr = ". " .. precision
		end		
		content = content .. model[b["ItemType"]](b)
	else 
		content = ref
	end
	local name = mw.hash.hashValue( 'sha1', content .. pr )
	if field ~= "Publication" and field ~= "Reference" then
		return '<ref name="' .. name .. '">' .. content .. pr .. '.</ref>'
	else
		return "*" .. content .. pr .. "\n"	
	end		
end

function p.modelRefPub(rr)
	local ct, pr, r = '','', mw.text.truncate(rr[1],-8,'')
	if bbib[r] then
		b = bbib[r]
		if #b.Author > 1 then
			ct = string.gsub(b.Author,";"," ; ") .. ". "
		else
			ct = b.Editor .. "ed"
		end
		if #rr[2] > 1 then
			pr = ". " .. rr[2]
		end		
		ct = ct .. model[b["ItemType"]](b)
	else 
		ct = rr[1]
	end
	return "*" .. ct .. pr .. "\n"
end

function p.modelRefNote(rr)
	local ct, pr, r = '','', mw.text.truncate(rr[1],-8,'')
	if bbib[r] then
		b = bbib[r]
		if #b.Author > 1 then
			ct = string.gsub(b.Author,";"," ; ") .. ". "
		else
			ct = b.Editor .. "ed"
		end
		if #rr[2] > 1 then
			pr = ". " .. rr[2]
		end		
		ct = ct .. model[b["ItemType"]](b)
	else 
		ct = rr[1]
	end
	local name = mw.hash.hashValue( 'sha1', ct .. pr )
	return '<ref name="' .. name .. '">' .. ct .. pr .. '.</ref>'
end


function p.split(frame)
	local refer = ''
	for _,rr in ipairs(mw.text.split(frame.args[1]:gsub("%s*#%s*","#"),'#')) do
		refer = refer .. p.modelRefPub(mw.text.split(rr,'+'))
	end
	return refer
end

function p.splitTextN(refs)
	local refer = ''
	if refs and #refs > 4 then
		for _,rr in ipairs(mw.text.split(refs:gsub("%s*#%s*","#"),'#')) do
			if #rr > 4 then
				refer = refer .. p.modelRefNote(mw.text.split(rr,'+'))
			end
		end
	end
	return refer
end

function p.splitTextRP(refs)
	local refer = ''
	if refs and #refs > 4 then
		for _,rr in ipairs(mw.text.split(refs:gsub("%s*#%s*","#"),'#')) do
			if #rr > 4 then
				refer = refer .. p.modelRefPub(mw.text.split(rr,'+'))
			end
		end
	end
	return refer
end
return p