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

De Lagny-sur-Marne Wiki
Aller à la navigation Aller à la recherche
0x010D (discussion | contributions)
test
0x010D (discussion | contributions)
provisoirement avant intégration totale de mw.title
Ligne 34 : Ligne 34 :


function p.docname(frame)
function p.docname(frame)
    local page = mw.title.getCurrentTitle()
     --On n'est pas dans une sous-page
     --On n'est pas dans une sous-page
     if frame:preprocess('{{BASEPAGENAME}}') == frame:preprocess('{{PAGENAME}}') then
     if not page.isSubpage then
         return frame:preprocess('{{SUBJECTPAGENAME}}/Documentation')
         return frame:preprocess('{{SUBJECTPAGENAME}}/Documentation')
     else
     else
         --On est dans une sous-page
         --On est dans une sous-page
         nom = frame:preprocess('{{SUBPAGENAME}}')
         local nom = page.subpageText
         if nom == 'Documentation' or nom == 'Bac à sable' or nom == 'Test' then
         if nom == 'Documentation' or nom == 'Bac à sable' or nom == 'Test' then
             return frame:preprocess('{{#rel2abs:../Documentation}}')
             return frame:preprocess('{{#rel2abs:../Documentation}}')

Version du 21 juillet 2013 à 21:46

--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 corps = {}
       
   --Bandeau pour les sous-pages /Bac à sable
   if frame:preprocess('Documentation') == '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)))
   table.insert(corps, p.contenu(frame, args))
   table.insert(corps, frame:preprocess(p.notice(frame, args)))
   --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(frame)

   local page = mw.title.getCurrentTitle()
   --On n'est pas dans une sous-page
   if not page.isSubpage then
       return frame:preprocess('Module:Documentation/Documentation')
   else
       --On est dans une sous-page
       local nom = page.subpageText
       if nom == 'Documentation' or nom == 'Bac à sable' or nom == 'Test' then
           return frame:preprocess('Documentation')
       else
           return frame:preprocess('Module:Documentation/Documentation')
       end
   end

end

-- test de fonctionnalité (note : la page courante via mw.title.getCurrentTitle() devrait être récupérée une fois pour toute par la fonction principale) function p.docname2(frame)

   local page = mw.title.getCurrentTitle()
   
   -- est-ce qu'on est une page principale ou une sous-page ?
   if (not page.isSubpage) then
       -- page principale : <nom de la page>/Documentation
       return page.text .. "/Documentation"
   else
       -- on est dans une sous-page : quel type de sous-page ?
       if (page.subpageText == 'Documentation' or page.subpageText == 'Bac à sable' or page.subpageText == 'Test') then
           -- on retourne la page de documentation de la sous-page
           return page.baseText .. "/Documentation"
       else
           return page.text .. "/Documentation"
       end
   end

end

function p.entete(frame, args)

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(frame)) then
               table.insert(entete, p.docname(frame))
               table.insert(entete, '|action=edit modifier}}]] [Modèle:Purger le cache')
           else
               table.insert(entete, p.docname(frame))
               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)

   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(frame)_.._%27')
       and p.ifexist(p.docname(frame)) then
           table.insert(contenu, frame:preprocess('Modèle:' .. p.docname(frame) .. ''))
       end
   end
table.insert(contenu, frame:preprocess('\n
\n'))
   return table.concat(contenu)

end

function p.notice(frame, args)

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