« Module:Protection » : différence entre les versions

De Lagny-sur-Marne Wiki
Aller à la navigation Aller à la recherche
0x010D (discussion | contributions)
Aucun résumé des modifications
0x010D (discussion | contributions)
suppression paramètre « nombre » : utilité proche de zéro et laborieux à mettre à jour (si ça l'est…)
 
(11 versions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
-- Ce module implémente les modèles {{Albumchart}} et {{Singlechart}}.
-- Ce module implémente les modèles {{Protection}}, {{Semi-protection étendue}}, {{Semi-protection}}, {{Semi-protection longue}} et {{Nom protégé}}.


local p = {}
local p = {}
 
-- Chargement du module de données.
-- Chargement du module de données.
local donnees = mw.loadData('Module:Protection/Données')
local donnees = mw.loadData('Module:Protection/Données')
 
-- Définition des tables de données.
-- Définition des tables de données.
local types = donnees.types
local types = donnees.types
local cfg = donnees.configuration
local cfg = donnees.configuration
 
--Redéfinitions utiles.
--Redéfinitions utiles.
local format = mw.ustring.format
local format = mw.ustring.format
local insert = table.insert
local insert = table.insert
 
local function protectionPage(modeProtection, titrePage)
local function protectionPage(typeProtection, modeProtection, titrePage)
-- Retourne vrai si la page courante est protégée et correspond
-- Retourne vrai si la page courante est protégée et correspond
-- au type de protection.
-- au type de protection.
local niveauProtection = titrePage.protectionLevels.edit[1]
local action = types[typeProtection].action or 'edit'
return modeProtection.niveau == niveauProtection
local niveau = titrePage.protectionLevels[action] and titrePage.protectionLevels[action][1]
return modeProtection.niveau == niveau
end
end
 
local function estSousPage(titrePage)
local function estSousPage(titrePage)
-- Teste si la page actuelle est une sous-page /Documentation,
-- Teste si la page actuelle est une sous-page /Documentation,
Ligne 46 : Ligne 47 :
return iconeTitre(argsIcone)
return iconeTitre(argsIcone)
end
end
 
local function insertionCategorie(typeProtection, nsPage)
local function insertionCategorie(typeProtection, nsPage)
local nomCategorie = typeProtection.categorie[nsPage]
local nomCategorie = typeProtection.categorie[nsPage]
Ligne 54 : Ligne 55 :
return format(lienCategorie, nomCategorie or defautCategorie)
return format(lienCategorie, nomCategorie or defautCategorie)
end
end
 
local function bandeauProtection(titrePage, args)
local function bandeauProtection(titrePage, args)
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']
local texte = mw.html.create('span')
local texte = mw.html.create('span')
local lienAdmin, lienJournal
local pageDiscussion, lienAdmin, lienJournal
   
   
-- Gestion du nombre d'inclusion pour les modéles/modules.
-- Gestion du nombre d'inclusions pour les modèles/modules.
if nsPage == 'Modèle' or nsPage == 'Module' then
if nsPage == 'Modèle' or nsPage == 'Module' then
if args.nombre and tonumber(args.nombre) then
titre = format(titre, titrePage:partialUrl())
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
end
   
   
-- Gestion du paramètre 'texte' et de ses liens internes
-- Gestion du paramètre 'texte' et de ses liens internes
pageDiscussion = tostring(titrePage.talkPageTitle)
lienAdmin = mw.title.new(cfg['lienAdmin'])
lienAdmin = mw.title.new(cfg['lienAdmin'])
:fullUrl(format(cfg['optionAdmin'],
:fullUrl(format(cfg['optionAdmin'],
Ligne 79 : Ligne 76 :
:fullUrl(format(cfg['optionJournal'],
:fullUrl(format(cfg['optionJournal'],
mw.uri.encode(titrePage.fullText, 'WIKI')))
mw.uri.encode(titrePage.fullText, 'WIKI')))
texte
texte
:addClass('plainlinks')
:addClass('plainlinks')
:wikitext(format(cfg['texteBandeau'],  
:wikitext(format(cfg['texteBandeau'],  
tostring(titrePage.talkPageTitle), lienAdmin, lienJournal))
pageDiscussion, pageDiscussion, lienAdmin, lienJournal))
   
   
return mw.getCurrentFrame():expandTemplate{
return require('Module:Bandeau')._bandeauAvertissement{
title = "Méta bandeau d'avertissement",
niveau    = 'information',
args  = {
['icône'] = types['protection'].image,
niveau    = 'information',
titre    = args[1] or titre,
['icône'] = types['protection'].image,
texte    = tostring(texte)
titre    = args[1] or titre,
texte    = tostring(texte)
}
}
}
end
end
 
function p.main(typeProtection, args, titrePage)
function p.main(args, typeProtection, titrePage)
local modeProtection = types[typeProtection or 'protection']
typeProtection = typeProtection or 'protection'
local modeProtection = types[typeProtection]
local titrePage = titrePage or mw.title.getCurrentTitle()
local titrePage = titrePage or mw.title.getCurrentTitle()
local res = {}
local res = {}
Ligne 105 : Ligne 100 :
end
end
   
   
if protectionPage(modeProtection, titrePage) then
if protectionPage(typeProtection, modeProtection, titrePage) then
-- Création de l'icône de titre selon le mode de protection.
-- Création de l'icône de titre selon le mode de protection.
insert(res, creerIconeTitre(modeProtection))
insert(res, creerIconeTitre(modeProtection))
Ligne 124 : Ligne 119 :
return table.concat(res)
return table.concat(res)
end
end
 
local function adaptateur(nomFonction)
local function adaptateur(nomFonction)
return function (frame)
return function (frame)
Ligne 137 : Ligne 132 :
end
end
   
   
return p.main(nomFonction, args)
return p.main(args, nomFonction)
end
end
end
end
Ligne 143 : Ligne 138 :
-- Insertion dans la table p des fonctions appelées par les
-- Insertion dans la table p des fonctions appelées par les
-- modèles à l'aide d'un adaptateur de fonction.
-- modèles à l'aide d'un adaptateur de fonction.
local nomsFonction = {'protection', 'semiProtection', 'semiProtectionLongue', 'nomProtégé'}  
local nomsFonction = {'protection', 'semiProtectionEtendue', 'semiProtection', 'semiProtectionLongue', 'nomProtégé'}  
for _, nomFonction in ipairs(nomsFonction) do
for _, nomFonction in ipairs(nomsFonction) do
p[nomFonction] = adaptateur(nomFonction)
p[nomFonction] = adaptateur(nomFonction)
end
end
 
return p
return p

Dernière version du 22 juin 2016 à 03:49

-- Ce module implémente les modèles , Modèle:Semi-protection étendue, 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] and 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 nsPage = args.nsdoc or titrePage.nsText local titre = cfg[nsPage] or cfg['titreDéfaut'] local texte = mw.html.create('span') local pageDiscussion, lienAdmin, lienJournal

-- Gestion du nombre d'inclusions pour les modèles/modules. if nsPage == 'Modèle' or nsPage == 'Module' then titre = format(titre, titrePage:partialUrl()) end

-- Gestion du paramètre 'texte' et de ses liens internes pageDiscussion = tostring(titrePage.talkPageTitle) 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'], pageDiscussion, pageDiscussion, lienAdmin, lienJournal))

return require('Module:Bandeau')._bandeauAvertissement{ niveau = 'information', ['icône'] = types['protection'].image, titre = args[1] or titre, texte = tostring(texte) } end

function p.main(args, typeProtection, titrePage) typeProtection = typeProtection or 'protection' local modeProtection = types[typeProtection] 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(args, nomFonction) 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', 'semiProtectionEtendue', 'semiProtection', 'semiProtectionLongue', 'nomProtégé'} for _, nomFonction in ipairs(nomsFonction) do p[nomFonction] = adaptateur(nomFonction) end

return p