Communauté  • Livre d'or
Chats noirs.jpg Actualités, astuces, interview... Venez lire la gazette de ce printemps de Vikidia ! DessinInterview.png
Cette page est protégée.

Module:Bandeau petit

Aller à la navigation Aller à la recherche
 Documentation[modifier] [purger]

Le module : Bandeau petit sert à créer les modèles de la catégorie : Modèle bandeau de section :

et ceux de la catégorie : Modèle bandeau d'entête :

Deux fonctions locales génèrent le code des modèles :

  • bandeauSection pour les bandeaux de section ;
  • bandeauEntete pour les bandeaux d’entête ;

mais les deux codes sont en réalité très proches et pourraient potentiellement être fusionnés.

Une fonction sert l’appel depuis d’autres modules, utilisée pour le moment pour le module : Super article pour le modèle : Super article mini :

  • bandeauSection.
local p = {}

--
-- fonctions principales
--

-- <div class="bandeau-section"><i class="italique (1) (4)" style="text-indent:(2);"}}>(3)</i></div>
local function bandeauSection( icone, blanc, texte, class )
	local html = mw.html.create( 'div' )

	html:addClass( 'bandeau-section' )
	    :tag( 'i' ):addClass( 'italique' )
	               :addClass( icone )
	               :addClass( class )
	               :css( 'text-indent', blanc )
	               :wikitext( texte )
	return html
end

-- <div class="bandeau-entete (3?:sans-ligne)"><i class="italique (1)" style="text-indent:1.8em;"}}>(2)</i></div>
local function bandeauEntete( icone, texte, ligne )
	local html = mw.html.create( 'div' )

	local sans_ligne
	if ligne then
		sans_ligne = nil
	else
		sans_ligne = 'sans-ligne'
	end

	html:addClass( 'bandeau-entete' )
	    :addClass( sans_ligne )
	    :tag( 'i' ):addClass( 'italique' )
	               :addClass( icone )
	               :css( 'text-indent', '1.8em' )
	               :wikitext( texte )
	return html
end

function p.bandeauEntete( canari, icone, texte, ligne )
	if canari ~= nil then
		error( 'la fonction « BandeauEntete » ne doit pas être utilisée depuis un modèle' )
	end

	return tostring( bandeauEntete( icone, texte, ligne ))
end

--
-- bandeaux personnalisés
--

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

	local icone = args['icône'] ~= '' and args['icône'] or
	              args['icone'] ~= '' and args['icone'] or 'loupe'
	local texte = args[1]       ~= '' and args[1]       or
	              args['texte'] ~= '' and args['texte'] or 'Texte à remplacer.'
	local class = args['class'] ~= '' and args['class'] or nil

	local blanc
	if icone == 'en-savoir-plus' then
		blanc = '2.4em'
	elseif icone == 'en-travaux' then
		blanc = '2.5em'
	elseif icone == 'fusionner' or
	       icone == 'scinder' then
		blanc = '2.8em'
	else
		blanc = '1.8em'
	end

	return tostring( bandeauSection( icone, blanc, texte, class ))
end

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

	local icone = args['icône'] ~= '' and args['icône'] or
	              args['icone'] ~= '' and args['icone'] or 'homonymie'
	local texte = args[1]       ~= '' and args[1]       or
	              args['texte'] ~= '' and args['texte'] or 'Texte à remplacer.'

	return tostring( bandeauEntete( icone, texte, not args['sans ligne'] ))
end

--
-- bandeaux de section
--

function p.ACompleter( frame )
	local phrase = [=[Cette section est vide, pas assez détaillée ou incomplète. <span class="plainlinks">[%s '''Améliore-la !''']</span>]=]
	local action = mw.title.getCurrentTitle():canonicalUrl{ action = 'edit' }

	phrase = phrase:format( action )

	return tostring( bandeauSection( 'en-travaux', '2.5em', phrase ))
end

function p.ArticleACreer( frame )
	local lien = require('Module:Multiparamètres').lien

	local nombre, phrase = lien( frame:getParent().args, true )
	assert( nombre ~= 0, 'Au moins une page doit être précisée !' )

	if (nombre == 1) then
		phrase = 'Article à créer : ' .. phrase .. '.'
	else
		phrase = 'Articles à créer : ' .. phrase .. '.'
	end

	return tostring( bandeauSection( 'redaction', '1.8em', phrase ))
end

function p.ArticleALire( frame )
	local lien = require('Module:Multiparamètres').lien

	local nombre, phrase = lien( frame:getParent().args, true )
	assert( nombre ~= 0, 'Au moins une page doit être précisée !' )

	if (nombre == 1) then
		phrase = 'Article à lire : ' .. phrase .. '.'
	else
		phrase = 'Articles à lire : ' .. phrase .. '.'
	end

	return tostring( bandeauSection( 'loupe', '1.8em', phrase ))
end

function p.EnSavoirPlus( frame )
	local lien = require('Module:Multiparamètres').lien

	local nombre, phrase = lien( frame:getParent().args, true )
	assert( nombre ~= 0, 'Au moins une page doit être précisée !' )

	if (nombre == 1) then
		phrase = 'Pour en savoir plus, lis l’article : ' .. phrase .. '.'
	else
		phrase = 'Pour en savoir plus, lis les articles : ' .. phrase .. '.'
	end

	return tostring( bandeauSection( 'en-savoir-plus', '2.4em', phrase ))
end

function p.SectionNonNeutre( frame )
	local html = bandeauSection( 'non-neutre',
	                             '1.8em',
	                             'Cette section ne respecte pas la [[Vikidia:neutralité|neutralité de point de vue]].',
	                             'texte-en-rouge' )
	local nocat = frame:getParent().args['nocat']
	if (not nocat or nocat == '') then
		html:wikitext( '[[Catégorie:Article à vérifier]]' )
	end

	return tostring( html )
end

--
-- bandeaux d'entête
--

function p.Autre( frame )
	local args = frame:getParent().args
	local phrase
	if args[5] then
		error( 'le modèle : Autre prend au maximum quatre paramètres' )

	elseif args[4] and mw.text.trim( args[4] ) ~= '' then
		if args[1] and mw.text.trim( args[1] ) ~= '' then
			phrase = 'Cet article concerne ' .. args[1] .. '. '
			      .. 'Si tu cherches ' .. args[2]
		              .. ', lis <b>[[' .. args[3] .. ']]</b>.'
		              .. ' Pour les sujets voisins, lis <b>[[' .. args[4] .. ']]</b>.'

		else
			phrase = 'Si tu cherches ' .. args[2]
		              .. ', lis <b>[[' .. args[3] .. ']]</b>.'
		              .. ' Pour les sujets voisins, lis <b>[[' .. args[4] .. ']]</b>.'
		end

	elseif args[3] and mw.text.trim( args[3] ) ~= '' then
		if args[1] and mw.text.trim( args[1] ) ~= '' then
			phrase = 'Cet article concerne ' .. args[1] .. '. '
			      .. 'Si tu cherches ' .. args[2]
		              .. ', lis <b>[[' .. args[3] .. ']]</b>.'

		else
			phrase = 'Si tu cherches ' .. args[2]
		              .. ', lis <b>[[' .. args[3] .. ']]</b>.'
		end

	elseif args[1] then
		if args[2] then
			phrase = 'Si tu cherches ' .. args[1]
		              .. ', lis <b>[[' .. args[2] .. ']]</b>.'

		else
			phrase = 'Lis aussi <b>[[' .. args[1] .. ']]</b>.'
		end

	else
		return p.Homonymes( frame )
	end

	return tostring( bandeauEntete( 'homonymie', phrase, not args['sans ligne'] ))
end

function p.Confondre( frame )
	local lien = require('Module:Multiparamètres').lien
	local args = frame:getParent().args

	local nombre, phrase = lien( args, true, 'ou' )
	assert( nombre ~= 0, 'Au moins une page doit être précisée !' )

	phrase = 'Ne pas confondre avec ' .. phrase .. ' !'

	return tostring( bandeauEntete( 'confusion', phrase, not args['sans ligne'] ))
end

function p.Homonymes( frame )
	local lien = require('Module:Multiparamètres').lien
	local args = frame:getParent().args

	local nombre, phrase = lien( args, true, 'ou' )

	if nombre == 0 then
		phrase = '[[' .. mw.title.getCurrentTitle().text .. ' (homonymie)]]'
	end

	phrase = 'Si tu cherches un article [[homonyme]], tu veux peut-être lire ' .. phrase .. '.'

	return tostring( bandeauEntete( 'homonymie', phrase, not args['sans ligne'] ))
end

function p.Homonymie( frame )
	local args = frame:getParent().args
	local phrase = "Sur cette [[Aide:Page d'homonymie|page d’homonymie]], tu trouveras différents sujets qui ont le même nom !"

	local entete = bandeauEntete( 'homonymie', phrase, not args['sans ligne'] )

	if (not args['nocat'] or args['nocat'] == '') then
		entete:wikitext( '[[Catégorie:Homonymie]]__DISAMBIG__' )
	end

	return tostring( entete )
end

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

	local phrase = '« ' .. args[1] .. ' » rapporte ici. Pour les autres significations, voir [[' .. args[2] .. ']].'

	return tostring( bandeauEntete( 'homonymie', phrase, not args['sans ligne'] ))
end

function p.Titres( frame )
	local args = frame:getParent().args
	local phrase = "Cette page d’[[Aide:Page d'homonymie|homonymie]] répertorie les différents œuvres partageant un même titre."

	local entete = bandeauEntete( 'homonymie', phrase, not args['sans ligne'] )

	if (not args['nocat'] or args['nocat'] == '') then
		entete:wikitext( '[[Catégorie:Homonymie]]__DISAMBIG__' )
	end

	return tostring( entete )
end

function p.WV_classe( frame )
	local args = frame:getParent().args
	local titre = mw.title.getCurrentTitle().text
	local texte = args[1] and '[[v:' .. args[1] .. '|liste des cours de ' .. titre .. ']]' or 'liste des cours de ' .. titre

	local phrase = 'Cette page est un [[Encyclopédie|article encyclopédique]]. Pour des ressources éducatives, voir la ' .. texte .. ' sur [[Wikiversité]].'

	return tostring( bandeauEntete( 'homonymie2', phrase, not args['sans ligne'] ))
end

function p.WV_fac( frame )
	local args = frame:getParent().args
	local titre = args.titre or mw.title.getCurrentTitle().text

	local phrase = 'Cette page est un [[Encyclopédie|article encyclopédique]]. Pour des ressources éducatives, voir la [[v:Faculté:' .. titre .. '|faculté d' .. (args[1] or 'e ') .. titre .. ']] sur [[Wikiversité]].'

	return tostring( bandeauEntete( 'homonymie2', phrase, not args['sans ligne'] ))
end

return p