« Module:Protection » : différence entre les versions
fixe la gestion des noms protégés |
Utilisation du Module:Bandeau |
||
| Ligne 57 : | Ligne 57 : | ||
local function bandeauProtection(titrePage, args) | local function bandeauProtection(titrePage, args) | ||
local Bandeau = require('Module:Bandeau') | |||
local nsPage = args.nsdoc or titrePage.nsText | local nsPage = args.nsdoc or titrePage.nsText | ||
local titre = cfg[nsPage] or cfg['titreDéfaut'] | local titre = cfg[nsPage] or cfg['titreDéfaut'] | ||
| Ligne 86 : | Ligne 87 : | ||
tostring(titrePage.talkPageTitle), lienAdmin, lienJournal)) | tostring(titrePage.talkPageTitle), lienAdmin, lienJournal)) | ||
return | return Bandeau._bandeauAvertissement{ | ||
niveau = 'information', | |||
['icône'] = types['protection'].image, | |||
titre = args[1] or titre, | |||
texte = tostring(texte) | |||
} | } | ||
end | end | ||
Version du 7 janvier 2016 à 02:35
-- Ce module implémente les modèles , Modèle:Semi-protection, Modèle:Semi-protection longue et Modèle:Nom protégé.
local p = {}
-- Chargement du module de données. local donnees = mw.loadData('Module:Protection/Données')
-- Définition des tables de données. local types = donnees.types local cfg = donnees.configuration
--Redéfinitions utiles. local format = mw.ustring.format local insert = table.insert
local function protectionPage(typeProtection, modeProtection, titrePage) -- Retourne vrai si la page courante est protégée et correspond -- au type de protection. local action = types[typeProtection].action or 'edit' local niveau = titrePage.protectionLevels[action][1] return modeProtection.niveau == niveau end
local function estSousPage(titrePage) -- Teste si la page actuelle est une sous-page /Documentation, -- /Bac à sable ou /Test de modèle ou de module. Retourne vrai -- si c'est le cas et faux sinon. local espaceNom = titrePage.nsText == 'Modèle' or titrePage.nsText == 'Module' local sousPage = titrePage.isSubpage and (titrePage.subpageText == 'Documentation' or titrePage.subpageText == 'Bac à sable' or titrePage.subpageText == 'Test')
return espaceNom and sousPage end
local function creerIconeTitre(modeProtection) local iconeTitre = require('Module:Icône de titre')._main local argsIcone = { image = modeProtection.image, lien = modeProtection.lien, texte = modeProtection.texte, taille = 15, id = modeProtection.id or 'protection-edition' }
return iconeTitre(argsIcone) end
local function insertionCategorie(typeProtection, nsPage) local nomCategorie = typeProtection.categorie[nsPage] local defautCategorie = typeProtection.categorie['défaut'] local lienCategorie =
return format(lienCategorie, nomCategorie or defautCategorie) end
local function bandeauProtection(titrePage, args) local Bandeau = require('Module:Bandeau') local nsPage = args.nsdoc or titrePage.nsText local titre = cfg[nsPage] or cfg['titreDéfaut'] local texte = mw.html.create('span') local lienAdmin, lienJournal
-- Gestion du nombre d'inclusion pour les modéles/modules. if nsPage == 'Modèle' or nsPage == 'Module' then if args.nombre and tonumber(args.nombre) then titre = format(titre, 'dans plus de ' .. mw.language.new('fr') :formatNum(tonumber(args.nombre))) else titre = format(titre, 'sur un très grand nombre de') end end
-- Gestion du paramètre 'texte' et de ses liens internes lienAdmin = mw.title.new(cfg['lienAdmin']) :fullUrl(format(cfg['optionAdmin'], mw.uri.encode(titrePage.fullText, 'WIKI'))) if nsPage == then lienAdmin = lienAdmin .. cfg['option2Admin'] end lienJournal = mw.title.new(cfg['lienJournal']) :fullUrl(format(cfg['optionJournal'], mw.uri.encode(titrePage.fullText, 'WIKI')))
texte :addClass('plainlinks') :wikitext(format(cfg['texteBandeau'], tostring(titrePage.talkPageTitle), lienAdmin, lienJournal))
return Bandeau._bandeauAvertissement{ niveau = 'information', ['icône'] = types['protection'].image, titre = args[1] or titre, texte = tostring(texte) } end
function p.main(typeProtection, args, titrePage) local modeProtection = types[typeProtection or 'protection'] local titrePage = titrePage or mw.title.getCurrentTitle() local res = {}
if typeProtection == 'protection' and args.nocat then return bandeauProtection(titrePage, args) end
if protectionPage(typeProtection, modeProtection, titrePage) then -- Création de l'icône de titre selon le mode de protection. insert(res, creerIconeTitre(modeProtection)) -- Création du bandeau de protection pour le mode 'protection'. if typeProtection == 'protection' then insert(res, bandeauProtection(titrePage, args)) end -- Catégorisation selon le mode de protection. insert(res, insertionCategorie(modeProtection, titrePage.nsText)) elseif not estSousPage(titrePage) then -- Catégorisation lorsque le niveau de protection en écriture ne -- correspond pas ou plus. Note : les sous-pages '/Documentation', -- '/Bac à sable' ou '/Test' appartenant aux modèles ou aux modules -- ne sont pas – et ne doivent pas être – concernées. insert(res, ) end
return table.concat(res) end
local function adaptateur(nomFonction) return function (frame) local args = {} local argsParent = frame:getParent().args
-- Paramètres vides interprétés par Lua. for cle, val in pairs(argsParent) do if val ~= or cle == 'nsdoc' then args[cle] = mw.text.trim(val) end end
return p.main(nomFonction, args) end end
-- Insertion dans la table p des fonctions appelées par les -- modèles à l'aide d'un adaptateur de fonction. local nomsFonction = {'protection', 'semiProtection', 'semiProtectionLongue', 'nomProtégé'} for _, nomFonction in ipairs(nomsFonction) do p[nomFonction] = adaptateur(nomFonction) end
return p