Jump to content

Module:Documentation

From Simple English Wikipedia, the free encyclopedia
Revision as of 19:58, 29 July 2013 by 109.151.161.64 (talk) (Created page with "--Ce module implémente le modèle {{Documentation}}. local p = {} function p.corps(frame) args = frame:getParent().args local page = mw.title.getCurrentTitle() ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Please edit Module:Documentation


--Ce module implémente le modèle {{Documentation}}.
 
local p = {}
 
function p.corps(frame)
    args = frame:getParent().args
    local page = mw.title.getCurrentTitle()
    doc = p.docname(page)
    local corps = {}
 
    --Bandeau pour les sous-pages /Bac à sable
    if page.subpageText == 'Bac à sable' then
        table.insert(corps, '<div style="clear:both />')
        table.insert(corps, frame:preprocess('{{Sous-page de bac à sable}}'))
    end
 
    --Génération de la documentation
    table.insert(corps, p.entete(page))
    table.insert(corps, p.contenu(frame, page))
    table.insert(corps, p.notice(page))
 
    --Code HTML brut
    if args.raw then
        return frame:preprocess('<nowiki>' .. table.concat(corps) .. '</nowiki>\n:' .. os.clock())
    end
 
    return table.concat(corps)
end
 
function p.docname(page)
    --On n'est pas dans une sous-page
    if not page.isSubpage then return page.subjectNsText .. ":" .. page.text .. "/Documentation" end
 
    --On est dans une sous-page
    if page.subpageText == 'Documentation'
    or page.subpageText == 'Bac à sable'
    or page.subpageText == 'Test' then
        return page.subjectNsText .. ":" .. page.baseText .. "/Documentation"
    else
        return page.subjectNsText .. ":" .. page.text .. "/Documentation"
    end
end
 
function p.ifexist(page)
    if not page then return false end
    if mw.title.new(page).exists then return true end
    return false
end
 
function p.entete(page)
    local entete = {'<div style="clear:both; margin:1em 0 0 0; border:1px solid #aaa; background:'}
 
    if not args.couleur then table.insert(entete, '#ecfcf4')
    else table.insert(entete, args.couleur) end
 
    table.insert(entete, '; padding:1em 1em 0.8em;">')
    table.insert(entete, '<div style="margin-bottom:1ex; border-bottom:1px solid #aaa; padding-bottom:3px;">')
    table.insert(entete, '[[Fichier:Template-info.png|50px|alt=Documentation du modèle|link=]]')
    table.insert(entete, '<span style="font-weight:bold; font-size:125%">&nbsp;')
 
    if args.titre then table.insert(entete, args.titre)
    else table.insert(entete, 'Documentation') end
    table.insert(entete, '</span>')
 
    if not args.contenu then
        table.insert(entete, '<span class="mw-editsection plainlinks">&#91;[')
        local arg = mw.title.new(args[1] or doc)
 
        if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
            table.insert(entete, arg:fullUrl('action=edit') .. ' modifier]')
            table.insert(entete, '&#93;&#32;&#91;[')
            table.insert(entete, page:fullUrl('action=purge') .. ' purger]')
        else
            table.insert(entete, arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"}))
            table.insert(entete, ' créer]')
        end
        table.insert(entete, '&#93;</span>')
    end
 
    table.insert(entete, '</div>')
    return table.concat(entete)
end
 
function p.contenu(frame, page)
    local contenu = {}
    local arg = args[1] or doc
    if args.contenu then
        table.insert(contenu, '\n')
        table.insert(contenu, args.contenu)
    else
        table.insert(contenu, frame:preprocess('<nowiki />'))
        table.insert(contenu, '\n')
        if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
            table.insert(contenu, frame:preprocess('{{' .. arg .. '}}'))
        end
    end
 
    table.insert(contenu, '\n')
    table.insert(contenu, frame:preprocess('<nowiki />'))
    table.insert(contenu, '<div style="clear:both" />\n')
    return table.concat(contenu)
end
 
function p.notice(page)
    local notice = {}
    local arg = mw.title.new(args[1] or doc)
 
    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 ')
            table.insert(notice, '[[Aide:Modèle|modèle]] est directement [[Aide:Inclusion|incluse]] ')
            table.insert(notice, 'dans le corps de ce dernier.<br />Si cette page est protégée, ')
            table.insert(notice, 'veuillez transférer le contenu de la documentation vers sa [')
            table.insert(notice, arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"}))
            table.insert(notice, ' sous-page dédiée].')
        end
    else
        if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
            table.insert(notice, '<div class="plainlinks" style="border-top:1px solid #aaa; margin: 1em 0 0;">')
            table.insert(notice, '<p style="margin-bottom:0; padding-left:1em; font-style:italic;">')
            table.insert(notice, 'La [[Aide:Comment documenter un modèle ?|documentation]] de ce ')
            table.insert(notice, '[[Aide:Modèle|modèle]] est [[Aide:Inclusion|incluse]] depuis sa [[')
            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"
        local argbacasable = mw.title.new(bacasable)
        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, 'bacasable&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"
        local argtest = mw.title.new(test)
        if p.ifexist(test) then
            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 ')
        table.insert(notice, '<span class="plainlinks">[')
 
        if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
            table.insert(notice, arg:fullUrl('action=edit'))
        else
            table.insert(notice, arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"}))
        end
 
        table.insert(notice, ' /Documentation].')
    end
    table.insert(notice, '</p></div></div>')
    return table.concat(notice)
end
 
return p