Module:Bandeau
-- Module dédié à la création de bandeaux en tous genres
local fun = {}
function fun.metaBandeauAvertissement(frame)
local pframe = frame:getParent() local arguments = pframe.args return fun.do_metaBandeauAvertissement(arguments)
end
-- Squelette d'un bandeau d'avertissement function fun.do_metaBandeauAvertissement(arguments) local result = "" local niveau = arguments.niveau or ""
local bClass = mw.ustring.gsub(niveau,"é","e")
local icone = ""
local texte = ""
-- Icônes prédéfinies local iconeTable = { grave = "Fairytale no.svg", ["modéré"] = "Emblem-important.svg", information = "Information_icon.svg", ["ébauche"] = "Nuvola_apps_kedit.svg" }
-- Utiliser l'icône fournie s'il y a lieu, ou prendre parmi celles de la table if(arguments["icône-complexe"] ~= nil and arguments["icône-complexe"] ~= "") then icone = arguments["icône-complexe"] else
icone = "
"
end
-- Texte du bandeau if(arguments.texte ~= nil) then
texte = "
"
end
-- Mise en boîte
result = "
" .. icone .. " | " .. (arguments.titre or "Pas de titre") .. "" .. (arguments.date or "") .. " " .. texte .. " |
"
return result end
function fun.ebauche(frame)
local pframe = frame:getParent() local arguments = pframe.args return fun.do_ebauche(arguments)
end
function fun.do_ebauche(arguments) -- Données relatives aux différents paramètres possibles du modèle -- Seront déplacées en sous-page dès que loadData sera activé -- local data = mw.loadData("Module:Bandeau/ébauche") local data = { football = {"Soccer.svg", "le football"}, footballeur = {"football", "un footballeur"}, ["hip hop"] = {"redirection", "hip-hop"}, ["hip-hop"] = {"BandeauPortailHipHopSmall-fr.svg", "le hip-hop"}, histoire = {"Pierre_Mignard_001.jpg", "l’histoire"}, Italie = {"Italy looking like the flag.svg", "l’Italie"}, jardinage = {"Extracted pink rose.png", "le jardinage et l’horticulture"}, lac = {"Icon river reservoir.svg", "un lac"}, lapin = {"Lapin01.svg", "la cuniculture", "Cuniculture"} }
local index = 1 local inconnu = {false, ""} local newTheme = 0 local nomTheme = arguments[1] local icones = {} local sujets = {} local categories = {}
-- Récupération des données sur tous les thèmes while(arguments[index] ~= nil) do -- Récupération des données relatives au thème theme = data[nomTheme] if(theme ~= nil) then if(theme[1] == "alias" or theme[1] == "redirection") then -- Cas de redirection newTheme = newTheme + 1 nomTheme = theme[2] else -- Cas normal newTheme = 0 -- Gestion de l'icône if(theme[1] ~= nil) then local cibleIcone = data[theme[1]] -- Le nom de l'icône est-il une référence directe à un autre thème ? if(cibleIcone == nil or cibleIcone[1] == "alias" or cibleIcone[1] == "redirection") then -- Non : on récupère le nom du fichier icones[#icones+1] = theme[1] else -- Oui : on récupère l'icône de l'autre thème icones[#icones+1] = cibleIcone[1] end end -- Gestion du sujet if(theme[2] ~= nil) then sujets[#sujets+1] = theme[2] end -- Gestion de la catégorie if(theme[3] ~= nil) then categories[#categories+1] = theme[3] else -- Par défaut, la catégorie correspond au thème categories[#categories+1] = nomTheme end end else -- Thème inconnu : on le mémorise et on passe au suivant newTheme = 0 inconnu[1] = true inconnu[2] = inconnu[2] .. arguments[index] .. " " end
-- Passage éventuel au thème suivant if(newTheme > 2) then
-- Prévention des boucles infinies newTheme = 0 end if(newTheme == 0) then -- Nouveau thème (non issu d'une redirection) index = index + 1 nomTheme = arguments[index] end end
-- Génération du bandeau
local multiIcone = ""
local taille = "45x35px"
-- Réduire les icônes si elles sont trop nombreuses
if(#icones > 3) then
taille = "35x25px"
end
if(#icones > 0) then
for i = 1, #icones do
multiIcone = multiIcone .. "[[Image:" .. icones[i] .. "|" .. taille .. "|alt=|link=]]"
-- Passage sur la deuxième ligne
if(#icones > 3 and i == math.floor((#icones+1)/2)) then
multiIcone = multiIcone .. "
"
elseif(i ~= #icone) then
multiIcone = multiIcone .. " "
end
end
multiIcone = "
"
end
-- Texte du bandeau, contenant les sujets local texteSuj = "Cet article est une ébauche" if(#sujets > 0) then texteSuj = texteSuj .. " concernant " for i = 1, #sujets do texteSuj = texteSuj .. sujets[i] if(i < #sujets-1) then texteSuj = texteSuj .. ", " elseif(i == #sujets-1) then texteSuj = texteSuj .. " et " end end end texteSuj = texteSuj .. ".\n"
local texteCat = "" -- Ne pas catégoriser si nocat est présent if(arguments.nocat == nil) then if(#categories > 0) then for i = 1, #categories do texteCat = texteCat .. "[[Catégorie:Wikipédia:ébauche " .. categories[i] .. "]] " end else texteCat = "" end end
-- Préparation de l'appel du modèle de méta-bandeau local metaArgs = { niveau = "ébauche", ["icône-complexe"] = multiIcone, titre = texteSuj }
return fun.do_metaBandeauAvertissement(metaArgs) .. texteCat
end
return fun