« Module:Documentation » : différence entre les versions
Aller à la navigation
Aller à la recherche
Modèle>Orlodrim m (A modifié le niveau de protection de « Module:Documentation » ([Modifier=Autoriser uniquement les utilisateurs auto-confirmés] (infini) [Renommer=Autoriser uniquement les administrateurs] (infini))) |
Modèle>Hlm Z. (importation du bac à sable ; uti) |
||
| Ligne 3 : | Ligne 3 : | ||
local p = {} | local p = {} | ||
function p.documentation(frame) | |||
local args = frame:getParent().args | |||
function p. | 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', {selfClosing = true}) | |||
:done() | |||
:wikitext(frame:preprocess('{{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)) | |||
:node(contenu(args, titreDoc, existeDoc)) | |||
:node(notice(args, page, doc, existeDoc)) | |||
return tostring(res) | |||
end | end | ||
function | 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 | end | ||
function | function existePage(page) | ||
return page and page.exists | |||
end | end | ||
function lienUrl(nomPage, titrePage, action, pagePreload) | |||
local argument = {} | |||
if pagePreload then | |||
argument = { | |||
['action'] = action or 'edit', | |||
['preload'] = 'Modèle:Documentation/Preload' .. pagePreload} | |||
else | |||
argument = {['action'] = action or 'edit'} | |||
end | |||
return mw.ustring.format('[%s %s]', nomPage:fullUrl(argument), titrePage) | |||
end | |||
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=Documentation|link=]]') | |||
:tag('span') | |||
:css('font-weight', 'bold') | |||
:css('font-size', '125%') | |||
:wikitext(' ') | |||
:wikitext(args.titre or 'Documentation') | |||
:done() | |||
if not args.contenu then | if not args.contenu then | ||
local editionLien = res:tag('span') | |||
:addClass('mw-editsection plainlinks') | |||
:wikitext('[') | |||
if existeDoc then | |||
editionLien | |||
:wikitext(lienUrl(doc, 'modifier')) | |||
else | |||
editionLien | |||
:wikitext(lienUrl(doc, 'créer', 'edit', '')) | |||
end | |||
editionLien | |||
:wikitext('] [') | |||
:wikitext(lienUrl(page, 'purger', 'purge')) | |||
:wikitext(']') | |||
end | |||
return tostring(res) | |||
end | end | ||
function contenu(args, titreDoc, existeDoc) | |||
local res = mw.html.create(''):newline() | |||
if args.contenu then | |||
res:wikitext(args.contenu) | |||
elseif existeDoc then | |||
local frame = mw.getCurrentFrame() | |||
local contenuDoc = args[1] or titreDoc or '' | |||
res:wikitext(frame:expandTemplate{title = contenuDoc}) | |||
end | |||
res | |||
:newline() | |||
:tag('div', {selfClosing = true}) | |||
:css('clear', 'both') | |||
return tostring(res) | |||
end | end | ||
function notice(args, page, doc, existeDoc) | |||
local res = mw.html.create('div') | |||
if args.contenu or existeDoc then | |||
res | |||
:css('border-top', '1px solid #aaa') | |||
:css('margin', '1em 0 0') | |||
end | |||
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) | |||
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('.') | |||
end | |||
else | |||
if existeDoc then | |||
contenuParagraphe | |||
:wikitext('La [[Aide:Documentation de modèle|documentation]] ') | |||
:wikitext('de ce [[Aide:Modèle|modèle]] est ') | |||
:wikitext('[[Aide:Inclusion|incluse]] depuis sa [[') | |||
:wikitext(tostring(doc)) | |||
:wikitext('|sous-page de documentation]] ') | |||
:tag('span') | |||
:css('font-size', '89%') | |||
:css('font-style', 'normal') | |||
:wikitext('(') | |||
:wikitext(lienUrl(doc, 'modifier')) | |||
:wikitext(' | ') | |||
:wikitext(lienUrl(doc, 'historique', 'history')) | |||
:wikitext(').<br />') | |||
:done() | |||
end | |||
contenuParagraphe:wikitext('Les éditeurs peuvent travailler dans le ') | |||
local titrePageBacasable = doc.subjectNsText .. ':' .. doc.baseText .. '/Bac à sable' | |||
local pageBacasable = mw.title.new(titrePageBacasable) | |||
if existePage(pageBacasable) then | |||
contenuParagraphe | |||
:wikitext('[[' .. titrePageBacasable .. '|bac à sable]] ') | |||
:tag('span') | |||
:css('font-size', '89%') | |||
:css('font-style', 'normal') | |||
:wikitext('(') | |||
:wikitext(lienUrl(pageBacasable, 'modifier')) | |||
:wikitext(')') | |||
else | |||
contenuParagraphe | |||
:wikitext('bac à sable ') | |||
:tag('span') | |||
:css('font-size', '89%') | |||
:css('font-style', 'normal') | |||
:wikitext('(') | |||
:wikitext(lienUrl(pageBacasable, 'créer', 'edit', '2')) | |||
:wikitext(')') | |||
end | |||
contenuParagraphe:wikitext(' et la page de ') | |||
local titrePageTest = doc.subjectNsText .. ':' .. doc.baseText .. '/Test' | |||
local pageTest = mw.title.new(titrePageTest) | |||
if existePage(pageTest) then | |||
contenuParagraphe | |||
:wikitext('[[' .. titrePageTest .. '|test]] ') | |||
:tag('span') | |||
:css('font-size', '89%') | |||
:css('font-style', 'normal') | |||
:wikitext('(') | |||
:wikitext(lienUrl(pageTest, 'modifier')) | |||
:wikitext(')') | |||
else | |||
contenuParagraphe | |||
:wikitext('test ') | |||
:tag('span') | |||
:css('font-size', '89%') | |||
:css('font-style', 'normal') | |||
:wikitext('(') | |||
:wikitext(lienUrl(pageTest, 'créer', 'edit', '3')) | |||
:wikitext(')') | |||
end | |||
contenuParagraphe | |||
:wikitext('.<br />Veuillez placer les catégories dans la sous-page ') | |||
if existeDoc then | |||
contenuParagraphe:wikitext(lienUrl(doc, '/Documentation')) | |||
else | |||
contenuParagraphe:wikitext(lienUrl(doc, '/Documentation', 'edit', '')) | |||
end | |||
contenuParagraphe:wikitext('.') | |||
end | |||
return tostring(res) | |||
end | end | ||
return p | return p | ||
Version du 7 mars 2014 à 18:05
La documentation pour ce module peut être créée à Module:Documentation/doc
--Ce module implémente le modèle {{Documentation}}.
local p = {}
function p.documentation(frame)
local args = frame:getParent().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', {selfClosing = true})
:done()
:wikitext(frame:preprocess('{{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))
:node(contenu(args, titreDoc, existeDoc))
:node(notice(args, page, doc, existeDoc))
return tostring(res)
end
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
function existePage(page)
return page and page.exists
end
function lienUrl(nomPage, titrePage, action, pagePreload)
local argument = {}
if pagePreload then
argument = {
['action'] = action or 'edit',
['preload'] = 'Modèle:Documentation/Preload' .. pagePreload}
else
argument = {['action'] = action or 'edit'}
end
return mw.ustring.format('[%s %s]', nomPage:fullUrl(argument), titrePage)
end
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=Documentation|link=]]')
:tag('span')
:css('font-weight', 'bold')
:css('font-size', '125%')
:wikitext(' ')
:wikitext(args.titre or 'Documentation')
:done()
if not args.contenu then
local editionLien = res:tag('span')
:addClass('mw-editsection plainlinks')
:wikitext('[')
if existeDoc then
editionLien
:wikitext(lienUrl(doc, 'modifier'))
else
editionLien
:wikitext(lienUrl(doc, 'créer', 'edit', ''))
end
editionLien
:wikitext('] [')
:wikitext(lienUrl(page, 'purger', 'purge'))
:wikitext(']')
end
return tostring(res)
end
function contenu(args, titreDoc, existeDoc)
local res = mw.html.create(''):newline()
if args.contenu then
res:wikitext(args.contenu)
elseif existeDoc then
local frame = mw.getCurrentFrame()
local contenuDoc = args[1] or titreDoc or ''
res:wikitext(frame:expandTemplate{title = contenuDoc})
end
res
:newline()
:tag('div', {selfClosing = true})
:css('clear', 'both')
return tostring(res)
end
function notice(args, page, doc, existeDoc)
local res = mw.html.create('div')
if args.contenu or existeDoc then
res
:css('border-top', '1px solid #aaa')
:css('margin', '1em 0 0')
end
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)
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('.')
end
else
if existeDoc then
contenuParagraphe
:wikitext('La [[Aide:Documentation de modèle|documentation]] ')
:wikitext('de ce [[Aide:Modèle|modèle]] est ')
:wikitext('[[Aide:Inclusion|incluse]] depuis sa [[')
:wikitext(tostring(doc))
:wikitext('|sous-page de documentation]] ')
:tag('span')
:css('font-size', '89%')
:css('font-style', 'normal')
:wikitext('(')
:wikitext(lienUrl(doc, 'modifier'))
:wikitext(' | ')
:wikitext(lienUrl(doc, 'historique', 'history'))
:wikitext(').<br />')
:done()
end
contenuParagraphe:wikitext('Les éditeurs peuvent travailler dans le ')
local titrePageBacasable = doc.subjectNsText .. ':' .. doc.baseText .. '/Bac à sable'
local pageBacasable = mw.title.new(titrePageBacasable)
if existePage(pageBacasable) then
contenuParagraphe
:wikitext('[[' .. titrePageBacasable .. '|bac à sable]] ')
:tag('span')
:css('font-size', '89%')
:css('font-style', 'normal')
:wikitext('(')
:wikitext(lienUrl(pageBacasable, 'modifier'))
:wikitext(')')
else
contenuParagraphe
:wikitext('bac à sable ')
:tag('span')
:css('font-size', '89%')
:css('font-style', 'normal')
:wikitext('(')
:wikitext(lienUrl(pageBacasable, 'créer', 'edit', '2'))
:wikitext(')')
end
contenuParagraphe:wikitext(' et la page de ')
local titrePageTest = doc.subjectNsText .. ':' .. doc.baseText .. '/Test'
local pageTest = mw.title.new(titrePageTest)
if existePage(pageTest) then
contenuParagraphe
:wikitext('[[' .. titrePageTest .. '|test]] ')
:tag('span')
:css('font-size', '89%')
:css('font-style', 'normal')
:wikitext('(')
:wikitext(lienUrl(pageTest, 'modifier'))
:wikitext(')')
else
contenuParagraphe
:wikitext('test ')
:tag('span')
:css('font-size', '89%')
:css('font-style', 'normal')
:wikitext('(')
:wikitext(lienUrl(pageTest, 'créer', 'edit', '3'))
:wikitext(')')
end
contenuParagraphe
:wikitext('.<br />Veuillez placer les catégories dans la sous-page ')
if existeDoc then
contenuParagraphe:wikitext(lienUrl(doc, '/Documentation'))
else
contenuParagraphe:wikitext(lienUrl(doc, '/Documentation', 'edit', ''))
end
contenuParagraphe:wikitext('.')
end
return tostring(res)
end
return p