Module:Documentation

De Baripedia
Révision datée du 17 décembre 2013 à 00:05 par Arthur (discussion | contributions) (1 version)
(diff) ◂ Version précédente | Voir la version actuelle (diff) | Version suivante ▸ (diff)

This module displays a blue box containing documentation for templates, Lua modules, or other pages. It is usually run using the {{documentation}} template.

Normal usage

For most uses, this module should be called from the {{documentation}} template. Please see the template page for usage instructions and a list of parameters.

Use in other modules

To use this module from another Lua module, first load it with require:

<source lang="lua"> local documentation = require('Module:Documentation').main </source>

Then you can simply call it using a table of arguments. <source lang="lua"> documentation{content = 'Some documentation', ['link box'] = 'My custom link box'} </source>

Please refer to the template documentation for usage instructions and a list of parameters.

Porting to other wikis

The module has a configuration file at Module:Documentation/config which is intended to allow easy translation and porting to other wikis. Please see the code comments in the config page for instructions. If you have any questions, or you need a feature which is not currently implemented, please leave a message at Template talk:Documentation to get the attention of a developer.


Erreur de script : Erreur Lua : impossible de créer le processus : proc_open n’est pas disponible. Vérifiez la directive de configuration PHP « disable_functions ».

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

local TableBuilder = require('Module:TableBuilder')
 
function p.corps(frame)
    args = frame:getParent().args
    local page = mw.title.getCurrentTitle()
    doc = p.docname(page)
    tab = TableBuilder.new()

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

    return tab.concat()
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 or not mw.title.new(page).exists then return false end
    return true
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')
    else tab.insert(args.couleur) end
 
    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)
    else tab.insert('Documentation') end
    tab.insert('</span>')

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

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

    return tab.concat()
end
 
function p.contenu(frame, page)
    local arg = args[1] or doc

    if args.contenu then
        tab.insert('\n')
           .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()
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
            tab.insert('[[' .. bacasable .. '|bac à sable]]')
               .insert('&nbsp;<span style="font-size:89%; font-style:normal;">([')
               .insert(argbacasable:fullUrl('action=edit'))
               .insert(' modifier])</span>')
        else
            tab.insert('bac à sable&nbsp;<span style="font-size:89%; font-style:normal;">([')
               .insert(argbacasable:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload2"}))
               .insert(' créer])</span>')
        end
        tab.insert(' et la page de ')
 
        local test = arg.subjectNsText .. ":" .. arg.baseText .. "/Test"
        local argtest = mw.title.new(test)
        if p.ifexist(test) then
            tab.insert('[[' .. test .. '|test]]')
               .insert('&nbsp;<span style="font-size:89%; font-style:normal;">([')
               .insert(argtest:fullUrl('action=edit'))
               .insert(' modifier])</span>')
        else
            tab.insert('test&nbsp;<span style="font-size:89%; font-style:normal;">([')
               .insert(argtest:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload3"}))
               .insert(' créer])</span>')
        end
 
        tab.insert('.<br />Veuillez placer les catégories dans la sous-page ')
           .insert('<span class="plainlinks">[')
 
        if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
            tab.insert(arg:fullUrl('action=edit'))
        else
            tab.insert(arg:fullUrl({["action"]="edit", ["preload"]="Modèle:Documentation/Preload"}))
        end
        tab.insert(' /Documentation].')
    end
    tab.insert('</p></div></div>')

    return tab.concat()
end

return p