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

De Lagny-sur-Marne Wiki
Aller à la navigation Aller à la recherche
0x010D (discussion | contributions)
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))
0x010D (discussion | contributions)
importation du bac à sable ; uti
Ligne 3 : Ligne 3 :
local p = {}
local p = {}


local TableBuilder = require('Module:TableBuilder')
function p.documentation(frame)
local args = frame:getParent().args
function p.corps(frame)
local page = mw.title.getCurrentTitle()
    args = frame:getParent().args
local titreDoc = nomDocumentation(page)
    local page = mw.title.getCurrentTitle()
local doc = mw.title.new(args[1] or titreDoc)
    doc = p.docname(page)
local existeDoc = existePage(doc)
    tab = TableBuilder.new()
local res = mw.html.create('')


    --Bandeau pour les sous-pages /Bac à sable
--Bandeau pour les sous-pages /Bac à sable
    if page.subpageText == 'Bac à sable' then
if page.subpageText == 'Bac à sable' then
        tab.insert('<div style="clear:both />')
res
          .insert(frame:preprocess('{{Sous-page de bac à sable}}'))
:tag('div', {selfClosing = true})
    end
:done()
:wikitext(frame:preprocess('{{Sous-page de bac à sable}}'))
    --Génération de la documentation
end
    p.entete(page)
    p.contenu(frame, page)
    p.notice(page)


    return tab.concat()
--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 p.docname(page)
function nomDocumentation(page)
    --On n'est pas dans une sous-page
--On n'est pas dans une sous-page
    if not page.isSubpage then return page.subjectNsText .. ":" .. page.text .. "/Documentation" end
if not page.isSubpage then
return page.subjectNsText .. ':' .. page.text .. '/Documentation'
    --On est dans une sous-page
end
    if page.subpageText == 'Documentation'
 
    or page.subpageText == 'Bac à sable'
--On est dans une sous-page
    or page.subpageText == 'Test' then
local sousPage = page.subpageText
        return page.subjectNsText .. ":" .. page.baseText .. "/Documentation"
if sousPage == 'Documentation'
    else
or sousPage == 'Bac à sable'
        return page.subjectNsText .. ":" .. page.text .. "/Documentation"
or sousPage == 'Test' then
    end
return page.subjectNsText .. ':' .. page.baseText .. '/Documentation'
else
return page.subjectNsText .. ':' .. page.text .. '/Documentation'
end
end
end
 
function p.ifexist(page)
function existePage(page)
    if not page or not mw.title.new(page).exists then return false end
return page and page.exists
    return true
end
end
function p.entete(page)
    tab.insert('<div style="clear:both; margin:1em 0 0 0; border:1px solid #aaa; background:')


    if not args.couleur then tab.insert('#ecfcf4')
function lienUrl(nomPage, titrePage, action, pagePreload)
    else tab.insert(args.couleur) end
local argument = {}
    tab.insert('; padding:1em 1em 0.8em;">')
      .insert('<div style="margin-bottom:1ex; border-bottom:1px solid #aaa; padding-bottom:3px;">')
      .insert('[[Fichier:Template-info.png|50px|alt=Documentation du modèle|link=]]')
      .insert('<span style="font-weight:bold; font-size:125%">&nbsp;')


    if args.titre then tab.insert(args.titre)
if pagePreload then
    else tab.insert('Documentation') end
argument = {
    tab.insert('</span>')
['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('&nbsp;')
:wikitext(args.titre or 'Documentation')
:done()


if not args.contenu then
if not args.contenu then
        local arg = mw.title.new(args[1] or doc)
local editionLien = res:tag('span')
        tab.insert('<span class="mw-editsection plainlinks">&#91;[')
:addClass('mw-editsection plainlinks')
:wikitext('&#91;')


        if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
if existeDoc then
            tab.insert(arg:fullUrl('action=edit'))
editionLien
              .insert(' modifier')
:wikitext(lienUrl(doc, 'modifier'))
        else
else
            tab.insert(arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"}))
editionLien
              .insert(' créer')
:wikitext(lienUrl(doc, 'créer', 'edit', ''))
        end
end
        tab.insert(']&#93;&#32;&#91;[')
        tab.insert(page:fullUrl('action=purge') .. ' purger]')
          .insert('&#93;</span>')
    end
tab.insert('</div>')


    return tab.concat()
editionLien
:wikitext('&#93;&#32;&#91;')
:wikitext(lienUrl(page, 'purger', 'purge'))
:wikitext('&#93;')
end
 
return tostring(res)
end
end
function p.contenu(frame, page)
    local arg = args[1] or doc


    if args.contenu then
function contenu(args, titreDoc, existeDoc)
        tab.insert('\n')
local res = mw.html.create(''):newline()
          .insert(args.contenu)
    else
        tab.insert(frame:preprocess('<nowiki />'))
          .insert('\n')
        if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
            tab.insert(frame:preprocess('{{' .. arg .. '}}'))
        end
    end
    tab.insert('\n')
      .insert(frame:preprocess('<nowiki />'))
      .insert('<div style="clear:both" />\n')


    return tab.concat()
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 p.notice(page)
    local arg = mw.title.new(args[1] or doc)
    if args.contenu then
        tab.insert('<div class="plainlinks" style="border-top:1px solid #aaa; margin: 1em 0 0;">')
          .insert('<p style="margin-bottom:0; padding-left:1em; font-style:italic;">\n')
        if args.notice then
            tab.insert(args.notice)
        else
            tab.insert('La [[Aide:Documentation de modèle|documentation]] de ce ')
              .insert('[[Aide:Modèle|modèle]] est directement [[Aide:Inclusion|incluse]] ')
              .insert('dans le corps de ce dernier. [')
              .insert(page:fullUrl('action=purge'))
  .insert(' Cliquez ici pour purger le cache].')
              .insert('<br />Si cette page est protégée, ')
              .insert('veuillez transférer le contenu de la documentation vers sa [')
              .insert(arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"}))
              .insert(' sous-page dédiée].')
        end
    else
        if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
            tab.insert('<div class="plainlinks" style="border-top:1px solid #aaa; margin: 1em 0 0;">')
              .insert('<p style="margin-bottom:0; padding-left:1em; font-style:italic;">')
              .insert('La [[Aide:Documentation de modèle|documentation]] de ce ')
              .insert('[[Aide:Modèle|modèle]] est [[Aide:Inclusion|incluse]] depuis sa [[')
              .insert(tostring(arg) .. '|sous-page de documentation]]')
              .insert('&nbsp;<span style="font-size:89%; font-style:normal;">([')
              .insert(arg:fullUrl('action=edit'))
              .insert(' modifier]&nbsp;|&nbsp;[')
              .insert(arg:fullUrl('action=history') .. ' historique])</span>.<br />')
        else
            tab.insert('<div class="plainlinks">')
              .insert('<p style="margin-bottom:0; padding-left:1em; font-style:italic;">')
        end
        tab.insert('Les éditeurs peuvent travailler dans le ')
        local bacasable = arg.subjectNsText .. ":" .. arg.baseText .. "/Bac à sable"
        local argbacasable = mw.title.new(bacasable)


        if p.ifexist(bacasable) then
function notice(args, page, doc, existeDoc)
            tab.insert('[[' .. bacasable .. '|bac à sable]]')
local res = mw.html.create('div')
              .insert('&nbsp;<span style="font-size:89%; font-style:normal;">([')
 
              .insert(argbacasable:fullUrl('action=edit'))
if args.contenu or existeDoc then
              .insert(' modifier])</span>')
res
        else
:css('border-top', '1px solid #aaa')
            tab.insert('bac à sable&nbsp;<span style="font-size:89%; font-style:normal;">([')
:css('margin', '1em 0 0')
              .insert(argbacasable:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload2"}))
end
              .insert(' créer])</span>')
 
        end
local contenuParagraphe = res
        tab.insert(' et la page de ')
:tag('p')
:addClass('plainlinks')
        local test = arg.subjectNsText .. ":" .. arg.baseText .. "/Test"
:css('margin-bottom', '0')
        local argtest = mw.title.new(test)
:css('padding-left', '1em')
        if p.ifexist(test) then
:css('font-style', 'italic')
            tab.insert('[[' .. test .. '|test]]')
 
              .insert('&nbsp;<span style="font-size:89%; font-style:normal;">([')
if args.contenu then
              .insert(argtest:fullUrl('action=edit'))
if args.notice then
              .insert(' modifier])</span>')
contenuParagraphe:wikitext(args.notice)
        else
else
            tab.insert('test&nbsp;<span style="font-size:89%; font-style:normal;">([')
contenuParagraphe
              .insert(argtest:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload3"}))
:wikitext('La [[Aide:Documentation de modèle|documentation]] ')
              .insert(' créer])</span>')
:wikitext('de ce [[Aide:Modèle|modèle]] est directement ')
        end
:wikitext('[[Aide:Inclusion|incluse]] dans le corps de ce dernier. ')
:wikitext(lienUrl(page, 'Cliquez ici pour purger le cache', 'purge'))
        tab.insert('.<br />Veuillez placer les catégories dans la sous-page ')
:wikitext('.<br />Si cette page est protégée, veuillez ')
          .insert('<span class="plainlinks">[')
:wikitext('transférer le contenu de la documentation vers sa ')
:wikitext(lienUrl(doc, 'sous-page dédiée', 'edit', ''))
        if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
:wikitext('.')
            tab.insert(arg:fullUrl('action=edit'))
end
        else
else
            tab.insert(arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"}))
if existeDoc then
        end
contenuParagraphe
        tab.insert(' /Documentation].')
:wikitext('La [[Aide:Documentation de modèle|documentation]] ')
    end
:wikitext('de ce [[Aide:Modèle|modèle]] est ')
    tab.insert('</p></div></div>')
:wikitext('[[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()
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]]&nbsp;')
:tag('span')
:css('font-size', '89%')
:css('font-style', 'normal')
:wikitext('(')
:wikitext(lienUrl(pageBacasable, 'modifier'))
:wikitext(')')
else
contenuParagraphe
:wikitext('bac à sable&nbsp;')
: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]]&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
 
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 tab.concat()
return tostring(res)
end
end


return p
return p

Version du 7 mars 2014 à 18:05

--Ce module implémente le modèle Modèle:Méta documentation de modèle.

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('Modèle: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('Documentation')

: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 documentation ') :wikitext('de ce modèle est directement ') :wikitext('incluse dans le corps de ce dernier. ') :wikitext(lienUrl(page, 'Cliquez ici pour purger le cache', 'purge')) :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', )) :wikitext('.') end else if existeDoc then contenuParagraphe :wikitext('La documentation ') :wikitext('de ce modèle est ') :wikitext('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(').
') :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('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('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('.
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