Communauté • Livre d'or
Actualités, astuces, interview... Venez lire la gazette de ce printemps de Vikidia !
Actualités, astuces, interview... Venez lire la gazette de ce printemps de Vikidia !
Module:Portail
Aller à la navigation
Aller à la recherche
Ce module est désormais inutilisé car il causait certains problèmes, merci de ne plus l'utiliser.
Le module : Portail fait fonctionner le modèle : Portail (voir sa documentation), ainsi que tous les bandeaux de portails.
Syntaxe usuelle
Pour créer un nouveau bandeau, utiliser la syntaxe suivante.
<includeonly>{{#invoke:Portail|Portail|nocat={{{nocat|}}} | couleur tour = <!-- une couleur, comme « #8898BF » --> | couleur fond = <!-- une couleur, comme « #C8D8FF » --> | lien portail = <!-- le titre de la page du portail, comme « Portail:France » --> | portail = <!-- un descriptif du portail, comme « Portail de la France » --> | détail = <!-- l’accroche, comme « Accéder au portail sur la France ! » --> | image = <!-- une image sans « Fichier: », comme « Francestubmap.png » --> | taille image = <!-- si nécessaire, taille de l’image en pixels, comme « 30 » --> }}</includeonly><noinclude>{{doc portail|France|la |maj}}</noinclude>
Quelques autres paramètres existent, voir le code.
La documentation de ce module est incluse depuis sa sous-page de documentation (modifier | historique).
Veuillez placer les catégories dans la sous-page /Documentation.
Les éditeurs peuvent travailler dans le bac à sable (créer).
local p = {}
--
-- création des bandeaux de portail
--
function p.portail( couleur_tour,
couleur_fond,
couleur_lien,
couleur_info,
lien_portail,
portail,
detail,
image,
taille_image,
categ,
appel )
local code
-- crée le texte du lien vers le portail
local info
if (couleur_lien and couleur_lien ~= '') then
info = tostring( mw.html.create( 'font' ):css( 'color', couleur_lien )
:wikitext( portail ))
else
info = portail
end
-- crée le texte du modèle
code = "'''[[%s|%s]]''' — %s"
info = code:format( lien_portail, info, detail )
if (couleur_info) then
info = tostring( mw.html.create( 'span' ):css( 'color', couleur_info )
:wikitext( info ))
end
-- crée le modèle
code = [=[<div style="display:table; margin:auto; margin-top:12px; border-left:4px solid %s; width:90%%; background:%s; border-radius:2px;"><div class="nomobile" style="display:table-cell; vertical-align:middle; padding:5px; text-align:left;">[[Fichier:%s|%spx|alt=|link=|class=noviewer]]</div><div style="display:table-cell; vertical-align:middle; width:90%%; font-size:110%%;">%s</div></div>]=]
local html = mw.html.create()
html:wikitext( code:format( couleur_tour, couleur_fond, image, taille_image, info ))
-- ajoute des catégories
if categ then
code = "[[Catégorie:%s/Pages liées]]"
html:wikitext( code:format( lien_portail ))
end
if not appel then
html:wikitext( "[[Catégorie:Portail appelé directement]]" )
end
return html
end
function p.Portail( frame )
local appel = frame:getParent().args['appel']
return tostring( p.portail( frame.args['couleur tour'],
frame.args['couleur fond'],
frame.args['couleur lien'],
frame.args['couleur info'],
frame.args['lien portail'],
frame.args['portail'],
frame.args['détail'],
frame.args['image'],
frame.args['taille image'],
not frame.args['nocat'] or frame.args['nocat'] == '',
appel == 'portail' or appel == 'humour' ))
end
--
-- Création de bandeaux spécifiques
--
local function portailInexistant( categ )
local html = p.portail( '#000000',
'#B7B7B7',
nil,
nil,
'Aide:Portail',
'Portail inexistant !',
'Le portail demandé n’existe pas. Corrige-le !',
'Dot grey.png',
'30',
false,
true )
if categ then
html:wikitext( "[[Catégorie:Article sans portail]]" )
end
return tostring( html )
end
local function portailDefaut( categ )
local html = p.portail( '#000000',
'#B7B7B7',
nil,
nil,
'Aide:Portail',
'Sans portail !',
'Cet article n’a pas de portail. Clique sur « Modifier le wikicode » pour en ajouter un !',
'Dot grey.png',
'30',
false,
true )
if categ then
html:wikitext( "[[Catégorie:Article sans portail]]" )
end
return tostring( html )
end
--
-- Création du bandeau de bas d'article
--
local function obtenirPortail_private( frame, titre )
return frame:expandTemplate{ title = 'Portail ' .. titre, args = { nocat = frame:getParent().args['nocat'], appel = 'portail' } }
end
local function obtenirPortail( frame, titre )
local test, portail = pcall( obtenirPortail_private, frame, titre )
if test then
return portail
else
return portailInexistant( not frame:getParent().args['nocat'] )
end
end
local function trioPortails( frame, portail1, portail2, portail3 )
local trio = [=[<p>
<div class="trio-portail-ext noprint" style="display:table; width:100%; clear:both; margin:0; padding:0; background-color:transparent;">]=]
-- le premier est forcément existant
trio = trio .. '<div class="trio-portail-int" style="display:table-cell; vertical-align:middle;">' .. tostring( obtenirPortail( frame, portail1 ))
if portail2 then
trio = trio .. '</div><div class="trio-portail-int" style="display:table-cell; vertical-align:middle;">' .. tostring( obtenirPortail( frame, portail2 ))
if portail3 then
trio = trio .. '</div><div class="trio-portail-int" style="display:table-cell; vertical-align:middle;">' .. tostring( obtenirPortail( frame, portail3 ))
end
end
return trio .. "</div></div>"
end
function p.Portails( frame )
local args = frame:getParent().args
local portails = {}
local retour = ''
-- éliminer les paramètres vides
for i, v in ipairs( args ) do
local portail = mw.text.trim( v )
if portail ~= '' then
portails[ #portails + 1 ] = portail
else
retour = '[[Catégorie:Portail avec argument vide]]'
end
end
-- gérer les cas étranges
if #portails == 0 then
return portailDefaut( not args['nocat'] )
end
if #portails == 1 then
return obtenirPortail( frame, portails[1] )
end
-- tableaux de (maxi trois) portails
local html = mw.html.create()
html:wikitext( trioPortails( frame, portails[1], portails[2], portails[3] ))
if portails[4] then
html:newline()
else
return tostring( html )
end
html:wikitext( trioPortails( frame, portails[4], portails[5], portails[6] ))
if portails[7] then
html:newline()
else
return tostring( html )
end
html:wikitext( trioPortails( frame, portails[7], portails[8], portails[9] ))
return retour .. tostring( html )
end
return p