« Module:Documentation » : différence entre les versions
amélioration partielle |
appel redondant de p.docname() |
||
Ligne 50 : | Ligne 50 : | ||
function p.entete(frame, args, page) | 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:'} | ||
local doc = p.docname(page) | |||
if not args.couleur then | if not args.couleur then | ||
Ligne 82 : | Ligne 83 : | ||
end | end | ||
else | else | ||
if p.ifexist( | if p.ifexist(doc) then | ||
table.insert(entete, | table.insert(entete, doc) | ||
table.insert(entete, '|action=edit modifier}}]] [{{Purger le cache|purger}}') | table.insert(entete, '|action=edit modifier}}]] [{{Purger le cache|purger}}') | ||
else | else | ||
table.insert(entete, | table.insert(entete, doc) | ||
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 99 : | Ligne 100 : | ||
function p.contenu(frame, args, page) | function p.contenu(frame, args, page) | ||
local contenu = {} | local contenu = {} | ||
local doc = p.docname(page) | |||
if args.contenu then | if args.contenu then | ||
table.insert(contenu, '\n') | table.insert(contenu, '\n') | ||
Ligne 109 : | Ligne 112 : | ||
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:' .. | elseif frame:preprocess('{{FULLPAGENAMEE}}') ~= frame:preprocess('{{FULLPAGENAMEE:' .. doc .. '}}') | ||
and p.ifexist( | and p.ifexist(doc) then | ||
table.insert(contenu, frame:preprocess('{{' .. | table.insert(contenu, frame:preprocess('{{' .. doc .. '}}')) | ||
end | end | ||
end | end | ||
Ligne 122 : | Ligne 125 : | ||
function p.notice(frame, args, page) | function p.notice(frame, args, page) | ||
local notice = {} | local notice = {} | ||
local doc = p.docname(page) | |||
if args.contenu then | if args.contenu then | ||
Ligne 133 : | Ligne 137 : | ||
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:' .. | table.insert(notice, '[{{fullurl:' .. doc) | ||
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( | 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, '<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 146 : | Ligne 150 : | ||
table.insert(notice, '[[' .. args[1] .. '|sous-page de documentation]]') | table.insert(notice, '[[' .. args[1] .. '|sous-page de documentation]]') | ||
else | else | ||
table.insert(notice, '[[' .. | table.insert(notice, '[[' .. doc .. '|sous-page de documentation]]') | ||
end | end | ||
Ligne 157 : | Ligne 161 : | ||
table.insert(notice, args[1] .. '|action=history}} historique]') | table.insert(notice, args[1] .. '|action=history}} historique]') | ||
else | else | ||
table.insert(notice, | table.insert(notice, doc .. '|action=edit}} modifier]') | ||
table.insert(notice, ' | [{{fullurl:') | table.insert(notice, ' | [{{fullurl:') | ||
table.insert(notice, | table.insert(notice, doc .. '|action=history}} historique]') | ||
end | end | ||
table.insert(notice, ')</span>.<br />') | table.insert(notice, ')</span>.<br />') | ||
Ligne 169 : | Ligne 173 : | ||
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:' .. | or p.ifexist(frame:preprocess('{{#rel2abs:' .. doc .. '/../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, | table.insert(notice, doc) | ||
end | end | ||
table.insert(notice, '/../Bac à sable}}|bac à sable]]') | table.insert(notice, '/../Bac à sable}}|bac à sable]]') | ||
Ligne 182 : | Ligne 186 : | ||
table.insert(notice, args[1]) | table.insert(notice, args[1]) | ||
else | else | ||
table.insert(notice, | table.insert(notice, doc) | ||
end | end | ||
table.insert(notice, '/../Bac à sable}}|action=edit}} modifier])</span>') | table.insert(notice, '/../Bac à sable}}|action=edit}} modifier])</span>') | ||
Ligne 191 : | Ligne 195 : | ||
table.insert(notice, args[1]) | table.insert(notice, args[1]) | ||
else | else | ||
table.insert(notice, | table.insert(notice, doc) | ||
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 199 : | Ligne 203 : | ||
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:' .. | or p.ifexist(frame:preprocess('{{#rel2abs:' .. doc .. '/../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, | table.insert(notice, doc) | ||
end | end | ||
table.insert(notice, '/../Test}}|test]]') | table.insert(notice, '/../Test}}|test]]') | ||
Ligne 212 : | Ligne 216 : | ||
table.insert(notice, args[1]) | table.insert(notice, args[1]) | ||
else | else | ||
table.insert(notice, | table.insert(notice, doc) | ||
end | end | ||
table.insert(notice, '/../Test}}|action=edit}} modifier])</span>') | table.insert(notice, '/../Test}}|action=edit}} modifier])</span>') | ||
Ligne 221 : | Ligne 225 : | ||
table.insert(notice, args[1]) | table.insert(notice, args[1]) | ||
else | else | ||
table.insert(notice, | table.insert(notice, doc) | ||
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 229 : | Ligne 233 : | ||
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( | if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then | ||
if args[1] then | if args[1] then | ||
table.insert(notice, args[1]) | table.insert(notice, args[1]) | ||
else | else | ||
table.insert(notice, | table.insert(notice, doc) | ||
end | end | ||
table.insert(notice, '|action=edit') | table.insert(notice, '|action=edit') | ||
Ligne 241 : | Ligne 245 : | ||
table.insert(notice, args[1]) | table.insert(notice, args[1]) | ||
else | else | ||
table.insert(notice, | table.insert(notice, doc) | ||
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:45
--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, ' ')
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(doc) then table.insert(entete, doc) table.insert(entete, '|action=edit modifier}}]] [Modèle:Purger le cache') else table.insert(entete, doc) table.insert(entete, '|action=edit&preload=Modèle:Documentation/Preload créer}}]') end end table.insert(entete, ']') endtable.insert(entete, '
return table.concat(entete)
end
function p.contenu(frame, args, page)
local contenu = {} local doc = p.docname(page)
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_.._doc_.._%27') and p.ifexist(doc) then table.insert(contenu, frame:preprocess('Modèle:' .. doc .. '')) end endtable.insert(contenu, frame:preprocess('\n
return table.concat(contenu)
end
function p.notice(frame, args, page)
local notice = {} local doc = p.docname(page)
if args.contenu thentable.insert(notice, '
\n')
if args.notice then
table.insert(notice, args.notice)
else
table.insert(notice, 'La documentation de ce modèle ')
table.insert(notice, 'est directement incluse dans le corps de ce dernier.
')
table.insert(notice, 'Si cette page est protégée, veuillez transférer le contenu de la documentation vers sa ')
table.insert(notice, '[{{fullurl:' .. doc)
table.insert(notice, '|action=edit&preload=Modèle:Documentation/Preload sous-page dédiée}}].')
end
else
if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
table.insert(notice, '
')
table.insert(notice, 'La documentation de ce ')
table.insert(notice, 'modèle est incluse depuis sa ')
if args[1] then
table.insert(notice, '[[' .. args[1] .. '|sous-page de documentation]]')
else
table.insert(notice, 'sous-page de documentation')
end
table.insert(notice, ' (')
table.insert(notice, '[{{fullurl:')
if args[1] then
table.insert(notice, args[1] .. '|action=edit}} modifier]')
table.insert(notice, ' | [{{fullurl:')
table.insert(notice, args[1] .. '|action=history}} historique]')
else
table.insert(notice, doc .. '|action=edit}} modifier]')
table.insert(notice, ' | [{{fullurl:')
table.insert(notice, doc .. '|action=history}} historique]')
end
table.insert(notice, ').
')
else
table.insert(notice, '
')
end
table.insert(notice, 'Les éditeurs peuvent travailler dans le ')
if args[1] and p.ifexist(frame:preprocess('Bac à sable'))
or p.ifexist(frame:preprocess('Bac à sable')) then
table.insert(notice, 'bac à sable')
table.insert(notice, ' (')
table.insert(notice, 'modifier)')
else
table.insert(notice, 'bac à sable (')
table.insert(notice, 'créer')
table.insert(notice, ')')
end
table.insert(notice, ' et la page de ')
if args[1] and p.ifexist(frame:preprocess('Test'))
or p.ifexist(frame:preprocess('Test')) then
table.insert(notice, 'test')
table.insert(notice, ' (')
table.insert(notice, 'modifier)')
else
table.insert(notice, 'test (')
table.insert(notice, 'créer')
table.insert(notice, ')')
end
table.insert(notice, '.
Veuillez placer les catégories dans la sous-page ')
table.insert(notice, '[')
table.insert(notice, '{{fullurl:')
if args[1] and p.ifexist(args[1]) or p.ifexist(doc) then
if args[1] then
table.insert(notice, args[1])
else
table.insert(notice, doc)
end
table.insert(notice, '|action=edit')
else
if args[1] then
table.insert(notice, args[1])
else
table.insert(notice, doc)
end
table.insert(notice, '|action=edit&preload=Modèle:Documentation/Preload')
end
table.insert(notice, ' /Documentation}}].')
end
table.insert(notice, '
return table.concat(notice)
end
return p