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

De Le Wiki de Lug
Aller à la navigation Aller à la recherche
Modèle>Hlm Z.
Aucun résumé des modifications
m (140 revisions imported: Modele avancement)
 
(129 versions intermédiaires par 15 utilisateurs non affichées)
Ligne 1 : Ligne 1 :
--Ce module implemente le modèle {{Documentation}}.
-- Ce module implémente le modèle {{Méta documentation de modèle}}.


local p = {}
local p = {}


    function p.corps(frame)
local function existePage(page)
        local args = frame:getParent().args
return page and page.exists
        local corps = {}
end
       
        --Bandeau pour les sous-pages /Bac à sable
        if frame:preprocess('{{SUBPAGENAME}}') == 'Bac à sable' then
            table.insert(corps, '<div style="clear:both />')
            table.insert(corps, '{{Sous-page de bac à sable}}')
        end


        --Génération de la documentation
local function nomSouspage(page, souspage)
        table.insert(corps, p.entete(frame, args))
--On n'est pas dans une sous-page
        table.insert(corps, p.contenu(frame, args))
if not page.isSubpage then
        table.insert(corps, p.notice(frame, args))
return page.subjectNsText .. ':' .. page.text .. '/' .. souspage
end


        --Code HTML brute
--On est dans une sous-page
        if args.raw then
local sousPage = page.subpageText
            return frame:preprocess('<nowiki>' .. table.concat(corps) .. '</nowiki>')
if sousPage == 'Documentation'
        end
or sousPage == 'Bac à sable'
or sousPage == 'Test' then
return page.subjectNsText .. ':' .. page.baseText .. '/' .. souspage
else
return page.subjectNsText .. ':' .. page.text .. '/' .. souspage
end
end


        return frame:preprocess(table.concat(corps))
local function lienUrl(nomPage, texteLien, action, pagePreload)
       
local arguments = {}
    end


    function p.ifexist(page, frame)
if action then
        if not page then return false end
arguments['action'] = action
        if frame:preprocess('{{#ifexist:' .. page .. '|1}}') == '1' then return true end
end
        return false
    end
   
    function p.docname(frame)
        --On n'est pas dans une sous-page
        if frame:preprocess('{{BASEPAGENAME}}') == frame:preprocess('{{PAGENAME}}') then
            return frame:preprocess('{{SUBJECTPAGENAME}}/Documentation')
        else
            --On est dans une sous-page
            nom = frame:preprocess('{{SUBPAGENAME}}')
            if nom == 'Documentation' or nom == 'Bac à sable' or nom == 'Test' then
                return frame:preprocess('{{#rel2abs:../Documentation}}')
            else
                return frame:preprocess('{{SUBJECTPAGENAME}}/Documentation')
            end
        end
    end


    function p.entete(frame, args)
if pagePreload then
        local entete = {'<div style="clear:both; margin:1em 0 0 0; border:1px solid #aaa; background:'}
arguments['preload'] = 'Modèle:Documentation/' .. pagePreload
end


        if not args.couleur then
if arguments['action'] or arguments['preload'] then
            table.insert(entete, '#ecfcf4')
return mw.ustring.format('[%s %s]', nomPage:fullUrl(arguments), texteLien)
        else
else
            table.insert(entete, args.couleur)
return mw.ustring.format('[[%s|%s]]', nomPage.fullText, texteLien)
        end
end
end


        table.insert(entete, '; padding:1em 1em 0.8em;">')
local function entete(args, page, doc, existeDoc)
        table.insert(entete, '<div style="margin-bottom:1ex; border-bottom:1px solid #aaa; padding-bottom:3px;">')
local res = mw.html.create('div')


        if not args.contenu then
-- Titre
            table.insert(entete, '<span id="doc_editlinks" class="editsection plainlinks">&#91;[')
res
:css('margin-bottom', '1ex')
:css('border-bottom', '1px solid #aaa')
:css('padding-bottom', '3px')
:wikitext('[[Fichier:Test Template Info-Icon.svg|50px|alt=|link=]]')
:tag('span')
:css('font-weight', 'bold')
:css('font-size', '125%')
:css('vertical-align', 'middle')
:wikitext('&nbsp;')
:wikitext(args.titre or 'Documentation')
:done()


            if args[1] then
-- Liens
                if p.ifexist(args[1], frame) then
local editionLien = res:tag('span')
                    table.insert(entete, '{{fullurl:')
:addClass('mw-editsection-like plainlinks')
                    table.insert(entete, args[1])
:css('vertical-align', 'middle')
                    table.insert(entete, '|action=edit modifier}}]&#93;&#32;&#91;{{Purger le cache|purger}}')
                else
                    table.insert(entete, '{{fullurl:')
                    table.insert(entete, args[1])
                    table.insert(entete, '|action=edit&preload=Modèle:Documentation/Preload créer}}]')
                end
            else
                if p.ifexist(p.docname(frame), frame) then
                    table.insert(entete, '{{fullurl:')
                    table.insert(entete, p.docname(frame))
                    table.insert(entete, '|action=edit modifier}}]&#93;&#32;&#91;{{Purger le cache|purger}}')
                else
                    table.insert(entete, '{{fullurl:')
                    table.insert(entete, p.docname(frame))
                    table.insert(entete, '|action=edit&preload=Modèle:Documentation/Preload créer}}]')
                end
            end
            table.insert(entete, '&#93;</span>')
        end


        table.insert(entete, '[[Fichier:Template-info.png|50px|alt=Documentation du modèle|link=]]')
if args['aucun contenu additionnel'] == nil then
        table.insert(entete, '<span style="font-weight:bold; font-size:125%">&nbsp;')
if not args.contenu then
if existeDoc then
editionLien
:wikitext('&#91;')
:wikitext(lienUrl(doc, 'voir'))
:wikitext('&#93; ')


        if args.titre then
:wikitext('&#91;')
            table.insert(entete, args.titre)
:wikitext(lienUrl(doc, 'modifier', 'edit'))
        else
:wikitext('&#93; ')
            table.insert(entete, 'Documentation')
        end
        table.insert(entete, '</span></div>')
       
        return table.concat(entete)
    end


    function p.contenu(frame, args)
:wikitext('&#91;')
        local contenu = {}
:wikitext(lienUrl(doc, 'historique', 'history'))
        if args.contenu then
:wikitext('&#93; ')
            table.insert(contenu, '\n')
else
            table.insert(contenu, args.contenu)
local pagePreload = 'Preload'
        else
if page.namespace == 828 then
            table.insert(contenu, '<nowiki />\n')
pagePreload = 'PreloadModule'
            --Évite toute récursion
end
            if args[1]
            and frame:preprocess('{{FULLPAGENAMEE}}') ~= frame:preprocess('{{FULLPAGENAMEE:' .. args[1] .. '}}')
            and p.ifexist(args[1], frame) then
                table.insert(contenu, '{{' .. args[1] .. '}}')
            elseif frame:preprocess('{{FULLPAGENAMEE}}') ~= frame:preprocess('{{FULLPAGENAMEE:' .. p.docname(frame) .. '}}')
            and p.ifexist(p.docname(frame), frame) then
                table.insert(contenu, '{{' .. p.docname(frame) .. '}}')
            end
        end
        table.insert(contenu, '\n<nowiki /><div style="clear:both" />\n')
        return table.concat(contenu)
    end
   
    function p.notice(frame, args)
        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:' .. p.docname(frame))
                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], frame) or p.ifexist(p.docname(frame), frame) 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, '[[' .. p.docname(frame) .. '|sous-page de documentation]]')
                end
               
                table.insert(notice, '&nbsp;<span style="font-size:89%; font-style:normal;">(')
                table.insert(notice, '[{{fullurl:')


                if args[1] then
editionLien
                    table.insert(notice, args[1] .. '|action=edit}} modifier]')
:wikitext('&#91;')
                    table.insert(notice, '&nbsp;|&nbsp;[{{fullurl:')
:wikitext(lienUrl(doc, 'créer', 'edit', pagePreload))
                    table.insert(notice, args[1] .. '|action=history}} historique]')
:wikitext('&#93; ')
                else
end
                    table.insert(notice, p.docname(frame) .. '|action=edit}} modifier]')
end
                    table.insert(notice, '&nbsp;|&nbsp;[{{fullurl:')
end
                    table.insert(notice, p.docname(frame) .. '|action=history}} historique]')
 
                end
editionLien
                table.insert(notice, ')</span>.<br />')
:wikitext('&#91;')
            else
:wikitext(lienUrl(page, 'purger', 'purge'))
                table.insert(notice, '<div class="plainlinks">')
:wikitext('&#93;')
                table.insert(notice, '<p style="margin-bottom:0; padding-left:1em; font-style:italic;">')
 
            end
return res
            table.insert(notice, 'Les éditeurs peuvent travailler dans le ')
end
           
 
            if args[1] and p.ifexist(frame:preprocess('{{#rel2abs:' .. args[1] .. '/../Bac à sable}}'), frame)
local function protection(page, doc, existeDoc, message)
            or p.ifexist(frame:preprocess('{{#rel2abs:' .. p.docname(frame) .. '/../Bac à sable}}'), frame) then
-- Insertion automatique du modèle de protection.
                table.insert(notice, '[[{{#rel2abs:')
local niveauProtection = page.protectionLevels.edit
                if args[1] then
 
                    table.insert(notice, args[1])
if niveauProtection and niveauProtection[1] then
                else
local tableProtection = {
                    table.insert(notice, p.docname(frame))
autoconfirmed = {'semiProtection', '{{%s*[Ss]emi%-protection%s*[|}]', '{{%s*[Ss]emi%-protection +longue%s*[|}]'},
                end
editextendedsemiprotected = {'semiProtectionEtendue', '{{%s*[Ss]emi%-protection +étendue%s*[|}]'},
                table.insert(notice, '/../Bac à sable}}|bac à sable]]')
sysop = {'protection', '{{%s*[Pp]rotection%s*[|}]'},
                table.insert(notice, '&nbsp;<span style="font-size:89%; font-style:normal;">(')
}
                table.insert(notice, '[{{fullurl:{{#rel2abs:')
local protection = tableProtection[niveauProtection[1]]
                if args[1] then
if not protection then
                    table.insert(notice, args[1])
return ''
                else
end
                    table.insert(notice, p.docname(frame))
 
                end
local alreadyShown = false
                table.insert(notice, '/../Bac à sable}}|action=edit}} modifier])</span>')
if existeDoc then
            else
-- Vérification qu'il n'y a pas déjà un modèle de
                table.insert(notice, 'bac à sable&nbsp;<span style="font-size:89%; font-style:normal;">(')
-- protection dans la documentation du modèle.
                table.insert(notice, '[{{fullurl:{{#rel2abs:')
local contenuDoc = doc:getContent()
                if args[1] then
if contenuDoc:match(protection[2]) or (protection[3] and contenuDoc:match(protection[3])) then
                    table.insert(notice, args[1])
alreadyShown = true
                else
end
                    table.insert(notice, p.docname(frame))
end
                end
 
                table.insert(notice, '/../Bac à sable}}|action=edit&preload=Modèle:Documentation/Preload2}} créer]')
if not alreadyShown then
                table.insert(notice, ')</span>')
if message == '' then
            end
message = nil
            table.insert(notice, ' et la page de ')
end
           
return require('Module:Protection').main({message}, protection[1], page)
            if args[1] and p.ifexist(frame:preprocess('{{#rel2abs:' .. args[1] .. '/../Test}}'), frame)
end
            or p.ifexist(frame:preprocess('{{#rel2abs:' .. p.docname(frame) .. '/../Test}}'), frame) then
end
                table.insert(notice, '[[{{#rel2abs:')
end
                if args[1] then
 
                    table.insert(notice, args[1])
-- pour les bacs à sable, on retire les balises de catégories
                else
-- habituellement situées en "includeonly" à la fin de la documentation
                    table.insert(notice, p.docname(frame))
local function retireBalisesCategories(contenuDoc)
                end
local count
                table.insert(notice, '/../Test}}|test]]')
repeat
                table.insert(notice, '&nbsp;<span style="font-size:89%; font-style:normal;">(')
contenuDoc, count = mw.ustring.gsub(contenuDoc, '%[%[Catégorie:[^%]]+%]%][\t\r\n\f ]*$', '')
                table.insert(notice, '[{{fullurl:{{#rel2abs:')
until count == 0
                if args[1] then
 
                    table.insert(notice, args[1])
contenuDoc, count = mw.ustring.gsub(contenuDoc, '[\t\r\n\f ]*$', '')
                else
 
                    table.insert(notice, p.docname(frame))
return contenuDoc
                end
end
                table.insert(notice, '/../Test}}|action=edit}} modifier])</span>')
 
            else
local function contenu(args, doc, existeDoc)
                table.insert(notice, 'test&nbsp;<span style="font-size:89%; font-style:normal;">(')
local page = mw.title.getCurrentTitle()
                table.insert(notice, '[{{fullurl:{{#rel2abs:')
local res = mw.html.create():newline()
                if args[1] then
 
                    table.insert(notice, args[1])
-- Contenu auto haut
                else
if args['contenu auto haut'] then
                    table.insert(notice, p.docname(frame))
res:wikitext(args['contenu auto haut'])
                end
  :newline()
                table.insert(notice, '/../Test}}|action=edit&preload=Modèle:Documentation/Preload3}} créer]')
end
                table.insert(notice, ')</span>')
 
            end
-- Contenu ou sous-page de doc
            table.insert(notice, '.<br />Veuillez placer les catégories dans la sous-page ')
if args['aucun contenu additionnel'] == nil then
            table.insert(notice, '<span class="plainlinks">[')
if args.contenu then
            table.insert(notice, '{{fullurl:')
res:newline()
            if args[1] and p.ifexist(args[1], frame) or p.ifexist(p.docname(frame), frame) then
  :wikitext(args.contenu)
                if args[1] then
  :newline()
                    table.insert(notice, args[1])
 
                else
elseif existeDoc then
                    table.insert(notice, p.docname(frame))
local contenuDoc = mw.getCurrentFrame():expandTemplate{title = doc.prefixedText}
                end
if page.subpageText == 'Bac à sable' or page.subpageText == 'Test' then
                table.insert(notice, '|action=edit')
contenuDoc = retireBalisesCategories(contenuDoc)
               
end
            else
res:newline()
                if args[1] then
  :wikitext(contenuDoc)
                    table.insert(notice, args[1])
  :newline()
                else
 
                    table.insert(notice, p.docname(frame))
elseif page.subpageText ~= 'Bac à sable' and page.subpageText ~= 'Test' and args['contenu facultatif'] == nil then
                end
local texteBandeau = '<b>Ce %s ne possède aucune [[Aide:Documentation de modèle|documentation]] '
                table.insert(notice, '|action=edit&preload=Modèle:Documentation/Preload')
..'explicative en sous-page</b>, pas même une description succincte.<br> '
            end
..'Vous pouvez %s afin de documenter ce %s adéquatement.'
            table.insert(notice, ' /Documentation}}].')
if page.namespace == 828 then -- Module
        end
texteBandeau = texteBandeau:format(
        table.insert(notice, '</p></div></div>')
'module',
        return table.concat(notice)
lienUrl(doc, 'créer cette sous-page', 'edit', 'PreloadModule'),
    end
'module'
)
else -- Modèle
texteBandeau = texteBandeau:format(
'modèle',
lienUrl(doc, 'créer cette sous-page', 'edit', 'Preload'),
'modèle'
)
end
if page.namespace == 10 then -- Modèle
texteBandeau = texteBandeau .. '[[Catégorie:Modèle sans documentation]]'
elseif page.namespace == 828 then -- Module
if page.text:sub(1, 12) == 'Utilisateur:' then
-- Pas de catégorisation pour le pseudo-namespace "Module:Utilisateur:Toto/Nom du module"
elseif existeDoc == false then
texteBandeau = texteBandeau .. '[[Catégorie:Module sans documentation]]'
end
end
local param = {
['icône'] = 'OOjs_UI_icon_book-ltr.svg',
alt = 'MIT',
style = 'width:80%;',
texte = texteBandeau,
}
res:wikitext(require('Module:Bandeau')._bandeau(param))
end
end
 
-- Contenu auto bas
if args['contenu auto bas'] then
res:newline()
  :wikitext(args['contenu auto bas'])
end
 
res
:tag('div')
:css('clear', 'both')
 
return res
end
 
local function notice(args, page, doc, existeDoc)
local res = mw.html.create('div')
:css('border-top', '1px solid #aaa')
:css('margin', '1.5em 0 0')
 
local contenuParagraphe = res
:tag('p')
:addClass('plainlinks')
:css('margin-bottom', '0')
:css('padding-left', '1em')
:css('font-style', 'italic')
 
-- Phrase "la documentation est générée par ..."
if args['nom modèle'] then
local lienAide = '[[Aide:Modèle|modèle]]'
if page.namespace == 828 then
lienAide = '[[Aide:Module|module]]'
end
 
contenuParagraphe
:wikitext('La [[Aide:Documentation de modèle|documentation]] de ce ')
:wikitext(lienAide)
:wikitext(' est générée par le modèle ')
:wikitext(mw.getCurrentFrame():expandTemplate{title = 'm', args = {args['nom modèle']} })
:wikitext('.<br>')
else
contenuParagraphe
:tag('span')
:addClass('error')
:wikitext('Erreur : le paramètre <code>nom modèle</code> n\'est pas renseigné.<br>')
end
 
-- Phrase indiquant la provenance du contenu (dans le corps ou en sous-page)
if args['aucun contenu additionnel'] == nil then
if args.contenu then
contenuParagraphe
:wikitext('Elle est directement [[Aide:Inclusion|incluse]] dans l\'appel de ce dernier. ')
:wikitext('Si cette page est protégée, veuillez ')
:wikitext('transférer le contenu de la documentation vers sa ')
:wikitext(lienUrl(doc, 'sous-page dédiée', 'edit', 'Preload'))
:wikitext('.<br>')
elseif existeDoc then
contenuParagraphe
:wikitext('Elle est [[Aide:Inclusion|incluse]] depuis ')
 
if args['page doc'] then
contenuParagraphe
:wikitext('la page [[')
:wikitext(tostring(doc))
:wikitext(']]. ')
else
contenuParagraphe
:wikitext('sa [[')
:wikitext(tostring(doc))
:wikitext('|sous-page de documentation]]. ')
end
 
contenuParagraphe
:wikitext('Veuillez placer les catégories sur cette page-là.<br>')
end
end
 
-- Phrase indiquant les liens vers le bac à sable et la page de test
contenuParagraphe
:wikitext('Les éditeurs peuvent travailler dans le ')
 
local titrePageBacasable = nomSouspage(page, 'Bac à sable')
local pageBacasable = mw.title.new(titrePageBacasable)
 
if existePage(pageBacasable) then
contenuParagraphe
:wikitext('[[' .. titrePageBacasable .. '|bac à sable]]&nbsp;')
:tag('span')
:css('font-size', '89%')
:css('font-style', 'normal')
:wikitext('(')
:wikitext(lienUrl(pageBacasable, 'modifier', 'edit'))
:wikitext(')')
else
local pagePreload = 'Preload2'
if page.namespace == 828 then
pagePreload = nil
end
contenuParagraphe
:wikitext('bac à sable&nbsp;')
:tag('span')
:css('font-size', '89%')
:css('font-style', 'normal')
:wikitext('(')
:wikitext(lienUrl(pageBacasable, 'créer', 'edit', pagePreload))
:wikitext(')')
end
 
if page.namespace ~= 828 then
contenuParagraphe:wikitext(' et la page de ')
 
local titrePageTest = nomSouspage(page, 'Test')
local pageTest = mw.title.new(titrePageTest)
 
if existePage(pageTest) then
contenuParagraphe
:wikitext('[[' .. titrePageTest .. '|test]]&nbsp;')
:tag('span')
:css('font-size', '89%')
:css('font-style', 'normal')
:wikitext('(')
:wikitext(lienUrl(pageTest, 'modifier', 'edit'))
:wikitext(')')
else
contenuParagraphe
:wikitext('test&nbsp;')
:tag('span')
:css('font-size', '89%')
:css('font-style', 'normal')
:wikitext('(')
:wikitext(lienUrl(pageTest, 'créer', 'edit', 'Preload3'))
:wikitext(')')
end
end
contenuParagraphe:wikitext('.')
 
return res
end
 
function p._documentation(args)
local page = mw.title.getCurrentTitle()
local titrePageDoc = args['page doc'] or nomSouspage(page, 'Documentation')
local doc = mw.title.new(titrePageDoc)
local existeDoc = existePage(doc)
local res = mw.html.create()
 
--Bandeau pour les sous-pages /Bac à sable
if page.subpageText == 'Bac à sable' then
res
:tag('div')
:css('clear', 'both')
:done()
:wikitext(mw.getCurrentFrame():expandTemplate{title = 'Sous-page de bac à sable'})
end
 
--Génération de la documentation
local couleur = '#ecfcf4'
if page.namespace == 828 then
couleur = '#ecf0fc'
end
 
res
:tag('div')
:addClass('documentation')
:css('clear', 'both')
:css('margin', '1em 0 0 0')
:css('border', '1px solid #aaa')
:css('background', couleur)
:css('padding', '1em 1em 0.8em')
:node(entete(args, page, doc, existeDoc))
:wikitext(protection(page, doc, existeDoc, args['message protection']))
:node(contenu(args, doc, existeDoc))
:node(notice(args, page, doc, existeDoc))
 
-- Catégorisation par défaut pour les modules sans documentation
if page.namespace == 828 and page.subpageText ~= 'Bac à sable' and page.subpageText ~= 'Test' then
if existeDoc == false then
res:wikitext("[[Catégorie:Module en langage Lua]]")
end
end
 
return tostring(res)
end
 
function p.documentation(frame)
local args = {}
local argsParent = frame:getParent().args
 
--Paramètres vides interprétés par Lua
for cle, val in pairs(argsParent) do
val = mw.text.trim(val)
if val ~= '' then
args[cle] = val
end
end
 
return p._documentation(args)
end


return p
return p

Version actuelle datée du 9 avril 2021 à 11:22

La documentation pour ce module peut être créée à Module:Documentation/doc

-- Ce module implémente le modèle {{Méta documentation de modèle}}.

local p = {}

local function existePage(page)
	return page and page.exists
end

local function nomSouspage(page, souspage)
	--On n'est pas dans une sous-page
	if not page.isSubpage then
		return page.subjectNsText .. ':' .. page.text .. '/' .. souspage
	end

	--On est dans une sous-page
	local sousPage = page.subpageText
	if sousPage == 'Documentation'
	or sousPage == 'Bac à sable'
	or sousPage == 'Test' then
		return page.subjectNsText .. ':' .. page.baseText .. '/' .. souspage
	else
		return page.subjectNsText .. ':' .. page.text .. '/' .. souspage
	end
end

local function lienUrl(nomPage, texteLien, action, pagePreload)
	local arguments = {}

	if action then
		arguments['action'] = action
	end

	if pagePreload then
		arguments['preload'] = 'Modèle:Documentation/' .. pagePreload
	end

	if arguments['action'] or arguments['preload'] then
		return mw.ustring.format('[%s %s]', nomPage:fullUrl(arguments), texteLien)
	else
		return mw.ustring.format('[[%s|%s]]', nomPage.fullText, texteLien)
	end
end

local function entete(args, page, doc, existeDoc)
	local res = mw.html.create('div')

	-- Titre
	res
		:css('margin-bottom', '1ex')
		:css('border-bottom', '1px solid #aaa')
		:css('padding-bottom', '3px')
 		:wikitext('[[Fichier:Test Template Info-Icon.svg|50px|alt=|link=]]')
	 	:tag('span')
	 		:css('font-weight', 'bold')
	 		:css('font-size', '125%')
	 		:css('vertical-align', 'middle')
	 		:wikitext('&nbsp;')
	 		:wikitext(args.titre or 'Documentation')
	 		:done()

	-- Liens
	local editionLien = res:tag('span')
		:addClass('mw-editsection-like plainlinks')
		:css('vertical-align', 'middle')

	if args['aucun contenu additionnel'] == nil then
		if not args.contenu then
			if existeDoc then
				editionLien
					:wikitext('&#91;')
					:wikitext(lienUrl(doc, 'voir'))
					:wikitext('&#93; ')

					:wikitext('&#91;')
					:wikitext(lienUrl(doc, 'modifier', 'edit'))
					:wikitext('&#93; ')

					:wikitext('&#91;')
					:wikitext(lienUrl(doc, 'historique', 'history'))
					:wikitext('&#93; ')
			else
				local pagePreload = 'Preload'
				if page.namespace == 828 then
					pagePreload = 'PreloadModule'
				end

				editionLien
					:wikitext('&#91;')
					:wikitext(lienUrl(doc, 'créer', 'edit', pagePreload))
					:wikitext('&#93; ')
			end
		end
	end

	editionLien
		:wikitext('&#91;')
		:wikitext(lienUrl(page, 'purger', 'purge'))
		:wikitext('&#93;')

	return res
end

local function protection(page, doc, existeDoc, message)
	-- Insertion automatique du modèle de protection.
	local niveauProtection = page.protectionLevels.edit

	if niveauProtection and niveauProtection[1] then
		local tableProtection = {
			autoconfirmed = {'semiProtection', '{{%s*[Ss]emi%-protection%s*[|}]', '{{%s*[Ss]emi%-protection +longue%s*[|}]'},
			editextendedsemiprotected = {'semiProtectionEtendue', '{{%s*[Ss]emi%-protection +étendue%s*[|}]'},
			sysop = {'protection', '{{%s*[Pp]rotection%s*[|}]'},
		}
		local protection = tableProtection[niveauProtection[1]]
		if not protection then
			return ''
		end

		local alreadyShown = false
		if existeDoc then
			-- Vérification qu'il n'y a pas déjà un modèle de
			-- protection dans la documentation du modèle.
			local contenuDoc = doc:getContent()
			if contenuDoc:match(protection[2]) or (protection[3] and contenuDoc:match(protection[3])) then
				alreadyShown = true
			end
		end

		if not alreadyShown then
			if message == '' then
				message = nil
			end
			return require('Module:Protection').main({message}, protection[1], page)
		end
	end
end

-- pour les bacs à sable, on retire les balises de catégories
-- habituellement situées en "includeonly" à la fin de la documentation
local function retireBalisesCategories(contenuDoc)
	local count
	repeat
		contenuDoc, count = mw.ustring.gsub(contenuDoc, '%[%[Catégorie:[^%]]+%]%][\t\r\n\f ]*$', '')
	until count == 0

	contenuDoc, count = mw.ustring.gsub(contenuDoc, '[\t\r\n\f ]*$', '')

	return contenuDoc
end

local function contenu(args, doc, existeDoc)
	local page = mw.title.getCurrentTitle()
	local res = mw.html.create():newline()

	-- Contenu auto haut
	if args['contenu auto haut'] then
		res:wikitext(args['contenu auto haut'])
		   :newline()
	end

	-- Contenu ou sous-page de doc
	if args['aucun contenu additionnel'] == nil then
		if args.contenu then
			res:newline()
			   :wikitext(args.contenu)
			   :newline()

		elseif existeDoc then
			local contenuDoc = mw.getCurrentFrame():expandTemplate{title = doc.prefixedText}
			if page.subpageText == 'Bac à sable' or page.subpageText == 'Test' then
				contenuDoc = retireBalisesCategories(contenuDoc)
			end
			res:newline()
			   :wikitext(contenuDoc)
			   :newline()

		elseif page.subpageText ~= 'Bac à sable' and page.subpageText ~= 'Test' and args['contenu facultatif'] == nil then
			local texteBandeau = '<b>Ce %s ne possède aucune [[Aide:Documentation de modèle|documentation]] '
				..'explicative en sous-page</b>, pas même une description succincte.<br> '
				..'Vous pouvez %s afin de documenter ce %s adéquatement.'
			if page.namespace == 828 then -- Module
				texteBandeau = texteBandeau:format(
					'module',
					lienUrl(doc, 'créer cette sous-page', 'edit', 'PreloadModule'),
					'module'
				)
			else -- Modèle
				texteBandeau = texteBandeau:format(
					'modèle',
					lienUrl(doc, 'créer cette sous-page', 'edit', 'Preload'),
					'modèle'
				)
			end
			if page.namespace == 10 then -- Modèle
				texteBandeau = texteBandeau .. '[[Catégorie:Modèle sans documentation]]'
			elseif page.namespace == 828 then -- Module
				if page.text:sub(1, 12) == 'Utilisateur:' then
					-- Pas de catégorisation pour le pseudo-namespace "Module:Utilisateur:Toto/Nom du module"
				elseif existeDoc == false then
					texteBandeau = texteBandeau .. '[[Catégorie:Module sans documentation]]'
				end
			end
			local param = {
				['icône'] = 'OOjs_UI_icon_book-ltr.svg',
				alt = 'MIT',
				style = 'width:80%;',
				texte = texteBandeau,
			}
			res:wikitext(require('Module:Bandeau')._bandeau(param))
		end
	end

	-- Contenu auto bas
	if args['contenu auto bas'] then
		res:newline()
		   :wikitext(args['contenu auto bas'])
	end

	res
		:tag('div')
			:css('clear', 'both')

	return res
end

local function notice(args, page, doc, existeDoc)
	local res = mw.html.create('div')
		:css('border-top', '1px solid #aaa')
		:css('margin', '1.5em 0 0')

	local contenuParagraphe = res
		:tag('p')
			:addClass('plainlinks')
			:css('margin-bottom', '0')
			:css('padding-left', '1em')
			:css('font-style', 'italic')

	-- Phrase "la documentation est générée par ..."
	if args['nom modèle'] then
		local lienAide = '[[Aide:Modèle|modèle]]'
		if page.namespace == 828 then
			lienAide = '[[Aide:Module|module]]'
		end

		contenuParagraphe
			:wikitext('La [[Aide:Documentation de modèle|documentation]] de ce ')
			:wikitext(lienAide)
			:wikitext(' est générée par le modèle ')
			:wikitext(mw.getCurrentFrame():expandTemplate{title = 'm', args = {args['nom modèle']} })
			:wikitext('.<br>')
	else
		contenuParagraphe
		:tag('span')
			:addClass('error')
			:wikitext('Erreur : le paramètre <code>nom modèle</code> n\'est pas renseigné.<br>')
	end

	-- Phrase indiquant la provenance du contenu (dans le corps ou en sous-page)
	if args['aucun contenu additionnel'] == nil then
		if args.contenu then
			contenuParagraphe
				:wikitext('Elle est directement [[Aide:Inclusion|incluse]] dans l\'appel de ce dernier. ')
				:wikitext('Si cette page est protégée, veuillez ')
				:wikitext('transférer le contenu de la documentation vers sa ')
				:wikitext(lienUrl(doc, 'sous-page dédiée', 'edit', 'Preload'))
				:wikitext('.<br>')
		elseif existeDoc then
			contenuParagraphe
				:wikitext('Elle est [[Aide:Inclusion|incluse]] depuis ')

			if args['page doc'] then
				contenuParagraphe
					:wikitext('la page [[')
					:wikitext(tostring(doc))
					:wikitext(']]. ')
			else
				contenuParagraphe
					:wikitext('sa [[')
					:wikitext(tostring(doc))
					:wikitext('|sous-page de documentation]]. ')
			end

			contenuParagraphe
				:wikitext('Veuillez placer les catégories sur cette page-là.<br>')
		end
	end

	-- Phrase indiquant les liens vers le bac à sable et la page de test
	contenuParagraphe
		:wikitext('Les éditeurs peuvent travailler dans le ')

	local titrePageBacasable = nomSouspage(page, 'Bac à sable')
	local pageBacasable = mw.title.new(titrePageBacasable)

	if existePage(pageBacasable) then
		contenuParagraphe
			:wikitext('[[' .. titrePageBacasable .. '|bac à sable]]&nbsp;')
			:tag('span')
				:css('font-size', '89%')
				:css('font-style', 'normal')
				:wikitext('(')
				:wikitext(lienUrl(pageBacasable, 'modifier', 'edit'))
				:wikitext(')')
	else
		local pagePreload = 'Preload2'
		if page.namespace == 828 then
			pagePreload = nil
		end
		contenuParagraphe
			:wikitext('bac à sable&nbsp;')
			:tag('span')
				:css('font-size', '89%')
				:css('font-style', 'normal')
				:wikitext('(')
				:wikitext(lienUrl(pageBacasable, 'créer', 'edit', pagePreload))
				:wikitext(')')
	end

	if page.namespace ~= 828 then
		contenuParagraphe:wikitext(' et la page de ')

		local titrePageTest = nomSouspage(page, 'Test')
		local pageTest = mw.title.new(titrePageTest)

		if existePage(pageTest) then
			contenuParagraphe
				:wikitext('[[' .. titrePageTest .. '|test]]&nbsp;')
				:tag('span')
					:css('font-size', '89%')
					:css('font-style', 'normal')
					:wikitext('(')
					:wikitext(lienUrl(pageTest, 'modifier', 'edit'))
					:wikitext(')')
		else
			contenuParagraphe
				:wikitext('test&nbsp;')
				:tag('span')
					:css('font-size', '89%')
					:css('font-style', 'normal')
					:wikitext('(')
					:wikitext(lienUrl(pageTest, 'créer', 'edit', 'Preload3'))
					:wikitext(')')
		end
	end
	contenuParagraphe:wikitext('.')

	return res
end

function p._documentation(args)
	local page = mw.title.getCurrentTitle()
	local titrePageDoc = args['page doc'] or nomSouspage(page, 'Documentation')
	local doc = mw.title.new(titrePageDoc)
	local existeDoc = existePage(doc)
	local res = mw.html.create()

	--Bandeau pour les sous-pages /Bac à sable
	if page.subpageText == 'Bac à sable' then
		res
			:tag('div')
				:css('clear', 'both')
				:done()
			:wikitext(mw.getCurrentFrame():expandTemplate{title = 'Sous-page de bac à sable'})
	end

	--Génération de la documentation
	local couleur = '#ecfcf4'
	if page.namespace == 828 then
		couleur = '#ecf0fc'
	end

	res
		:tag('div')
			:addClass('documentation')
			:css('clear', 'both')
			:css('margin', '1em 0 0 0')
			:css('border', '1px solid #aaa')
			:css('background', couleur)
			:css('padding', '1em 1em 0.8em')
			:node(entete(args, page, doc, existeDoc))
			:wikitext(protection(page, doc, existeDoc, args['message protection']))
			:node(contenu(args, doc, existeDoc))
			:node(notice(args, page, doc, existeDoc))

	-- Catégorisation par défaut pour les modules sans documentation
	if page.namespace == 828 and page.subpageText ~= 'Bac à sable' and page.subpageText ~= 'Test' then
		if existeDoc == false then
			res:wikitext("[[Catégorie:Module en langage Lua]]")
		end
	end

	return tostring(res)
end

function p.documentation(frame)
	local args = {}
	local argsParent = frame:getParent().args

	--Paramètres vides interprétés par Lua
	for cle, val in pairs(argsParent) do
		val = mw.text.trim(val)
		if val ~= '' then
			args[cle] = val
		end
	end

	return p._documentation(args)
end

return p