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

De Lagny-sur-Marne Wiki
Aller à la navigation Aller à la recherche
0x010D (discussion | contributions)
Aucun résumé des modifications
0x010D (discussion | contributions)
amélioration partielle
Ligne 5 : Ligne 5 :
function p.corps(frame)
function p.corps(frame)
     local args = frame:getParent().args
     local args = frame:getParent().args
    local page = mw.title.getCurrentTitle()
     local corps = {}
     local corps = {}


     --Bandeau pour les sous-pages /Bac à sable
     --Bandeau pour les sous-pages /Bac à sable
     if mw.title.getCurrentTitle().subpageText == 'Bac à sable' then
     if page.subpageText == 'Bac à sable' then
         table.insert(corps, '<div style="clear:both />')
         table.insert(corps, '<div style="clear:both />')
         table.insert(corps, frame:preprocess('{{Sous-page de bac à sable}}'))
         table.insert(corps, frame:preprocess('{{Sous-page de bac à sable}}'))
Ligne 14 : Ligne 15 :


     --Génération de la documentation
     --Génération de la documentation
     table.insert(corps, frame:preprocess(p.entete(frame, args)))
     table.insert(corps, frame:preprocess(p.entete(frame, args, page)))
     table.insert(corps, p.contenu(frame, args))
     table.insert(corps, p.contenu(frame, args, page))
     table.insert(corps, frame:preprocess(p.notice(frame, args)))
     table.insert(corps, frame:preprocess(p.notice(frame, args, page)))


     --Code HTML brut
     --Code HTML brut
Ligne 33 : Ligne 34 :
end
end


function p.docname(frame)
function p.docname(page)
     local page = mw.title.getCurrentTitle()
     --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
     --On est dans une sous-page
        --On n'est pas 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"
         return page.subjectNsText .. ":" .. page.text .. "/Documentation"
    else
        --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
     end
end
end


function p.entete(frame, args)
function p.entete(frame, args, page)
     local entete = {'<div style="clear:both; margin:1em 0 0 0; border:1px solid #aaa; background:'}
     local entete = {'<div style="clear:both; margin:1em 0 0 0; border:1px solid #aaa; background:'}


Ligne 85 : Ligne 82 :
             end
             end
         else
         else
             if p.ifexist(p.docname(frame)) then
             if p.ifexist(p.docname(page)) then
                 table.insert(entete, p.docname(frame))
                 table.insert(entete, p.docname(page))
                 table.insert(entete, '|action=edit modifier}}]&#93;&#32;&#91;{{Purger le cache|purger}}')
                 table.insert(entete, '|action=edit modifier}}]&#93;&#32;&#91;{{Purger le cache|purger}}')
             else
             else
                 table.insert(entete, p.docname(frame))
                 table.insert(entete, p.docname(page))
                 table.insert(entete, '|action=edit&preload=Modèle:Documentation/Preload créer}}]')
                 table.insert(entete, '|action=edit&preload=Modèle:Documentation/Preload créer}}]')
             end
             end
Ligne 100 : Ligne 97 :
end
end


function p.contenu(frame, args)
function p.contenu(frame, args, page)
     local contenu = {}
     local contenu = {}
     if args.contenu then
     if args.contenu then
Ligne 112 : Ligne 109 :
         and p.ifexist(args[1]) then
         and p.ifexist(args[1]) then
             table.insert(contenu, frame:preprocess('{{' .. args[1] .. '}}'))
             table.insert(contenu, frame:preprocess('{{' .. args[1] .. '}}'))
         elseif frame:preprocess('{{FULLPAGENAMEE}}') ~= frame:preprocess('{{FULLPAGENAMEE:' .. p.docname(frame) .. '}}')
         elseif frame:preprocess('{{FULLPAGENAMEE}}') ~= frame:preprocess('{{FULLPAGENAMEE:' .. p.docname(page) .. '}}')
         and p.ifexist(p.docname(frame)) then
         and p.ifexist(p.docname(page)) then
             table.insert(contenu, frame:preprocess('{{' .. p.docname(frame) .. '}}'))
             table.insert(contenu, frame:preprocess('{{' .. p.docname(page) .. '}}'))
         end
         end
     end
     end
Ligne 123 : Ligne 120 :
end
end


function p.notice(frame, args)
function p.notice(frame, args, page)
     local notice = {}
     local notice = {}


Ligne 136 : Ligne 133 :
             table.insert(notice, 'est directement [[Aide:Inclusion|incluse]] dans le corps de ce dernier.<br />')
             table.insert(notice, 'est directement [[Aide:Inclusion|incluse]] dans le corps de ce dernier.<br />')
             table.insert(notice, 'Si cette page est protégée, veuillez transférer le contenu de la documentation vers sa ')
             table.insert(notice, 'Si cette page est protégée, veuillez transférer le contenu de la documentation vers sa ')
             table.insert(notice, '[{{fullurl:' .. p.docname(frame))
             table.insert(notice, '[{{fullurl:' .. p.docname(page))
             table.insert(notice, '|action=edit&preload=Modèle:Documentation/Preload sous-page dédiée}}].')
             table.insert(notice, '|action=edit&preload=Modèle:Documentation/Preload sous-page dédiée}}].')
         end
         end
     else
     else
         if args[1] and p.ifexist(args[1]) or p.ifexist(p.docname(frame)) then
         if args[1] and p.ifexist(args[1]) or p.ifexist(p.docname(page)) then
             table.insert(notice, '<div class="plainlinks" style="border-top:1px solid #aaa; margin: 1em 0 0;">')
             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, '<p style="margin-bottom:0; padding-left:1em; font-style:italic;">')
Ligne 149 : Ligne 146 :
                 table.insert(notice, '[[' .. args[1] .. '|sous-page de documentation]]')
                 table.insert(notice, '[[' .. args[1] .. '|sous-page de documentation]]')
             else
             else
                 table.insert(notice, '[[' .. p.docname(frame) .. '|sous-page de documentation]]')
                 table.insert(notice, '[[' .. p.docname(page) .. '|sous-page de documentation]]')
             end
             end


Ligne 160 : Ligne 157 :
                 table.insert(notice, args[1] .. '|action=history}} historique]')
                 table.insert(notice, args[1] .. '|action=history}} historique]')
             else
             else
                 table.insert(notice, p.docname(frame) .. '|action=edit}} modifier]')
                 table.insert(notice, p.docname(page) .. '|action=edit}} modifier]')
                 table.insert(notice, '&nbsp;|&nbsp;[{{fullurl:')
                 table.insert(notice, '&nbsp;|&nbsp;[{{fullurl:')
                 table.insert(notice, p.docname(frame) .. '|action=history}} historique]')
                 table.insert(notice, p.docname(page) .. '|action=history}} historique]')
             end
             end
             table.insert(notice, ')</span>.<br />')
             table.insert(notice, ')</span>.<br />')
Ligne 172 : Ligne 169 :


         if args[1] and p.ifexist(frame:preprocess('{{#rel2abs:' .. args[1] .. '/../Bac à sable}}'))
         if args[1] and p.ifexist(frame:preprocess('{{#rel2abs:' .. args[1] .. '/../Bac à sable}}'))
         or p.ifexist(frame:preprocess('{{#rel2abs:' .. p.docname(frame) .. '/../Bac à sable}}')) then
         or p.ifexist(frame:preprocess('{{#rel2abs:' .. p.docname(page) .. '/../Bac à sable}}')) then
             table.insert(notice, '[[{{#rel2abs:')
             table.insert(notice, '[[{{#rel2abs:')
             if args[1] then
             if args[1] then
                 table.insert(notice, args[1])
                 table.insert(notice, args[1])
             else
             else
                 table.insert(notice, p.docname(frame))
                 table.insert(notice, p.docname(page))
             end
             end
             table.insert(notice, '/../Bac à sable}}|bac à sable]]')
             table.insert(notice, '/../Bac à sable}}|bac à sable]]')
Ligne 185 : Ligne 182 :
                 table.insert(notice, args[1])
                 table.insert(notice, args[1])
             else
             else
                 table.insert(notice, p.docname(frame))
                 table.insert(notice, p.docname(page))
             end
             end
             table.insert(notice, '/../Bac à sable}}|action=edit}} modifier])</span>')
             table.insert(notice, '/../Bac à sable}}|action=edit}} modifier])</span>')
Ligne 194 : Ligne 191 :
                 table.insert(notice, args[1])
                 table.insert(notice, args[1])
             else
             else
                 table.insert(notice, p.docname(frame))
                 table.insert(notice, p.docname(page))
             end
             end
             table.insert(notice, '/../Bac à sable}}|action=edit&preload=Modèle:Documentation/Preload2}} créer]')
             table.insert(notice, '/../Bac à sable}}|action=edit&preload=Modèle:Documentation/Preload2}} créer]')
Ligne 202 : Ligne 199 :


         if args[1] and p.ifexist(frame:preprocess('{{#rel2abs:' .. args[1] .. '/../Test}}'))
         if args[1] and p.ifexist(frame:preprocess('{{#rel2abs:' .. args[1] .. '/../Test}}'))
         or p.ifexist(frame:preprocess('{{#rel2abs:' .. p.docname(frame) .. '/../Test}}')) then
         or p.ifexist(frame:preprocess('{{#rel2abs:' .. p.docname(page) .. '/../Test}}')) then
             table.insert(notice, '[[{{#rel2abs:')
             table.insert(notice, '[[{{#rel2abs:')
             if args[1] then
             if args[1] then
                 table.insert(notice, args[1])
                 table.insert(notice, args[1])
             else
             else
                 table.insert(notice, p.docname(frame))
                 table.insert(notice, p.docname(page))
             end
             end
             table.insert(notice, '/../Test}}|test]]')
             table.insert(notice, '/../Test}}|test]]')
Ligne 215 : Ligne 212 :
                 table.insert(notice, args[1])
                 table.insert(notice, args[1])
             else
             else
                 table.insert(notice, p.docname(frame))
                 table.insert(notice, p.docname(page))
             end
             end
             table.insert(notice, '/../Test}}|action=edit}} modifier])</span>')
             table.insert(notice, '/../Test}}|action=edit}} modifier])</span>')
Ligne 224 : Ligne 221 :
                 table.insert(notice, args[1])
                 table.insert(notice, args[1])
             else
             else
                 table.insert(notice, p.docname(frame))
                 table.insert(notice, p.docname(page))
             end
             end
             table.insert(notice, '/../Test}}|action=edit&preload=Modèle:Documentation/Preload3}} créer]')
             table.insert(notice, '/../Test}}|action=edit&preload=Modèle:Documentation/Preload3}} créer]')
Ligne 232 : Ligne 229 :
         table.insert(notice, '<span class="plainlinks">[')
         table.insert(notice, '<span class="plainlinks">[')
         table.insert(notice, '{{fullurl:')
         table.insert(notice, '{{fullurl:')
         if args[1] and p.ifexist(args[1]) or p.ifexist(p.docname(frame)) then
         if args[1] and p.ifexist(args[1]) or p.ifexist(p.docname(page)) then
             if args[1] then
             if args[1] then
                 table.insert(notice, args[1])
                 table.insert(notice, args[1])
             else
             else
                 table.insert(notice, p.docname(frame))
                 table.insert(notice, p.docname(page))
             end
             end
             table.insert(notice, '|action=edit')
             table.insert(notice, '|action=edit')
Ligne 244 : Ligne 241 :
                 table.insert(notice, args[1])
                 table.insert(notice, args[1])
             else
             else
                 table.insert(notice, p.docname(frame))
                 table.insert(notice, p.docname(page))
             end
             end
             table.insert(notice, '|action=edit&preload=Modèle:Documentation/Preload')
             table.insert(notice, '|action=edit&preload=Modèle:Documentation/Preload')

Version du 23 juillet 2013 à 10:33

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

local p = {}

function p.corps(frame)

   local args = frame:getParent().args
   local page = mw.title.getCurrentTitle()
   local corps = {}
   --Bandeau pour les sous-pages /Bac à sable
   if page.subpageText == 'Bac à sable' then

table.insert(corps, '

')
       table.insert(corps, frame:preprocess('Modèle:Sous-page de bac à sable'))
   end
   --Génération de la documentation
   table.insert(corps, frame:preprocess(p.entete(frame, args, page)))
   table.insert(corps, p.contenu(frame, args, page))
   table.insert(corps, frame:preprocess(p.notice(frame, args, page)))
   --Code HTML brut
   if args.raw then
       return frame:preprocess('' .. table.concat(corps) .. '')
   end
   return table.concat(corps)

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.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.entete(frame, args, page)

local entete = {'
') table.insert(entete, '
')
   table.insert(entete, 'Documentation du modèle')
   table.insert(entete, ' ')
   if args.titre then
       table.insert(entete, args.titre)
   else
       table.insert(entete, 'Documentation')
   end
   table.insert(entete, '')
   if not args.contenu then
       table.insert(entete, '[[')
       table.insert(entete, '{{fullurl:')
       if args[1] then
           if p.ifexist(args[1]) then
               table.insert(entete, args[1])
               table.insert(entete, '|action=edit modifier}}]] [Modèle:Purger le cache')
           else
               table.insert(entete, args[1])
               table.insert(entete, '|action=edit&preload=Modèle:Documentation/Preload créer}}]')
           end
       else
           if p.ifexist(p.docname(page)) then
               table.insert(entete, p.docname(page))
               table.insert(entete, '|action=edit modifier}}]] [Modèle:Purger le cache')
           else
               table.insert(entete, p.docname(page))
               table.insert(entete, '|action=edit&preload=Modèle:Documentation/Preload créer}}]')
           end
       end
       table.insert(entete, ']')
   end
table.insert(entete, '
')
   return table.concat(entete)

end

function p.contenu(frame, args, page)

   local contenu = {}
   if args.contenu then
       table.insert(contenu, '\n')
       table.insert(contenu, args.contenu)
   else
       table.insert(contenu, frame:preprocess('\n'))
       --Évite toute récursion
       if args[1]
       and frame:preprocess('Module:Documentation') ~= frame:preprocess()
       and p.ifexist(args[1]) then
           table.insert(contenu, frame:preprocess('{{' .. args[1] .. '}}'))
       elseif frame:preprocess('Module:Documentation') ~= frame:preprocess('%27_.._p.docname(page)_.._%27')
       and p.ifexist(p.docname(page)) then
           table.insert(contenu, frame:preprocess('Modèle:' .. p.docname(page) .. ''))
       end
   end
table.insert(contenu, frame:preprocess('\n
\n'))
   return table.concat(contenu)

end

function p.notice(frame, args, page)

   local notice = {}
   if args.contenu then
table.insert(notice, '