Module:Documentation : Différence entre versions

De Lagny-sur-Marne Wiki
Aller à : navigation, rechercher
m (Retouche texte selon DIPP de Oliv0 le 1 août 2013 à 16:58 (CEST))
m (retouche modif précédente)
 
(44 révisions intermédiaires par 7 utilisateurs non affichées)
Ligne 3 : Ligne 3 :
 
local p = {}
 
local p = {}
  
function p.corps(frame)
+
local function existePage(page)
    args = frame:getParent().args
+
return page and page.exists
    local page = mw.title.getCurrentTitle()
+
end
    doc = p.docname(page)
+
 
    local corps = {}
+
local function nomDocumentation(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
 +
local sousPage = page.subpageText
 +
if sousPage == 'Documentation'
 +
or sousPage == 'Bac à sable'
 +
or sousPage == 'Test' then
 +
return page.subjectNsText .. ':' .. page.baseText .. '/Documentation'
 +
else
 +
return page.subjectNsText .. ':' .. page.text .. '/Documentation'
 +
end
 +
end
  
    --Bandeau pour les sous-pages /Bac à sable
+
local function lienUrl(nomPage, titrePage, action, pagePreload)
    if page.subpageText == 'Bac à sable' then
+
local argument = {['action'] = action or 'edit'}
        table.insert(corps, '<div style="clear:both />')
+
        table.insert(corps, frame:preprocess('{{Sous-page de bac à sable}}'))
+
if pagePreload then
    end
+
argument['preload'] = 'Modèle:Documentation/Preload' .. pagePreload
 +
end
  
    --Génération de la documentation
+
return mw.ustring.format('[%s %s]', nomPage:fullUrl(argument), titrePage)
    table.insert(corps, p.entete(page))
+
end
    table.insert(corps, p.contenu(frame, page))
 
    table.insert(corps, p.notice(page))
 
  
    --Code HTML brut
+
local function entete(args, page, doc, existeDoc)
    if args.raw then
+
local res = mw.html.create('div')
        return frame:preprocess('<nowiki>' .. table.concat(corps) .. '</nowiki>\n:' .. os.clock())
 
    end
 
  
    return table.concat(corps)
+
res
 +
:css('margin-bottom', '1ex')
 +
:css('border-bottom', '1px solid #aaa')
 +
:css('padding-bottom', '3px')
 +
:wikitext('[[Fichier:Template-info.png|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 not args.contenu then
 +
local editionLien = res:tag('span')
 +
:addClass('mw-editsection plainlinks')
 +
:css('vertical-align', 'middle')
 +
:wikitext('&#91;')
 +
 
 +
if existeDoc then
 +
editionLien:wikitext(lienUrl(doc, 'modifier'))
 +
else
 +
if args.module then
 +
editionLien:wikitext(lienUrl(doc, 'créer', 'edit', 'Module'))
 +
else
 +
editionLien:wikitext(lienUrl(doc, 'créer', 'edit', ''))
 +
end
 +
end
 +
 
 +
editionLien
 +
:wikitext('&#93;&#32;&#91;')
 +
:wikitext(lienUrl(page, 'purger', 'purge'))
 +
:wikitext('&#93;')
 +
end
 +
 
 +
return res
 
end
 
end
  
function p.docname(page)
+
local function protection(page, doc, existeDoc, message)
    --On n'est pas dans une sous-page
+
-- Insertion automatique du modèle de protection.
    if not page.isSubpage then return page.subjectNsText .. ":" .. page.text .. "/Documentation" end
+
local niveauProtection = page.protectionLevels.edit
  
    --On est dans une sous-page
+
if niveauProtection and niveauProtection[1] then
    if page.subpageText == 'Documentation'
+
local tableProtection = {
    or page.subpageText == 'Bac à sable'
+
autoconfirmed = {'semiProtection', '{{%s*[Ss]emi%-protection%s*l?o?n?g?u?e?[|}]'},
    or page.subpageText == 'Test' then
+
editextendedsemiprotected = {'semiProtectionEtendue', '{{%s*[Ss]emi%-protection étendue%s*[|}]'},
        return page.subjectNsText .. ":" .. page.baseText .. "/Documentation"
+
sysop = {'protection', '{{%s*[Pp]rotection%s*[|}]'},
    else
+
}
        return page.subjectNsText .. ":" .. page.text .. "/Documentation"
+
local protection = tableProtection[niveauProtection[1]]
    end
+
if existeDoc then
end
+
-- 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]) then
 +
protection = false
 +
end
 +
end
  
function p.ifexist(page)
+
if protection then
    if not page then return false end
+
if message == '' then
    if mw.title.new(page).exists then return true end
+
message = nil
    return false
+
end
 +
return require('Module:Protection').main({message}, protection[1], page)
 +
end
 +
end
 
end
 
end
  
function p.entete(page)
+
local function contenu(args, doc, existeDoc)
    local entete = {'<div style="clear:both; margin:1em 0 0 0; border:1px solid #aaa; background:'}
+
local page = mw.title.getCurrentTitle()
 +
local res = mw.html.create():newline()
  
    if not args.couleur then table.insert(entete, '#ecfcf4')
+
if args.contenu then
    else table.insert(entete, args.couleur) end
+
res:wikitext(args.contenu)
 +
elseif existeDoc then
 +
local frame = mw.getCurrentFrame()
 +
if frame.args and frame.args['contenu sous-page'] then
 +
res:wikitext(frame.args['contenu sous-page'])
 +
else
 +
res:wikitext(frame:expandTemplate{title = doc.prefixedText})
 +
end
 +
elseif page.subpageText ~= 'Bac à sable' and page.subpageText ~= 'Test' 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 args.module then
 +
texteBandeau = texteBandeau:format(
 +
'module',
 +
lienUrl(doc, 'créer cette sous-page', 'edit', 'Module'),
 +
'module'
 +
)
 +
else
 +
texteBandeau = texteBandeau:format(
 +
'modèle',
 +
lienUrl(doc, 'créer cette sous-page', 'edit', ''),
 +
'modèle'
 +
)
 +
end
 +
if page.namespace == 10 then
 +
texteBandeau = texteBandeau .. '[[Catégorie:Modèle sans documentation]]'
 +
elseif page.namespace == 828 then
 +
if page.baseText == 'Carte/données' or page.baseText == 'Country data' or page.text:sub(1, 12) == 'Utilisateur:' then
 +
-- pas de catégorisation pour : modèles de données, pseudo-namespace "Module:Utilisateur:Toto/Nom du module"
 +
else
 +
texteBandeau = texteBandeau .. '[[Catégorie:Module sans documentation]]'
 +
end
 +
end
 +
local param = {
 +
['icône'] = 'Book-cover-A-Z.svg',
 +
alt = 'domaine public',
 +
style = 'width:80%;',
 +
texte = texteBandeau,
 +
}
 +
res:wikitext(require('Module:Bandeau')._bandeau(param))
 +
end
  
    table.insert(entete, '; padding:1em 1em 0.8em;">')
+
res
    table.insert(entete, '<div style="margin-bottom:1ex; border-bottom:1px solid #aaa; padding-bottom:3px;">')
+
:newline()
    table.insert(entete, '[[Fichier:Template-info.png|50px|alt=Documentation du modèle|link=]]')
+
:tag('div')
    table.insert(entete, '<span style="font-weight:bold; font-size:125%">&nbsp;')
+
:css('clear', 'both')
 +
 +
return res
 +
end
  
    if args.titre then table.insert(entete, args.titre)
+
local function notice(args, page, doc, existeDoc)
    else table.insert(entete, 'Documentation') end
+
local res = mw.html.create('div')
    table.insert(entete, '</span>')
+
:css('border-top', '1px solid #aaa')
 +
:css('margin', '1.5em 0 0')
  
    if not args.contenu then
+
local contenuParagraphe = res
        table.insert(entete, '<span class="mw-editsection plainlinks">&#91;[')
+
:tag('p')
        local arg = mw.title.new(args[1] or doc)
+
:addClass('plainlinks')
 +
:css('margin-bottom', '0')
 +
:css('padding-left', '1em')
 +
:css('font-style', 'italic')
  
        if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
+
if args.contenu then
            table.insert(entete, arg:fullUrl('action=edit') .. ' modifier]')
+
if args.notice then
            table.insert(entete, '&#93;&#32;&#91;[')
+
contenuParagraphe:wikitext(args.notice .. '<br />')
            table.insert(entete, page:fullUrl('action=purge') .. ' purger]')
+
else
        else
+
contenuParagraphe
            table.insert(entete, arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"}))
+
:wikitext('La [[Aide:Documentation de modèle|documentation]] ')
            table.insert(entete, ' créer]')
+
:wikitext('de ce [[Aide:Modèle|modèle]] est directement ')
        end
+
:wikitext('[[Aide:Inclusion|incluse]] dans le corps de ce dernier. ')
        table.insert(entete, '&#93;</span>')
+
:wikitext(lienUrl(page, 'Cliquez ici pour purger le cache', 'purge'))
    end
+
:wikitext('.<br /> 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', ''))
 +
:wikitext('.<br /> ')
 +
end
 +
else
 +
if existeDoc then
 +
local lienAide = '[[Aide:Modèle|modèle]]'
 +
if args.module then
 +
lienAide = '[[Aide:Module|module]]'
 +
end
 +
contenuParagraphe
 +
:wikitext('La [[Aide:Documentation de modèle|documentation]] de ce ')
 +
:wikitext(lienAide)
 +
:wikitext(' est [[Aide:Inclusion|incluse]] depuis sa [[')
 +
:wikitext(tostring(doc))
 +
:wikitext('|sous-page de documentation]]&nbsp;')
 +
:tag('span')
 +
:css('font-size', '89%')
 +
:css('font-style', 'normal')
 +
:wikitext('(')
 +
:wikitext(lienUrl(doc, 'modifier'))
 +
:wikitext('&nbsp;|&nbsp;')
 +
:wikitext(lienUrl(doc, 'historique', 'history'))
 +
:wikitext(').<br /> ')
 +
:done()
 +
:wikitext('Veuillez placer les catégories dans la sous-page ')
 +
:wikitext(lienUrl(doc, '/Documentation'))
 +
:wikitext('.<br /> ')
 +
end
 +
end
 +
 +
contenuParagraphe:wikitext('Les éditeurs peuvent travailler dans le ')
 +
 +
local titrePageBacasable = nomDocumentation(page):gsub('/Documentation', '/Bac à sable')
 +
local pageBacasable = mw.title.new(titrePageBacasable)
  
    table.insert(entete, '</div>')
+
if existePage(pageBacasable) then
    return table.concat(entete)
+
contenuParagraphe
end
+
:wikitext('[[' .. titrePageBacasable .. '|bac à sable]]&nbsp;')
 +
:tag('span')
 +
:css('font-size', '89%')
 +
:css('font-style', 'normal')
 +
:wikitext('(')
 +
:wikitext(lienUrl(pageBacasable, 'modifier'))
 +
:wikitext(')')
 +
else
 +
local preLoad = '2'
 +
if args.module then
 +
preLoad = nil
 +
end
 +
contenuParagraphe
 +
:wikitext('bac à sable&nbsp;')
 +
:tag('span')
 +
:css('font-size', '89%')
 +
:css('font-style', 'normal')
 +
:wikitext('(')
 +
:wikitext(lienUrl(pageBacasable, 'créer', 'edit', preLoad))
 +
:wikitext(')')
 +
end
 +
 +
if not args.module then
 +
contenuParagraphe:wikitext(' et la page de ')
  
function p.contenu(frame, page)
+
local titrePageTest = nomDocumentation(page):gsub('/Documentation', '/Test')
    local contenu = {}
+
local pageTest = mw.title.new(titrePageTest)
    local arg = args[1] or doc
+
    if args.contenu then
+
if existePage(pageTest) then
        table.insert(contenu, '\n')
+
contenuParagraphe
        table.insert(contenu, args.contenu)
+
:wikitext('[[' .. titrePageTest .. '|test]]&nbsp;')
    else
+
:tag('span')
        table.insert(contenu, frame:preprocess('<nowiki />'))
+
:css('font-size', '89%')
        table.insert(contenu, '\n')
+
:css('font-style', 'normal')
        if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
+
:wikitext('(')
            table.insert(contenu, frame:preprocess('{{' .. arg .. '}}'))
+
:wikitext(lienUrl(pageTest, 'modifier'))
        end
+
:wikitext(')')
    end
+
else
 +
contenuParagraphe
 +
:wikitext('test&nbsp;')
 +
:tag('span')
 +
:css('font-size', '89%')
 +
:css('font-style', 'normal')
 +
:wikitext('(')
 +
:wikitext(lienUrl(pageTest, 'créer', 'edit', '3'))
 +
:wikitext(')')
 +
end
 +
end
 +
contenuParagraphe:wikitext('.')
  
    table.insert(contenu, '\n')
+
return res
    table.insert(contenu, frame:preprocess('<nowiki />'))
 
    table.insert(contenu, '<div style="clear:both" />\n')
 
    return table.concat(contenu)
 
 
end
 
end
  
function p.notice(page)
+
function p._documentation(args)
    local notice = {}
+
local page = mw.title.getCurrentTitle()
    local arg = mw.title.new(args[1] or doc)
+
local titreDoc = nomDocumentation(page)
 +
local doc = mw.title.new(args[1] or titreDoc)
 +
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
  
    if args.contenu then
+
--Génération de la documentation
        table.insert(notice, '<div class="plainlinks" style="border-top:1px solid #aaa; margin: 1em 0 0;">')
+
res
        table.insert(notice, '<p style="margin-bottom:0; padding-left:1em; font-style:italic;">\n')
+
:tag('div')
 +
:css('clear', 'both')
 +
:css('margin', '1em 0 0 0')
 +
:css('border', '1px solid #aaa')
 +
:css('background', args.couleur or '#ecfcf4')
 +
: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))
  
        if args.notice then
+
--Catégorisation des modules, en rangeant à part les modules de données
            table.insert(notice, args.notice)
+
if page.namespace == 828 and page.subpageText ~= 'Bac à sable' and page.subpageText ~= 'Test' then
        else
+
if page.isSubpage and page.baseText == 'Carte/données' then
            table.insert(notice, 'La [[Aide:Comment documenter un modèle ?|documentation]] de ce ')
+
res:wikitext("[[Catégorie:Module de paramétrage de carte]]")
            table.insert(notice, '[[Aide:Modèle|modèle]] est directement [[Aide:Inclusion|incluse]] ')
+
elseif page.isSubpage and page.baseText == 'Country data' then
            table.insert(notice, 'dans le corps de ce dernier.<br />Si cette page est protégée, ')
+
res:wikitext("[[Catégorie:Module d'informations pays]]")
            table.insert(notice, 'veuillez transférer le contenu de la documentation vers sa [')
+
else
            table.insert(notice, arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"}))
+
res:wikitext("[[Catégorie:Module en langage Lua]]")
            table.insert(notice, ' sous-page dédiée].')
+
end
        end
+
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 [[')
 
            table.insert(notice, tostring(arg) .. '|sous-page de documentation]]')
 
            table.insert(notice, '&nbsp;<span style="font-size:89%; font-style:normal;">([')
 
            table.insert(notice, arg:fullUrl('action=edit'))
 
            table.insert(notice, ' modifier]&nbsp;|&nbsp;[')
 
            table.insert(notice, arg:fullUrl('action=history') .. ' historique])</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 ')
 
  
        local bacasable = arg.subjectNsText .. ":" .. arg.baseText .. "/Bac à sable"
+
return tostring(res)
        local argbacasable = mw.title.new(bacasable)
+
end
        if p.ifexist(bacasable) then
 
            table.insert(notice, '[[' .. bacasable .. '|bac à sable]]')
 
            table.insert(notice, '&nbsp;<span style="font-size:89%; font-style:normal;">([')
 
            table.insert(notice, argbacasable:fullUrl('action=edit'))
 
            table.insert(notice, ' modifier])</span>')
 
        else
 
            table.insert(notice, 'bac à sable&nbsp;<span style="font-size:89%; font-style:normal;">([')
 
            table.insert(notice, argbacasable:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload2"}))
 
            table.insert(notice, ' créer])</span>')
 
        end
 
        table.insert(notice, ' et la page de ')
 
  
        local test = arg.subjectNsText .. ":" .. arg.baseText .. "/Test"
+
function p.documentation(frame)
        local argtest = mw.title.new(test)
+
local args = {}
        if p.ifexist(test) then
+
local argsParent = frame:getParent().args
            table.insert(notice, '[[' .. test .. '|test]]')
 
            table.insert(notice, '&nbsp;<span style="font-size:89%; font-style:normal;">([')
 
            table.insert(notice, argtest:fullUrl('action=edit'))
 
            table.insert(notice, ' modifier])</span>')
 
        else
 
            table.insert(notice, 'test&nbsp;<span style="font-size:89%; font-style:normal;">([')
 
            table.insert(notice, argtest:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload3"}))
 
            table.insert(notice, ' créer])</span>')
 
        end
 
  
        table.insert(notice, '.<br />Veuillez placer les catégories dans la sous-page ')
+
--Paramètres vides interprétés par Lua
        table.insert(notice, '<span class="plainlinks">[')
+
for cle, val in pairs(argsParent) do
 +
if val ~= '' then
 +
args[cle] = mw.text.trim(val)
 +
end
 +
end
  
        if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
+
return p._documentation(args)
            table.insert(notice, arg:fullUrl('action=edit'))
+
end
        else
 
            table.insert(notice, arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"}))
 
        end
 
  
        table.insert(notice, ' /Documentation].')
+
function p.nomDocumentation(frame)
    end
+
if frame.args[1] and mw.text.trim(frame.args[1]) ~= '' then
    table.insert(notice, '</p></div></div>')
+
return frame.args[1]
    return table.concat(notice)
+
else
 +
local titreDoc = nomDocumentation(mw.title.getCurrentTitle())
 +
if mw.title.new(titreDoc).exists then
 +
return titreDoc
 +
end
 +
end
 
end
 
end
  
 
return p
 
return p

Version actuelle datée du 15 mai 2017 à 08:40

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

--Ce module implémente le modèle {{Documentation}}.

local p = {}

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

local function nomDocumentation(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
	local sousPage = page.subpageText
	if sousPage == 'Documentation'
	or sousPage == 'Bac à sable'
	or sousPage == 'Test' then
		return page.subjectNsText .. ':' .. page.baseText .. '/Documentation'
	else
		return page.subjectNsText .. ':' .. page.text .. '/Documentation'
	end
end

local function lienUrl(nomPage, titrePage, action, pagePreload)
	local argument = {['action'] = action or 'edit'}
 
	if pagePreload then
		argument['preload'] = 'Modèle:Documentation/Preload' .. pagePreload
	end

	return mw.ustring.format('[%s %s]', nomPage:fullUrl(argument), titrePage)
end

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

	res
		:css('margin-bottom', '1ex')
		:css('border-bottom', '1px solid #aaa')
		:css('padding-bottom', '3px')
 		:wikitext('[[Fichier:Template-info.png|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 not args.contenu then
		local editionLien = res:tag('span')
			:addClass('mw-editsection plainlinks')
			:css('vertical-align', 'middle')
			:wikitext('&#91;')

		if existeDoc then
			editionLien:wikitext(lienUrl(doc, 'modifier'))
		else
			if args.module then
				editionLien:wikitext(lienUrl(doc, 'créer', 'edit', 'Module'))
			else
				editionLien:wikitext(lienUrl(doc, 'créer', 'edit', ''))
			end
		end

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

	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*l?o?n?g?u?e?[|}]'},
			editextendedsemiprotected = {'semiProtectionEtendue', '{{%s*[Ss]emi%-protection étendue%s*[|}]'},
			sysop = {'protection', '{{%s*[Pp]rotection%s*[|}]'},
		}
		local protection = tableProtection[niveauProtection[1]]
		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]) then
				protection = false
			end
		end

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

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

	if args.contenu then
		res:wikitext(args.contenu)
	elseif existeDoc then
		local frame = mw.getCurrentFrame()
		if frame.args and frame.args['contenu sous-page'] then
			res:wikitext(frame.args['contenu sous-page'])
		else
			res:wikitext(frame:expandTemplate{title = doc.prefixedText})
		end
	elseif page.subpageText ~= 'Bac à sable' and page.subpageText ~= 'Test' 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 args.module then
			texteBandeau = texteBandeau:format(
				'module',
				lienUrl(doc, 'créer cette sous-page', 'edit', 'Module'),
				'module'
			)
		else
			texteBandeau = texteBandeau:format(
				'modèle',
				lienUrl(doc, 'créer cette sous-page', 'edit', ''),
				'modèle'
			)
		end
		if page.namespace == 10 then
			texteBandeau = texteBandeau .. '[[Catégorie:Modèle sans documentation]]'
		elseif page.namespace == 828 then
			if page.baseText == 'Carte/données' or page.baseText == 'Country data' or page.text:sub(1, 12) == 'Utilisateur:' then
				-- pas de catégorisation pour : modèles de données, pseudo-namespace "Module:Utilisateur:Toto/Nom du module"
			else
				texteBandeau = texteBandeau .. '[[Catégorie:Module sans documentation]]'
			end
		end
		local param = {
			['icône'] = 'Book-cover-A-Z.svg',
			alt = 'domaine public',
			style = 'width:80%;',
			texte = texteBandeau,
		}
		res:wikitext(require('Module:Bandeau')._bandeau(param))
	end

	res
		:newline()
		: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')

	if args.contenu then
		if args.notice then
			contenuParagraphe:wikitext(args.notice .. '<br />')
		else
			contenuParagraphe
				:wikitext('La [[Aide:Documentation de modèle|documentation]] ')
				:wikitext('de ce [[Aide:Modèle|modèle]] est directement ')
				:wikitext('[[Aide:Inclusion|incluse]] dans le corps de ce dernier. ')
				:wikitext(lienUrl(page, 'Cliquez ici pour purger le cache', 'purge'))
				:wikitext('.<br /> 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', ''))
				:wikitext('.<br /> ')
		end
	else
		if existeDoc then
			local lienAide = '[[Aide:Modèle|modèle]]'
			if args.module then
				lienAide = '[[Aide:Module|module]]'
			end
			contenuParagraphe
				:wikitext('La [[Aide:Documentation de modèle|documentation]] de ce ')
				:wikitext(lienAide)
				:wikitext(' est [[Aide:Inclusion|incluse]] depuis sa [[')
				:wikitext(tostring(doc))
				:wikitext('|sous-page de documentation]]&nbsp;')
				:tag('span')
					:css('font-size', '89%')
					:css('font-style', 'normal')
					:wikitext('(')
					:wikitext(lienUrl(doc, 'modifier'))
					:wikitext('&nbsp;|&nbsp;')
					:wikitext(lienUrl(doc, 'historique', 'history'))
					:wikitext(').<br /> ')
					:done()
				:wikitext('Veuillez placer les catégories dans la sous-page ')
				:wikitext(lienUrl(doc, '/Documentation'))
				:wikitext('.<br /> ')
		end
	end
	
	contenuParagraphe:wikitext('Les éditeurs peuvent travailler dans le ')
	
	local titrePageBacasable = nomDocumentation(page):gsub('/Documentation', '/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'))
				:wikitext(')')
	else
		local preLoad = '2'
		if args.module then
			preLoad = nil
		end
		contenuParagraphe
			:wikitext('bac à sable&nbsp;')
			:tag('span')
				:css('font-size', '89%')
				:css('font-style', 'normal')
				:wikitext('(')
				:wikitext(lienUrl(pageBacasable, 'créer', 'edit', preLoad))
				:wikitext(')')
	end
	
	if not args.module then
		contenuParagraphe:wikitext(' et la page de ')

		local titrePageTest = nomDocumentation(page):gsub('/Documentation', '/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'))
					:wikitext(')')
		else
			contenuParagraphe
				:wikitext('test&nbsp;')
				:tag('span')
					:css('font-size', '89%')
					:css('font-style', 'normal')
					:wikitext('(')
					:wikitext(lienUrl(pageTest, 'créer', 'edit', '3'))
					:wikitext(')')
		end
	end
	contenuParagraphe:wikitext('.')

	return res
end

function p._documentation(args)
	local page = mw.title.getCurrentTitle()
	local titreDoc = nomDocumentation(page)
	local doc = mw.title.new(args[1] or titreDoc)
	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
	res
		:tag('div')
			:css('clear', 'both')
			:css('margin', '1em 0 0 0')
			:css('border', '1px solid #aaa')
			:css('background', args.couleur or '#ecfcf4')
			: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 des modules, en rangeant à part les modules de données
	if page.namespace == 828 and page.subpageText ~= 'Bac à sable' and page.subpageText ~= 'Test' then
		if page.isSubpage and page.baseText == 'Carte/données' then
			res:wikitext("[[Catégorie:Module de paramétrage de carte]]")
		elseif page.isSubpage and page.baseText == 'Country data' then
			res:wikitext("[[Catégorie:Module d'informations pays]]")
		else
			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
		if val ~= '' then
			args[cle] = mw.text.trim(val)
		end
	end

	return p._documentation(args)
end

function p.nomDocumentation(frame)
	if frame.args[1] and mw.text.trim(frame.args[1]) ~= '' then
		return frame.args[1]
	else
		local titreDoc = nomDocumentation(mw.title.getCurrentTitle())
		if mw.title.new(titreDoc).exists then
			return titreDoc
		end 
	end
end

return p