Garçon devant un ordinateur.jpg
Hollie Little Pink Laptop.jpg
À propos • Aide • Le Livre d'or
Les lecteurs de Vikidia demandent des articles en plus. Voyez la liste d'articles à créer, et venez nous aider à les rédiger !
Cette page est protégée.

Module:Ébauche

Aller à la navigation Aller à la recherche
 Documentation[créer] [purger]
local p = {}

--
-- création des bandeaux d'ébauche
--

local function ebauche( couleur_fond,
                        couleur_bord,
                        couleur_info,
                        image,
                        taille_image,
                        type_page,
                        accord,
                        domaine,
                        categorie )
	local code

	-- crée le contenant de l'icône
	local code_icone
	if (image) then
		code = [=[<div class="nomobile" style="vertical-align:middle; text-align:center; display:table-cell;">[[Fichier:%s|%spx|alt=|link=|class=noviewer]]</div>]=]
		code_icone = code:format( image, taille_image or '20' )
	else
		code_icone = ''
	end

	-- crée la première ligne du texte
	code = [=[%s est [[Aide:article à compléter|à compléter]].]=]
	local code_info1 = code:format( type_page or 'Cet article' )
	if (domaine) then
		code = [=[ Il concerne %s.]=]
		code_info1 = code_info1 .. code:format( domaine )
	end

	-- crée la deuxième ligne du texte
	code = [=[''[%s Améliore-%s] ! <small>([[Aide:Article à compléter|Aide]])</small>'']=]
	local code_info2
	code_info2 = code:format( mw.title.getCurrentTitle():canonicalUrl{ action = 'edit' }, accord or 'le' )

	-- crée le modèle
	code = [=[<center><div class="bandeau plainlinks" style="text-align:center; clear:both; border:2px solid %s; color:%s; border-radius:4px 18px 18px 4px; font-size:85%%; display:table; padding-right:0.4em; background-color:%s;"><div style="display:table-row;">%s<div style="text-align:center; display:table-cell;">%s<br />%s</div></div></div></center>
]=]
	local html = mw.html.create()
	html:wikitext( code:format( couleur_bord or 'transparent',
	                            couleur_info or couleur_bord or '#94A67E',
	                            couleur_fond or 'transparent',
	                            code_icone, code_info1, code_info2 ))

	-- ajoute des catégories
	if (categorie ~= '') then
		code = "[[Catégorie:%s]]"
		html:wikitext( code:format( categorie ))
	end
	return tostring( html )
end

function p.Ebauche( frame )
	local categorie = frame.args['catégorie']
	local html = ebauche( frame.args['couleur fond'],
	                      frame.args['couleur bord'],
	                      frame.args['couleur info'],
	                      frame.args['image'],
	                      frame.args['taille image'],
	                      frame.args['type page'],
	                      frame.args['accord'],
	                      frame.args['domaine'],
	                      (not frame:getParent().args['nocat'] or frame:getParent().args['nocat'] == '')
	                       and categorie ~= ''
	                       and categorie
	                       or '' )
	return tostring( html )
end

--
-- Création de bandeaux spécifiques
--

function p.ebaucheDefaut( categ )
	return tostring( ebauche( 'white',
	                          '#CBFF89',
	                          '#053E2B',
	                          'Ébauche vik.svg',
	                          '35',
	                          nil,
	                          nil,
	                          nil,
	                          categ and 'Ébauche' or '' ))
end

--
-- Création du bandeau de haut d'article
--

function p.obtenirEbauche_private( frame, titre )
	return frame:expandTemplate{ title = 'Ébauche ' .. titre, args = { nocat = frame:getParent().args['nocat'] } }
end
function p.obtenirEbauche( frame, titre )
	local test, ebauche = pcall( p.obtenirEbauche_private, frame, titre )
	if test == true then
		return ebauche
	elseif titre == '' then
		return p.ebaucheDefaut( not frame:getParent().args['nocat'] )
	else
		local ret = "[[Modèle:Ébauche " .. titre .. "]]"
		if (not frame:getParent().args['nocat']) then
			ret = ret .. "[[Catégorie:Ébauche inexistante]]"
		end
		return ret
	end
end

function p.duoEbauche( frame, titre1, titre2 )
	local code = [=[<p>
{| class="multi-bandeau" style="width: 100%%; clear: both; margin: 0; background-color: transparent; padding: 0;"
|- style="vertical-align: middle;"
| style="width: 50%%;" | %s
| style="width: 5; padding-left:8px" |
| style="width: 50%%;" | %s
|}]=]
	return code:format( tostring( p.obtenirEbauche( frame, titre1 )), tostring( p.obtenirEbauche( frame, titre2 )))
end

function p.Ebauches( frame )
	local args = frame:getParent().args

	-- pas de paramètre
	if (not args[1]) then
		return p.ebaucheDefaut( not args['nocat'] )
	end

	-- un paramètre
	if (not args[2]) then
		return p.obtenirEbauche( frame, args[1] )
	end

	-- deux paramètres
	local ligne1 = p.duoEbauche( frame, args[1], args[2] )
	if (not args[3]) then
		return tostring( ligne1 )
	end

	-- plein de paramètres
	if (not args[4]) then
		return tostring( ligne1 .. tostring( p.obtenirEbauche( frame, args[3] )))
	end
	return tostring( ligne1 .. tostring( p.duoEbauche( frame, args[3], args[4] )))
end

return p