Aller au contenu

Module:UICN

Une page de Wikipédia, l'encyclopédie libre.

 Documentation[créer] [purger]
require('strict')
local uicn = {}
local Outils = require( 'Module:Outils' )
local Commun = require( 'Module:Biblio/Commun' )

local function formatLienListeRouge( frame )
	local args = Outils.extractArgs( frame )
	local validArg = function ( ... ) return Commun.validTextArg( args, ... ) end
	local argsWrapper = {} -- Tableau wrapper, contient les arguments pour Biblio/Lien web après vérifications
	local verif = {} -- Tableau de contrôle
	
	-- Langue
	argsWrapper['langue'] = 'en'
	
	-- Liste des assesseurs
	local assesseur = validArg( 'assesseur', 'assesseurs' )
	if assesseur then
		if validArg( 'assesseurs' ) then
			argsWrapper['auteurs'] = args['assesseurs']
		else
			argsWrapper['auteur'] = args['assesseur']
		end
	end
	
	-- Date
	local date = validArg( 'année' )
	if date then
		argsWrapper['année'] = date
	end
	
	-- Titre pour Biblio/Lien web
	local taxon = validArg( 'taxon' )
	if taxon then
		argsWrapper['titre'] = "''" .. taxon .. "''"
	else
		verif.taxon = true
	end
	
	-- Lien
	local id = validArg( 'id' )
	local evaluation = validArg( 'évaluation' )
	if id and evaluation then 
		argsWrapper['url'] = 'https://www.iucnredlist.org/species/' .. id .. '/' .. evaluation
	elseif taxon then
		argsWrapper['url'] = 'http://apiv3.iucnredlist.org/api/v3/website/' .. taxon
	end
	
	-- Site
	argsWrapper['site'] = "''la ''[[liste rouge de l'UICN]]"
	
	-- DOI
	local doi = validArg( 'doi' )
	if doi then
		argsWrapper['doi'] = doi
	end
	
	-- Consulté le
	local consulte = validArg( 'consulté le' )
	if consulte then
		argsWrapper['consulté le'] = consulte
	end
	
	if not verif.taxon then
		local Ouvrage = require( 'Module:Biblio/Lien web' )
		return Ouvrage.lienWeb( argsWrapper ) 
	else
		local TableBuilder = require( 'Module:TableBuilder' )
		local erreur = TableBuilder.new()
		local absent = { }
		
		if verif.taxon then
			table.insert( absent, '« <code>taxon</code> »' )
		end
		
		erreur.insert( 1, '<span class="error">Modèle UICN : paramètre'
			.. ( #absent > 1 and 's ' or ' ' )
			.. mw.text.listToText( absent ) .. ' manquant' .. ( #absent > 1 and 's' or '' )
			.. '.&ensp;</span>'
		)
		
		return erreur.concat()
	end
	
end

function uicn.main( frame )
	return formatLienListeRouge( frame ) 
end

return uicn