« Module:Bandeau » : différence entre les versions
_bandeauAvertissement : prise en compte du paramètre class |
légende → alt (mais légende est toujours accepté temporairement, pour tous les modèles ou je l'ai inséré) |
||
| Ligne 67 : | Ligne 67 : | ||
local iconeWiki = icone | local iconeWiki = icone | ||
if not icone:match('%[') then | if not icone:match('%[') then | ||
local alt = args['légende'] or '' | local alt = args.alt or args['légende'] or '' | ||
if alt:lower() == cfg.public then | if alt:lower() == cfg.public then | ||
alt = '|link=' | alt = '|link=' | ||
| Ligne 120 : | Ligne 120 : | ||
class = args.class, | class = args.class, | ||
['icône'] = trim(args['icône']) or trim(args['icône-complexe']) or args.niveau, | ['icône'] = trim(args['icône']) or trim(args['icône-complexe']) or args.niveau, | ||
alt = args.alt or args['légende'], | |||
texte = tostring(htmlTexte), | texte = tostring(htmlTexte), | ||
['supplément'] = args['supplément'] | ['supplément'] = args['supplément'] | ||
| Ligne 140 : | Ligne 140 : | ||
local iconeWiki = icone | local iconeWiki = icone | ||
if not icone:match('%[') then | if not icone:match('%[') then | ||
local alt = args['légende'] or '|link=' | local alt = args.alt or args['légende'] or '' | ||
if alt:lower() == cfg.public then | |||
alt = '|link=' | |||
end | |||
iconeWiki = mw.ustring.format(cfg.formatLien, icone, 'text-top|20x17', alt) | iconeWiki = mw.ustring.format(cfg.formatLien, icone, 'text-top|20x17', alt) | ||
end | end | ||
Version du 11 janvier 2016 à 04:04
--Ce module implémente les modèles de bandeau.
--Standardisation des bandeaux (). --Créer une fonction exportable pour le modèle Modèle:Bandeau (ns:all). --Créer une fonction exportable pour les bandeaux d'article (ns:0). --Créer une fonction exportable pour les bandeaux de section (ns:0). --Créer une fonction exportable pour les bandeaux d'ébauche (ns:0). --Créer une fonction exportable pour les bandeaux de discussion (ns:1). --Créer une fonction exportable pour les bandeaux système (ns:8). --Gérer les images multiples.
local p = {}
local trim = require('Module:Outils').trim local yesno = require('Module:yesno') local class = mw.loadData('Module:Bandeau/Class') -- local paramEbauche = mw.loadData('Module:Bandeau/Ébauche') -- ne sera chargé que pour un bandeau d'ébauche.
local cfg = {
forme = 'bandeau-simple',
niveau = 'bandeau-niveau-neutre',
formatLien = '%s',
tailleIcone = '45x45',
public = 'domaine public',
erreurArgument = 'Paramètre |%s= manquant',
erreurEbaucheParam = 'le thème « %s » du modèle [[Modèle:Ébauche|
]] n’est pas défini.', erreurEbaucheType = 'le thème « %s » doit apparaître en tête de liste du modèle [[Modèle:Ébauche|
]].',
ebaucheImage = '%s', ebaucheTitre = '%s est une ébauche.', ebaucheTitreSujet = '%s est une ébauche concernant %s.', ebaucheCateg = , }
local function erreur(texte, formatstring, tag) local res = mw.html.create(tag or 'span') res :addClass('error') :wikitext('Erreur : ')
if formatstring then res:wikitext(string.format(formatstring, texte)) else res:wikitext(texte) end
return tostring(res) end
function p._bandeau(args) local res = mw.html.create('div') local cells = mw.html.create() local icone = trim(args.image) or trim(args['icône']) local backgroundIcone = class.icones[icone] or local texte = (trim(args.texte) or erreur('texte', cfg.erreurArgument))
res :attr{ id = args.id } :addClass(class.formes[args.forme] or cfg.forme) :addClass(class.niveau[args.niveau] or cfg.niveau) :addClass('plainlinks') :addClass(args.class) :cssText(args.style)
if yesno(args.centrer) then cells = mw.html.create('div') :addClass('bandeau-centrer') end if icone and backgroundIcone == then local iconeWiki = icone if not icone:match('%[') then local alt = args.alt or args['légende'] or if alt:lower() == cfg.public then alt = '|link=' end local taille = args['taille icône'] or cfg.tailleIcone iconeWiki = mw.ustring.format(cfg.formatLien, icone, taille, alt) end cells :tag('div') :addClass('bandeau-cell bandeau-icone') :cssText(args.styleImage) --Provisoire :wikitext(iconeWiki) :done() elseif backgroundIcone ~= and args.forme == 'section' then texte = ' ' .. texte end cells :tag('div') :addClass('bandeau-cell ' .. backgroundIcone) :cssText(args.styleTexte) --Provisoire :wikitext(texte) :newline() :done()
res :node(cells)
if trim(args['supplément']) then res :tag('p') :wikitext(args['supplément']) :done() end
return tostring(res) end
function p._bandeauAvertissement(args) local htmlTexte = mw.html.create()
htmlTexte :tag('strong') :addClass('bandeau-titre') :wikitext(trim(args.titre) or erreur('titre', cfg.erreurArgument)) :done() :wikitext(args.date) :newline():newline() :wikitext(args.texte)
local parametres = { forme = 'article', niveau = args.niveau, id = args.id, class = args.class, ['icône'] = trim(args['icône']) or trim(args['icône-complexe']) or args.niveau, alt = args.alt or args['légende'], texte = tostring(htmlTexte), ['supplément'] = args['supplément'] }
return p._bandeau(parametres) end
function p._bandeauSection(args) local res = mw.html.create('div') local icone = trim(args.image) or trim(args['icône']) local backgroundIcone = class.icones[icone] or local texte = ' ' .. (trim(args.texte) or erreur('texte', cfg.erreurArgument))
res :addClass('bandeau-section') :addClass(class.niveau[args.niveau] or cfg.niveau)
if icone and backgroundIcone == then local iconeWiki = icone if not icone:match('%[') then local alt = args.alt or args['légende'] or if alt:lower() == cfg.public then alt = '|link=' end iconeWiki = mw.ustring.format(cfg.formatLien, icone, 'text-top|20x17', alt) end res :wikitext(iconeWiki) :done() end res :addClass(backgroundIcone) :wikitext(texte) :done()
return tostring(res) end
p['_ébauche'] = function (args) local paramEbauche = mw.loadData('Module:Bandeau/Ébauche') local ebauches, gestionErreur = {}, {} local frame = mw.getCurrentFrame() local parametres = { icone = 'icône', sujet = 'sujet', selon = 'selon', categ = 'catégorie', type = 'type', message = 'message' } local getEbaucheTable = function( theme ) -- récupére les paramètres lié au theme, à partir du module:Bandeau/Ébauche ou du modèle:Ébauche/paramètres theme local modele = 'Modèle:Ébauche/paramètres ' .. theme local params if paramEbauche[theme] then params = { nom = theme } for n, v in pairs(paramEbauche[theme]) do params[n] = v end elseif mw.title.new( modele ).exists then params = { nom = theme } for n, v in pairs(parametres) do local param = frame:expandTemplate{title = modele, args = {v}} params[n] = trim(param) end end return params end local ebaucheParam = function( i, param ) -- foction qui retourne la valeur de param pour l'ébauche i, ou une valeur par défaut. return ebauches[i] and ebauches[i][param] or paramEbauche[][param] end
for i, theme in ipairs(args) do -- récupération des paramètres de tous les thèmes theme = trim(theme) if theme then local t = getEbaucheTable(theme) if t then table.insert(ebauches, t) else table.insert( gestionErreur, erreur(theme, cfg.erreurEbaucheParam, 'div') ) end end end
local images, titres, categs = {}, {}, {}
local tailleIcone = cfg.tailleIcone
if #ebauches > 3 then
tailleIcone = '35x25'
end
for i, ebauche in ipairs(ebauches) do
-- mise en forme des images
if ebauche.icone then
table.insert(
images,
cfg.formatLien:format(
ebauche.icone,
tailleIcone,
ebauche.altIcone or
)
)
end
if math.fmod(#ebauches, 3) == 1 and (#ebauches - i) == 2
or math.fmod(i, 3) == 0 and (#ebauches - i) > 1
then
-- sur plusieurs lignes s'il y a plus de 3 images, avec minimum deux images sur la dernière ligne.
table.insert(images,'
')
end
if i > 1 and ebauche.type and ebauche.type ~= paramEbauche[].type then -- remplace "Cet article par "Ce portail" ou autre en fonction du premier thème. table.insert( gestionErreur, erreur(ebauche.nom, cfg.erreurEbaucheType, 'div') ) end
-- récupères les différents noms de thème table.insert(titres, ebauche.sujet)
-- mise en forme des catégories if ebauche.categ then table.insert( categs, cfg.ebaucheCateg:format( ebauche.categ ) ) end end
local image if trim(args['icône']) then local theme = getEbaucheTable(args['icône']) if theme and theme.icone then image = cfg.formatLien:format(theme.icone, tailleIcone, theme.altIcone or ) end elseif #images == 1 then image = images[1] elseif #images > 1 then image = cfg.ebaucheImage:format(table.concat(images, ' ')) end
local titre if #titres > 0 then titre = cfg.ebaucheTitreSujet:format( ebaucheParam(1, 'type'), mw.text.listToText(titres) ) else titre = cfg.ebaucheTitre:format(ebaucheParam(1, 'type')) end local texte if #ebauches == 0 then texte = (ebaucheParam(1, 'message')) .. '.' else texte = (ebaucheParam(1, 'message')) .. ' ' .. (ebaucheParam(1, 'selon')) .. '.' end
local parametres = { niveau = 'ébauche', ['icône'] = image, titre = titre, texte = texte, id = args.id }
local categ = if not yesno(args.nocat) then categ = table.concat(categs) if categ == then categ = cfg.ebaucheCateg:format() end end
local messageErreur = table.concat(gestionErreur) if messageErreur:len() > 0 and not yesno(args.nocat) then messageErreur = messageErreur .. end
return p._bandeauAvertissement(parametres) .. messageErreur .. categ end
-- Insertion dans la table p des fonctions appelées par les -- modèles à l'aide d'un adaptateur de fonction. local function adaptateur(nomFonction) return function (frame) local args if frame.args.texte or frame.args.titre then args = frame.args else args = frame:getParent().args end return p[nomFonction](args) end end
local nomsFonction = {'bandeau', 'bandeauAvertissement', 'bandeauSection', 'ébauche' } for _, nomFonction in ipairs(nomsFonction) do p[nomFonction] = adaptateur('_' .. nomFonction) end
return p