Module:Sourdant

Èn årtike di Wiccionaire.
Sauter à la navigation Sauter à la recherche
I gn a nén co di dzo-pådje /doc pol notule d' esplikêyes. Clitchîz cial po l' ahiver.
-- get informations about a reference
-- for infobox take a look at Module:Sourdant/infoboesse
 
local p = {}
local builder = require("Module:Builder")

-- return the table of a reference
-- or false if reference doesn't exist
function p.get_reference(refID)	
	local ref = builder.load_data("Sourdant/" .. refID)
	
	if not ref then	return false end
	
	-- follow alias : FR13 -> R13
	-- redirecting is not yet available for module
	if ref.alias ~= nil then
		ref = p.get_reference(ref.alias)
	end
	
	-- if sourdant author is an ID, get informations about the author
	-- LM -> Lucien Mahin
	if ref.id_author ~= nil then
		-- because ref is a read only table
		-- we need to make an editable copy
		local data = setmetatable( {}, { __index = ref });
		local a = p.get_reference(ref.id_author)
		if a then
			if a.authors ~= nil then
				data.authors = a.authors
			elseif a.author ~= nil then
				data.author = a.author
				if a.alt_author ~= nil then
					data.alt_author = a.alt_author
				end
			end
		end
		return data
	end
	
	return ref
end

-- return a reference as wikicode (author, title)
function p.get_text(frame)	
	local args = frame.args
	local refID = args[1]
	
	local ref = p.get_reference(refID)
	local text = ""
	local aid = nil
	local aname = nil
	if ref then
		-- 'name' param. overwrite all : author, title, year,...
		-- eg. Motî Haust (not Jean Haust, Dictionnaire liégeois, 1933,...)
		if ref.name and ref.name ~= "" then
			text = text .. "[[Sourdant:" .. refID .."|" .. ref.name .. "]]"
		else
			-- template {{s|oteur=}}
			if args.author and args.author ~= "" then
				aname = p.get_reference(args.author)
				if aname then
					text = text .. "[[Sourdant:" .. args.author .."|" .. aname.alt_author .. "]]"
				else
					text = text .. args.author
				end
			elseif ref.authors and ref.authors ~= "" then
				if ref.alt_authors and ref.alt_authors ~= "" then
					text = text .. ref.alt_authors
				else
					text = text .. ref.authors
				end
			else
				if ref.id_author then
					aid = ref.id_author
				else
					aid = refID
				end
				if ref.alt_author and ref.alt_author ~= "" then
					aname = ref.alt_author
				else
					aname = ref.author
				end
				
				if aname ~= nil and aname ~= "" then
					local author_page = mw.title.makeTitle("Sourdant", aid)
					if author_page.exists then
						text = text .. "[[Sourdant:" .. aid .."|" .. aname .. "]]" 
					end
				end
			end
		
			if ref.title and ref.title ~= "" then
				if text ~= "" then text = text .. ', ' end
				text = text .. "''[[Sourdant:" .. refID .."|" .. ref.title .. "]]''"
			end
		end
	else
		text = refID
	end
	
	text = frame:newParserValue(text).expand()
	if args[2] ~= nil and args[2] ~= "" then
		text = text .. ", " .. args[2]
	end
		
	if(args.ritch ~= nil and args.ritch ~= "0") then
		if args.ritch ~= "" then
			text = text .. " (fråze "
			if args.ritch == "rarindjeye" then
				text = text .. "rarindjeye"
			elseif args.ritch == "rif" then
				text = text .. "rifondowe"
			elseif args.ritch == "rif+" then
				text = text .. "rifondowe et recråxheye"
			elseif args.ritch == "rif~" then
				text = text .. "rifondowe et rarindjeye"
			end
			text = text .. ")"
		end
		text = '<span class="sourdant">— '..text..'.</span>'
	end
	
	return text
end

return p