Module:Documentation/Bac à sable
Apparence
[voir] [modifier] [historique] [purger]
Ce module implémente le modèle {{Méta documentation de modèle}}. Voir la page du modèle pour les instructions d'utilisation.
Fonctions exportables
documentation(frame)
– Fonction principale du module – à appeler avec#invoke
dans un modèle – renvoyant le code HTML de la documentation._documentation(args)
– Fonction subsidiaire du module – à appeler avecrequire()
dans un autre module – et renvoyant le code HTML de la documentation.
Autres fonctions
existePage(page)
– Teste si une page existe.textPagebase(page)
– Renvoie le nom d'une page sans son espace de noms, et sans le suffixe "/Documentation", "/Bac à sable" ou "/Test".nomSouspage(page, souspage)
– Renvoie le nom d'une sous-page, en tenant compte des cas où l'on se trouverait déjà dans une sous-page "/Documentation", "/Bac à sable" ou "/Test".lienUrl(nomPage, texteLien, action, pagePreload)
– Retourne un lien wikifié vers la page nomPage, affichant le texte texteLien, avec possibilité d'ajouter des query string (paramètre action) et un preload (paramètre pagePreload).entete(args, page, doc, existeDoc)
– Construit l'entête de la documentation contenant l'image de documentation, le titre, et les liens de création/modification/purge.protection(page, doc, existeDoc, message)
– Construit le bandeau indiquant la protection de la page le cas échéant.retireBalisesCategories(contenuDoc)
- Permet d'ignorer les balises de catégories lors de l'inclusion d'une page de doc pour les bacs à sables.contenu(args, titreDoc, existeDoc)
– Retourne la concaténation de la documentation en dur, sans cadre vert. C'est cette méthode qui génère la sous-page /Documentation rédigée par l'utilisateur.lienWstat(nomPage, texteLien)
- Retourne un lien externe vers la page wstat de statistiques sur un modèle ou module au nom nomPage, affichant le texte texteLien.notice(args, page, doc, existeDoc)
– Retourne la notice de la documentation situé en bas de page.
Exemples et tests
- Pour des exemples, voir la page de test permettant de tester diverses modifications apportées.
- Module:Documentation/Bac à sable, {{Documentation/Bac à sable}} et {{Documentation/Test}} permettent de tester diverses modifications apportées dans une version bac à sable.
La documentation de ce module est générée par le modèle {{Documentation module}}.
Elle est incluse depuis sa sous-page de documentation. Veuillez placer les catégories sur cette page-là.
Les éditeurs peuvent travailler dans le bac à sable (modifier).
Voir les statistiques d'appel depuis le wikicode sur l'outil wstat et les appels depuis d'autres modules.
--Ce module implemente le modèle {{Documentation}}.
local p = {}
function p.corps(frame)
args = frame:getParent().args
local page = mw.title.getCurrentTitle()
doc = p.docname(page)
local corps = {}
--Bandeau pour les sous-pages /Bac à sable
if page.subpageText == 'Bac à sable' then
table.insert(corps, '<div style="clear:both />')
table.insert(corps, frame:preprocess('{{Sous-page de bac à sable}}'))
end
--Génération de la documentation
table.insert(corps, frame:preprocess(p.entete(frame, args, page)))
table.insert(corps, p.contenu(frame, args, page))
table.insert(corps, frame:preprocess(p.notice(frame, args, page)))
--Code HTML brut
if args.raw then
return frame:preprocess('<nowiki>' .. table.concat(corps) .. '</nowiki>')
end
return table.concat(corps)
end
function p.ifexist(page)
if not page then return false end
if mw.title.new(page).exists then return true end
return false
end
function p.docname(page)
--On n'est pas dans une sous-page
if not page.isSubpage then return page.subjectNsText .. ":" .. page.text .. "/Documentation" end
--On est dans une sous-page
if page.subpageText == 'Documentation'
or page.subpageText == 'Bac à sable'
or page.subpageText == 'Test' then
return page.subjectNsText .. ":" .. page.baseText .. "/Documentation"
else
return page.subjectNsText .. ":" .. page.text .. "/Documentation"
end
end
function p.entete(page)
local entete = {'<div style="clear:both; margin:1em 0 0 0; border:1px solid #aaa; background:'}
if not args.couleur then table.insert(entete, '#ecfcf4')
else table.insert(entete, args.couleur) end
table.insert(entete, '; padding:1em 1em 0.8em;">')
table.insert(entete, '<div style="margin-bottom:1ex; border-bottom:1px solid #aaa; padding-bottom:3px;">')
table.insert(entete, '[[Fichier:Template-info.png|50px|alt=Documentation du modèle|link=]]')
table.insert(entete, '<span style="font-weight:bold; font-size:125%"> ')
if args.titre then table.insert(entete, args.titre)
else table.insert(entete, 'Documentation') end
table.insert(entete, '</span>')
if not args.contenu then
table.insert(entete, '<span class="mw-editsection plainlinks">[[')
local arg = mw.title.new(args[1] or doc)
if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
table.insert(entete, arg:fullUrl('action=edit') .. ' modifier]')
table.insert(entete, '] [[')
table.insert(entete, page:fullUrl('action=purge') .. ' purger]')
else
table.insert(entete, arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"}))
table.insert(entete, ' créer]')
end
table.insert(entete, ']</span>')
end
table.insert(entete, '</div>')
return table.concat(entete)
end
function p.contenu(frame, page)
local contenu = {}
if args.contenu then
table.insert(contenu, '\n')
table.insert(contenu, args.contenu)
else
table.insert(contenu, frame:preprocess('<nowiki />\n'))
--Évite toute récursion
if args[1]
and frame:preprocess('{{FULLPAGENAMEE}}') ~= frame:preprocess('{{FULLPAGENAMEE:' .. args[1] .. '}}')
and p.ifexist(args[1]) then
table.insert(contenu, frame:preprocess('{{' .. args[1] .. '}}'))
elseif frame:preprocess('{{FULLPAGENAMEE}}') ~= frame:preprocess('{{FULLPAGENAMEE:' .. doc .. '}}')
and p.ifexist(doc) then
table.insert(contenu, frame:preprocess('{{' .. doc .. '}}'))
end
end
table.insert(contenu, frame:preprocess('\n<nowiki /><div style="clear:both" />\n'))
return table.concat(contenu)
end
function p.notice(frame, page)
local notice = {}
if args.contenu then
table.insert(notice, '<div class="plainlinks" style="border-top:1px solid #aaa; margin: 1em 0 0;">')
table.insert(notice, '<p style="margin-bottom:0; padding-left:1em; font-style:italic;">\n')
if args.notice then
table.insert(notice, args.notice)
else
table.insert(notice, 'La [[Aide:Comment documenter un modèle ?|documentation]] de ce [[Aide:Modèle|modèle]] ')
table.insert(notice, 'est directement [[Aide:Inclusion|incluse]] dans le corps de ce dernier.<br />')
table.insert(notice, 'Si cette page est protégée, veuillez transférer le contenu de la documentation vers sa ')
table.insert(notice, '[{{fullurl:' .. doc)
table.insert(notice, '|action=edit&preload=Modèle:Documentation/Preload sous-page dédiée}}].')
end
else
if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
table.insert(notice, '<div class="plainlinks" style="border-top:1px solid #aaa; margin: 1em 0 0;">')
table.insert(notice, '<p style="margin-bottom:0; padding-left:1em; font-style:italic;">')
table.insert(notice, 'La [[Aide:Comment documenter un modèle ?|documentation]] de ce ')
table.insert(notice, '[[Aide:Modèle|modèle]] est [[Aide:Inclusion|incluse]] depuis sa ')
if args[1] then
table.insert(notice, '[[' .. args[1] .. '|sous-page de documentation]]')
else
table.insert(notice, '[[' .. doc .. '|sous-page de documentation]]')
end
table.insert(notice, ' <span style="font-size:89%; font-style:normal;">(')
table.insert(notice, '[{{fullurl:')
if args[1] then
table.insert(notice, args[1] .. '|action=edit}} modifier]')
table.insert(notice, ' | [{{fullurl:')
table.insert(notice, args[1] .. '|action=history}} historique]')
else
table.insert(notice, doc .. '|action=edit}} modifier]')
table.insert(notice, ' | [{{fullurl:')
table.insert(notice, doc .. '|action=history}} historique]')
end
table.insert(notice, ')</span>.<br />')
else
table.insert(notice, '<div class="plainlinks">')
table.insert(notice, '<p style="margin-bottom:0; padding-left:1em; font-style:italic;">')
end
table.insert(notice, 'Les éditeurs peuvent travailler dans le ')
if args[1] and p.ifexist(frame:preprocess('{{#rel2abs:' .. args[1] .. '/../Bac à sable}}'))
or p.ifexist(frame:preprocess('{{#rel2abs:' .. doc .. '/../Bac à sable}}')) then
table.insert(notice, '[[{{#rel2abs:')
if args[1] then
table.insert(notice, args[1])
else
table.insert(notice, doc)
end
table.insert(notice, '/../Bac à sable}}|bac à sable]]')
table.insert(notice, ' <span style="font-size:89%; font-style:normal;">(')
table.insert(notice, '[{{fullurl:{{#rel2abs:')
if args[1] then
table.insert(notice, args[1])
else
table.insert(notice, doc)
end
table.insert(notice, '/../Bac à sable}}|action=edit}} modifier])</span>')
else
table.insert(notice, 'bac à sable <span style="font-size:89%; font-style:normal;">(')
table.insert(notice, '[{{fullurl:{{#rel2abs:')
if args[1] then
table.insert(notice, args[1])
else
table.insert(notice, doc)
end
table.insert(notice, '/../Bac à sable}}|action=edit&preload=Modèle:Documentation/Preload2}} créer]')
table.insert(notice, ')</span>')
end
table.insert(notice, ' et la page de ')
if args[1] and p.ifexist(frame:preprocess('{{#rel2abs:' .. args[1] .. '/../Test}}'))
or p.ifexist(frame:preprocess('{{#rel2abs:' .. doc .. '/../Test}}')) then
table.insert(notice, '[[{{#rel2abs:')
if args[1] then
table.insert(notice, args[1])
else
table.insert(notice, doc)
end
table.insert(notice, '/../Test}}|test]]')
table.insert(notice, ' <span style="font-size:89%; font-style:normal;">(')
table.insert(notice, '[{{fullurl:{{#rel2abs:')
if args[1] then
table.insert(notice, args[1])
else
table.insert(notice, doc)
end
table.insert(notice, '/../Test}}|action=edit}} modifier])</span>')
else
table.insert(notice, 'test <span style="font-size:89%; font-style:normal;">(')
table.insert(notice, '[{{fullurl:{{#rel2abs:')
if args[1] then
table.insert(notice, args[1])
else
table.insert(notice, doc)
end
table.insert(notice, '/../Test}}|action=edit&preload=Modèle:Documentation/Preload3}} créer]')
table.insert(notice, ')</span>')
end
table.insert(notice, '.<br />Veuillez placer les catégories dans la sous-page ')
table.insert(notice, '<span class="plainlinks">[')
table.insert(notice, '{{fullurl:')
if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
if args[1] then
table.insert(notice, args[1])
else
table.insert(notice, doc)
end
table.insert(notice, '|action=edit')
else
if args[1] then
table.insert(notice, args[1])
else
table.insert(notice, doc)
end
table.insert(notice, '|action=edit&preload=Modèle:Documentation/Preload')
end
table.insert(notice, ' /Documentation}}].')
end
table.insert(notice, '</p></div></div>')
return table.concat(notice)
end
return p