Module:Documentation : Différence entre versions
Sauter à la navigation
Sauter à la recherche
m (Undid revision 908430596 by Paine Ellsworth (talk) srv - mybad) |
fr>Od1n (rétablissement de l'ordre correct : le paramètre "contenu" doit emporter la priorité sur la sous-page de documentation (penser aux méta-modèles de documentation)) |
||
| Ligne 1 : | Ligne 1 : | ||
| − | -- | + | --Ce module implémente le modèle {{Documentation}}. |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
local p = {} | local p = {} | ||
| − | + | local function existePage(page) | |
| − | + | return page and page.exists | |
| + | end | ||
| − | + | local function nomSouspage(page, souspage) | |
| − | + | --On n'est pas dans une sous-page | |
| − | + | if not page.isSubpage then | |
| − | + | return page.subjectNsText .. ':' .. page.text .. '/' .. souspage | |
| − | |||
| − | |||
| − | |||
| − | local function | ||
| − | -- | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
| − | local | + | --On est dans une sous-page |
| − | + | local sousPage = page.subpageText | |
| − | return | + | if sousPage == 'Documentation' |
| + | or sousPage == 'Bac à sable' | ||
| + | or sousPage == 'Test' then | ||
| + | return page.subjectNsText .. ':' .. page.baseText .. '/' .. souspage | ||
| + | else | ||
| + | return page.subjectNsText .. ':' .. page.text .. '/' .. souspage | ||
end | end | ||
| − | |||
| − | |||
| − | |||
end | end | ||
| − | + | local function lienUrl(nomPage, titrePage, action, pagePreload) | |
| + | local argument = {['action'] = action or 'edit'} | ||
| − | + | if pagePreload then | |
| − | if | + | argument['preload'] = 'Modèle:Documentation/Preload' .. pagePreload |
| − | |||
| − | |||
| − | |||
end | end | ||
| − | |||
| − | |||
| − | |||
| − | + | return mw.ustring.format('[%s %s]', nomPage:fullUrl(argument), titrePage) | |
| − | |||
| − | |||
end | end | ||
| − | + | local function entete(args, page, doc, existeDoc) | |
| + | local res = mw.html.create('div') | ||
| − | + | res | |
| − | + | :css('margin-bottom', '1ex') | |
| − | + | :css('border-bottom', '1px solid #aaa') | |
| + | :css('padding-bottom', '3px') | ||
| + | :wikitext('[[Fichier:Test Template Info-Icon.svg|50px|alt=|link=]]') | ||
| + | :tag('span') | ||
| + | :css('font-weight', 'bold') | ||
| + | :css('font-size', '125%') | ||
| + | :css('vertical-align', 'middle') | ||
| + | :wikitext(' ') | ||
| + | :wikitext(args.titre or 'Documentation') | ||
| + | :done() | ||
| − | + | if not args.contenu then | |
| + | local editionLien = res:tag('span') | ||
| + | :addClass('mw-editsection plainlinks') | ||
| + | :css('vertical-align', 'middle') | ||
| + | :wikitext('[') | ||
| − | + | if existeDoc then | |
| − | + | editionLien:wikitext(lienUrl(doc, 'modifier')) | |
| − | + | else | |
| − | + | if args.module then | |
| − | + | editionLien:wikitext(lienUrl(doc, 'créer', 'edit', 'Module')) | |
| − | + | else | |
| − | + | editionLien:wikitext(lienUrl(doc, 'créer', 'edit', '')) | |
| − | + | end | |
| − | + | end | |
| − | |||
| − | end | ||
| − | + | editionLien | |
| − | + | :wikitext('] [') | |
| − | + | :wikitext(lienUrl(page, 'purger', 'purge')) | |
| − | + | :wikitext(']') | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
| − | |||
| − | + | return res | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | return | ||
end | end | ||
| − | + | local function protection(page, doc, existeDoc, message) | |
| − | -- | + | -- Insertion automatique du modèle de protection. |
| − | + | local niveauProtection = page.protectionLevels.edit | |
| − | + | if niveauProtection and niveauProtection[1] then | |
| − | + | local tableProtection = { | |
| − | + | autoconfirmed = {'semiProtection', '{{%s*[Ss]emi%-protection%s*[|}]', '{{%s*[Ss]emi%-protection +longue%s*[|}]'}, | |
| − | + | editextendedsemiprotected = {'semiProtectionEtendue', '{{%s*[Ss]emi%-protection +étendue%s*[|}]'}, | |
| − | + | sysop = {'protection', '{{%s*[Pp]rotection%s*[|}]'}, | |
| − | + | } | |
| − | + | local protection = tableProtection[niveauProtection[1]] | |
| − | + | if not protection then | |
| − | + | return '' | |
| − | + | end | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | local alreadyShown = false | |
| − | + | if existeDoc then | |
| − | + | -- Vérification qu'il n'y a pas déjà un modèle de | |
| − | + | -- protection dans la documentation du modèle. | |
| − | + | local contenuDoc = doc:getContent() | |
| − | + | if contenuDoc:match(protection[2]) or (protection[3] and contenuDoc:match(protection[3])) then | |
| − | + | alreadyShown = true | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
| − | |||
end | end | ||
| − | |||
| − | + | if not alreadyShown then | |
| − | + | if message == '' then | |
| − | + | message = nil | |
| − | + | end | |
| − | + | return require('Module:Protection').main({message}, protection[1], page) | |
| − | |||
| − | |||
| − | |||
end | end | ||
| − | |||
end | end | ||
| + | end | ||
| + | |||
| + | -- pour les bacs à sable, on retire les balises de catégories | ||
| + | -- habituellement situées en "includeonly" à la fin de la documentation | ||
| + | local function retireBalisesCategories(contenuDoc) | ||
| + | local count | ||
| + | repeat | ||
| + | contenuDoc, count = mw.ustring.gsub(contenuDoc, '%[%[Catégorie:[^%]]+%]%][\t\r\n\f ]*$', '') | ||
| + | until count == 0 | ||
| − | + | contenuDoc, count = mw.ustring.gsub(contenuDoc, '[\t\r\n\f ]*$', '') | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | return contenuDoc | |
| − | + | end | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | local function contenu(args, doc, existeDoc) | |
| − | + | local page = mw.title.getCurrentTitle() | |
| − | + | local res = mw.html.create():newline() | |
| − | |||
| − | + | if args.contenu then | |
| − | + | res:wikitext(args.contenu) | |
| − | |||
| − | |||
| − | + | elseif existeDoc then | |
| − | + | local contenuDoc = mw.getCurrentFrame():expandTemplate{title = doc.prefixedText} | |
| − | + | if page.subpageText == 'Bac à sable' or page.subpageText == 'Test' then | |
| − | + | contenuDoc = retireBalisesCategories(contenuDoc) | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
| − | + | res:wikitext(contenuDoc) | |
| − | + | if args['complément'] then | |
| − | + | res :newline() | |
| − | + | :newline() | |
| − | + | :wikitext(args['complément']) | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
| − | |||
| − | + | elseif page.subpageText ~= 'Bac à sable' and page.subpageText ~= 'Test' then | |
| − | + | local texteBandeau = '<b>Ce %s ne possède aucune [[Aide:Documentation de modèle|documentation]] ' | |
| − | + | ..'explicative en sous-page</b>, pas même une description succincte.<br> ' | |
| − | + | ..'Vous pouvez %s afin de documenter ce %s adéquatement.' | |
| − | + | if args.module then | |
| − | + | texteBandeau = texteBandeau:format( | |
| − | + | 'module', | |
| − | + | lienUrl(doc, 'créer cette sous-page', 'edit', 'Module'), | |
| − | + | 'module' | |
| − | + | ) | |
| − | + | if page.baseText == 'Country data' or page.text:sub(1, 12) == 'Utilisateur:' then | |
| − | + | -- pas de catégorisation pour : modèles de données, pseudo-namespace "Module:Utilisateur:Toto/Nom du module" | |
| − | + | else | |
| − | + | texteBandeau = texteBandeau .. '[[Catégorie:Module sans documentation]]' | |
| − | + | end | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
else | else | ||
| − | + | texteBandeau = texteBandeau:format( | |
| − | + | 'modèle', | |
| − | + | lienUrl(doc, 'créer cette sous-page', 'edit', ''), | |
| + | 'modèle' | ||
| + | ) | ||
| + | texteBandeau = texteBandeau .. '[[Catégorie:Modèle sans documentation]]' | ||
end | end | ||
| + | local param = { | ||
| + | ['icône'] = 'OOjs_UI_icon_book-ltr.svg', | ||
| + | alt = 'MIT', | ||
| + | style = 'width:80%;', | ||
| + | texte = texteBandeau, | ||
| + | } | ||
| + | res:wikitext(require('Module:Bandeau')._bandeau(param)) | ||
end | end | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | res | |
| − | + | :newline() | |
| − | + | :tag('div') | |
| − | + | :css('clear', 'both') | |
| − | + | ||
| − | + | return res | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
| − | + | local function notice(args, page, doc, existeDoc) | |
| − | - | + | local res = mw.html.create('div') |
| − | + | :css('border-top', '1px solid #aaa') | |
| + | :css('margin', '1.5em 0 0') | ||
| − | p | + | local contenuParagraphe = res |
| + | :tag('p') | ||
| + | :addClass('plainlinks') | ||
| + | :css('margin-bottom', '0') | ||
| + | :css('padding-left', '1em') | ||
| + | :css('font-style', 'italic') | ||
| − | + | if args.contenu then | |
| − | + | if args.notice then | |
| − | + | contenuParagraphe:wikitext(args.notice .. '<br />') | |
| − | + | else | |
| − | + | contenuParagraphe | |
| − | + | :wikitext('La [[Aide:Documentation de modèle|documentation]] ') | |
| − | + | :wikitext('de ce [[Aide:Modèle|modèle]] est directement ') | |
| − | + | :wikitext('[[Aide:Inclusion|incluse]] dans le corps de ce dernier. ') | |
| − | + | :wikitext(lienUrl(page, 'Cliquez ici pour purger le cache', 'purge')) | |
| − | + | :wikitext('.<br /> Si cette page est protégée, veuillez ') | |
| − | + | :wikitext('transférer le contenu de la documentation vers sa ') | |
| − | + | :wikitext(lienUrl(doc, 'sous-page dédiée', 'edit', '')) | |
| − | + | :wikitext('.<br /> ') | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
else | else | ||
| − | + | if existeDoc then | |
| − | + | local lienAide = '[[Aide:Modèle|modèle]]' | |
| − | + | if args.module then | |
| − | + | lienAide = '[[Aide:Module|module]]' | |
| − | + | end | |
| − | + | contenuParagraphe | |
| − | + | :wikitext('La [[Aide:Documentation de modèle|documentation]] de ce ') | |
| − | + | :wikitext(lienAide) | |
| − | + | :wikitext(' est [[Aide:Inclusion|incluse]] depuis sa [[') | |
| − | + | :wikitext(tostring(doc)) | |
| − | + | :wikitext('|sous-page de documentation]] ') | |
| − | + | :tag('span') | |
| − | + | :css('font-size', '89%') | |
| − | + | :css('font-style', 'normal') | |
| − | + | :wikitext('(') | |
| − | + | :wikitext(lienUrl(doc, 'modifier')) | |
| − | + | :wikitext(' | ') | |
| − | + | :wikitext(lienUrl(doc, 'historique', 'history')) | |
| − | + | :wikitext(').<br /> ') | |
| − | + | :done() | |
| − | + | :wikitext('Veuillez placer les catégories dans la sous-page ') | |
| − | + | :wikitext(lienUrl(doc, '/Documentation')) | |
| − | + | :wikitext('.<br /> ') | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
end | end | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | contenuParagraphe:wikitext('Les éditeurs peuvent travailler dans le ') | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | local | + | local titrePageBacasable = nomSouspage(page, 'Bac à sable') |
| − | + | local pageBacasable = mw.title.new(titrePageBacasable) | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | if existePage(pageBacasable) then | |
| − | + | contenuParagraphe | |
| − | + | :wikitext('[[' .. titrePageBacasable .. '|bac à sable]] ') | |
| − | + | :tag('span') | |
| − | + | :css('font-size', '89%') | |
| − | + | :css('font-style', 'normal') | |
| − | + | :wikitext('(') | |
| − | + | :wikitext(lienUrl(pageBacasable, 'modifier')) | |
| − | + | :wikitext(')') | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
else | else | ||
| − | + | local preLoad = '2' | |
| − | + | if args.module then | |
| − | + | preLoad = nil | |
| − | + | end | |
| − | + | contenuParagraphe | |
| − | + | :wikitext('bac à sable ') | |
| − | + | :tag('span') | |
| − | + | :css('font-size', '89%') | |
| − | + | :css('font-style', 'normal') | |
| − | + | :wikitext('(') | |
| − | + | :wikitext(lienUrl(pageBacasable, 'créer', 'edit', preLoad)) | |
| − | + | :wikitext(')') | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
| − | |||
| − | |||
| − | |||
| − | + | if not args.module then | |
| − | + | contenuParagraphe:wikitext(' et la page de ') | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | local titrePageTest = nomSouspage(page, 'Test') | |
| − | + | local pageTest = mw.title.new(titrePageTest) | |
| − | |||
| − | + | if existePage(pageTest) then | |
| − | + | contenuParagraphe | |
| − | + | :wikitext('[[' .. titrePageTest .. '|test]] ') | |
| − | + | :tag('span') | |
| − | + | :css('font-size', '89%') | |
| − | + | :css('font-style', 'normal') | |
| − | + | :wikitext('(') | |
| − | + | :wikitext(lienUrl(pageTest, 'modifier')) | |
| − | + | :wikitext(')') | |
| − | + | else | |
| − | + | contenuParagraphe | |
| + | :wikitext('test ') | ||
| + | :tag('span') | ||
| + | :css('font-size', '89%') | ||
| + | :css('font-style', 'normal') | ||
| + | :wikitext('(') | ||
| + | :wikitext(lienUrl(pageTest, 'créer', 'edit', '3')) | ||
| + | :wikitext(')') | ||
| + | end | ||
end | end | ||
| − | + | contenuParagraphe:wikitext('.') | |
| − | |||
| − | |||
| − | |||
| − | + | return res | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
| − | + | function p._documentation(args) | |
| − | + | local page = mw.title.getCurrentTitle() | |
| − | + | local titreDoc = args[1] or nomSouspage(page, 'Documentation') | |
| + | local doc = mw.title.new(titreDoc) | ||
| + | local existeDoc = existePage(doc) | ||
| + | local res = mw.html.create() | ||
| − | + | --Bandeau pour les sous-pages /Bac à sable | |
| − | + | if page.subpageText == 'Bac à sable' then | |
| − | + | res | |
| − | -- | + | :tag('div') |
| − | + | :css('clear', 'both') | |
| − | + | :done() | |
| − | + | :wikitext(mw.getCurrentFrame():expandTemplate{title = 'Sous-page de bac à sable'}) | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
| − | -- | + | --Génération de la documentation |
| − | + | res | |
| − | + | :tag('div') | |
| − | + | :css('clear', 'both') | |
| − | + | :css('margin', '1em 0 0 0') | |
| − | + | :css('border', '1px solid #aaa') | |
| − | + | :css('background', args.couleur or '#ecfcf4') | |
| − | + | :css('padding', '1em 1em 0.8em') | |
| − | + | :node(entete(args, page, doc, existeDoc)) | |
| − | + | :wikitext(protection(page, doc, existeDoc, args['message protection'])) | |
| − | + | :node(contenu(args, doc, existeDoc)) | |
| − | + | :node(notice(args, page, doc, existeDoc)) | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | --Catégorisation des modules, en rangeant à part les modules de données | |
| − | -- | + | if args.module and page.subpageText ~= 'Bac à sable' and page.subpageText ~= 'Test' then |
| − | + | if page.isSubpage and page.baseText == 'Country data' then | |
| − | + | res:wikitext("[[Catégorie:Module d'informations pays|" .. page.subpageText .. "]]") | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
else | else | ||
| − | + | res:wikitext("[[Catégorie:Module en langage Lua]]") | |
end | end | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | return tostring(res) | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | return | ||
end | end | ||
| − | function p. | + | function p.documentation(frame) |
| − | + | local args = {} | |
| − | + | local argsParent = frame:getParent().args | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | local | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | --Paramètres vides interprétés par Lua | |
| − | + | for cle, val in pairs(argsParent) do | |
| − | -- | + | val = mw.text.trim(val) |
| − | + | if val ~= '' then | |
| − | + | args[cle] = val | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
end | end | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | return p._documentation(args) | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
return p | return p | ||
Version du 16 août 2019 à 00:17
La documentation pour ce module peut être créée à Module:Documentation/doc
--Ce module implémente le modèle {{Documentation}}.
local p = {}
local function existePage(page)
return page and page.exists
end
local function nomSouspage(page, souspage)
--On n'est pas dans une sous-page
if not page.isSubpage then
return page.subjectNsText .. ':' .. page.text .. '/' .. souspage
end
--On est dans une sous-page
local sousPage = page.subpageText
if sousPage == 'Documentation'
or sousPage == 'Bac à sable'
or sousPage == 'Test' then
return page.subjectNsText .. ':' .. page.baseText .. '/' .. souspage
else
return page.subjectNsText .. ':' .. page.text .. '/' .. souspage
end
end
local function lienUrl(nomPage, titrePage, action, pagePreload)
local argument = {['action'] = action or 'edit'}
if pagePreload then
argument['preload'] = 'Modèle:Documentation/Preload' .. pagePreload
end
return mw.ustring.format('[%s %s]', nomPage:fullUrl(argument), titrePage)
end
local function entete(args, page, doc, existeDoc)
local res = mw.html.create('div')
res
:css('margin-bottom', '1ex')
:css('border-bottom', '1px solid #aaa')
:css('padding-bottom', '3px')
:wikitext('[[Fichier:Test Template Info-Icon.svg|50px|alt=|link=]]')
:tag('span')
:css('font-weight', 'bold')
:css('font-size', '125%')
:css('vertical-align', 'middle')
:wikitext(' ')
:wikitext(args.titre or 'Documentation')
:done()
if not args.contenu then
local editionLien = res:tag('span')
:addClass('mw-editsection plainlinks')
:css('vertical-align', 'middle')
:wikitext('[')
if existeDoc then
editionLien:wikitext(lienUrl(doc, 'modifier'))
else
if args.module then
editionLien:wikitext(lienUrl(doc, 'créer', 'edit', 'Module'))
else
editionLien:wikitext(lienUrl(doc, 'créer', 'edit', ''))
end
end
editionLien
:wikitext('] [')
:wikitext(lienUrl(page, 'purger', 'purge'))
:wikitext(']')
end
return res
end
local function protection(page, doc, existeDoc, message)
-- Insertion automatique du modèle de protection.
local niveauProtection = page.protectionLevels.edit
if niveauProtection and niveauProtection[1] then
local tableProtection = {
autoconfirmed = {'semiProtection', '{{%s*[Ss]emi%-protection%s*[|}]', '{{%s*[Ss]emi%-protection +longue%s*[|}]'},
editextendedsemiprotected = {'semiProtectionEtendue', '{{%s*[Ss]emi%-protection +étendue%s*[|}]'},
sysop = {'protection', '{{%s*[Pp]rotection%s*[|}]'},
}
local protection = tableProtection[niveauProtection[1]]
if not protection then
return ''
end
local alreadyShown = false
if existeDoc then
-- Vérification qu'il n'y a pas déjà un modèle de
-- protection dans la documentation du modèle.
local contenuDoc = doc:getContent()
if contenuDoc:match(protection[2]) or (protection[3] and contenuDoc:match(protection[3])) then
alreadyShown = true
end
end
if not alreadyShown then
if message == '' then
message = nil
end
return require('Module:Protection').main({message}, protection[1], page)
end
end
end
-- pour les bacs à sable, on retire les balises de catégories
-- habituellement situées en "includeonly" à la fin de la documentation
local function retireBalisesCategories(contenuDoc)
local count
repeat
contenuDoc, count = mw.ustring.gsub(contenuDoc, '%[%[Catégorie:[^%]]+%]%][\t\r\n\f ]*$', '')
until count == 0
contenuDoc, count = mw.ustring.gsub(contenuDoc, '[\t\r\n\f ]*$', '')
return contenuDoc
end
local function contenu(args, doc, existeDoc)
local page = mw.title.getCurrentTitle()
local res = mw.html.create():newline()
if args.contenu then
res:wikitext(args.contenu)
elseif existeDoc then
local contenuDoc = mw.getCurrentFrame():expandTemplate{title = doc.prefixedText}
if page.subpageText == 'Bac à sable' or page.subpageText == 'Test' then
contenuDoc = retireBalisesCategories(contenuDoc)
end
res:wikitext(contenuDoc)
if args['complément'] then
res :newline()
:newline()
:wikitext(args['complément'])
end
elseif page.subpageText ~= 'Bac à sable' and page.subpageText ~= 'Test' then
local texteBandeau = '<b>Ce %s ne possède aucune [[Aide:Documentation de modèle|documentation]] '
..'explicative en sous-page</b>, pas même une description succincte.<br> '
..'Vous pouvez %s afin de documenter ce %s adéquatement.'
if args.module then
texteBandeau = texteBandeau:format(
'module',
lienUrl(doc, 'créer cette sous-page', 'edit', 'Module'),
'module'
)
if page.baseText == 'Country data' or page.text:sub(1, 12) == 'Utilisateur:' then
-- pas de catégorisation pour : modèles de données, pseudo-namespace "Module:Utilisateur:Toto/Nom du module"
else
texteBandeau = texteBandeau .. '[[Catégorie:Module sans documentation]]'
end
else
texteBandeau = texteBandeau:format(
'modèle',
lienUrl(doc, 'créer cette sous-page', 'edit', ''),
'modèle'
)
texteBandeau = texteBandeau .. '[[Catégorie:Modèle sans documentation]]'
end
local param = {
['icône'] = 'OOjs_UI_icon_book-ltr.svg',
alt = 'MIT',
style = 'width:80%;',
texte = texteBandeau,
}
res:wikitext(require('Module:Bandeau')._bandeau(param))
end
res
:newline()
:tag('div')
:css('clear', 'both')
return res
end
local function notice(args, page, doc, existeDoc)
local res = mw.html.create('div')
:css('border-top', '1px solid #aaa')
:css('margin', '1.5em 0 0')
local contenuParagraphe = res
:tag('p')
:addClass('plainlinks')
:css('margin-bottom', '0')
:css('padding-left', '1em')
:css('font-style', 'italic')
if args.contenu then
if args.notice then
contenuParagraphe:wikitext(args.notice .. '<br />')
else
contenuParagraphe
:wikitext('La [[Aide:Documentation de modèle|documentation]] ')
:wikitext('de ce [[Aide:Modèle|modèle]] est directement ')
:wikitext('[[Aide:Inclusion|incluse]] dans le corps de ce dernier. ')
:wikitext(lienUrl(page, 'Cliquez ici pour purger le cache', 'purge'))
:wikitext('.<br /> Si cette page est protégée, veuillez ')
:wikitext('transférer le contenu de la documentation vers sa ')
:wikitext(lienUrl(doc, 'sous-page dédiée', 'edit', ''))
:wikitext('.<br /> ')
end
else
if existeDoc then
local lienAide = '[[Aide:Modèle|modèle]]'
if args.module then
lienAide = '[[Aide:Module|module]]'
end
contenuParagraphe
:wikitext('La [[Aide:Documentation de modèle|documentation]] de ce ')
:wikitext(lienAide)
:wikitext(' est [[Aide:Inclusion|incluse]] depuis sa [[')
:wikitext(tostring(doc))
:wikitext('|sous-page de documentation]] ')
:tag('span')
:css('font-size', '89%')
:css('font-style', 'normal')
:wikitext('(')
:wikitext(lienUrl(doc, 'modifier'))
:wikitext(' | ')
:wikitext(lienUrl(doc, 'historique', 'history'))
:wikitext(').<br /> ')
:done()
:wikitext('Veuillez placer les catégories dans la sous-page ')
:wikitext(lienUrl(doc, '/Documentation'))
:wikitext('.<br /> ')
end
end
contenuParagraphe:wikitext('Les éditeurs peuvent travailler dans le ')
local titrePageBacasable = nomSouspage(page, 'Bac à sable')
local pageBacasable = mw.title.new(titrePageBacasable)
if existePage(pageBacasable) then
contenuParagraphe
:wikitext('[[' .. titrePageBacasable .. '|bac à sable]] ')
:tag('span')
:css('font-size', '89%')
:css('font-style', 'normal')
:wikitext('(')
:wikitext(lienUrl(pageBacasable, 'modifier'))
:wikitext(')')
else
local preLoad = '2'
if args.module then
preLoad = nil
end
contenuParagraphe
:wikitext('bac à sable ')
:tag('span')
:css('font-size', '89%')
:css('font-style', 'normal')
:wikitext('(')
:wikitext(lienUrl(pageBacasable, 'créer', 'edit', preLoad))
:wikitext(')')
end
if not args.module then
contenuParagraphe:wikitext(' et la page de ')
local titrePageTest = nomSouspage(page, 'Test')
local pageTest = mw.title.new(titrePageTest)
if existePage(pageTest) then
contenuParagraphe
:wikitext('[[' .. titrePageTest .. '|test]] ')
:tag('span')
:css('font-size', '89%')
:css('font-style', 'normal')
:wikitext('(')
:wikitext(lienUrl(pageTest, 'modifier'))
:wikitext(')')
else
contenuParagraphe
:wikitext('test ')
:tag('span')
:css('font-size', '89%')
:css('font-style', 'normal')
:wikitext('(')
:wikitext(lienUrl(pageTest, 'créer', 'edit', '3'))
:wikitext(')')
end
end
contenuParagraphe:wikitext('.')
return res
end
function p._documentation(args)
local page = mw.title.getCurrentTitle()
local titreDoc = args[1] or nomSouspage(page, 'Documentation')
local doc = mw.title.new(titreDoc)
local existeDoc = existePage(doc)
local res = mw.html.create()
--Bandeau pour les sous-pages /Bac à sable
if page.subpageText == 'Bac à sable' then
res
:tag('div')
:css('clear', 'both')
:done()
:wikitext(mw.getCurrentFrame():expandTemplate{title = 'Sous-page de bac à sable'})
end
--Génération de la documentation
res
:tag('div')
:css('clear', 'both')
:css('margin', '1em 0 0 0')
:css('border', '1px solid #aaa')
:css('background', args.couleur or '#ecfcf4')
:css('padding', '1em 1em 0.8em')
:node(entete(args, page, doc, existeDoc))
:wikitext(protection(page, doc, existeDoc, args['message protection']))
:node(contenu(args, doc, existeDoc))
:node(notice(args, page, doc, existeDoc))
--Catégorisation des modules, en rangeant à part les modules de données
if args.module and page.subpageText ~= 'Bac à sable' and page.subpageText ~= 'Test' then
if page.isSubpage and page.baseText == 'Country data' then
res:wikitext("[[Catégorie:Module d'informations pays|" .. page.subpageText .. "]]")
else
res:wikitext("[[Catégorie:Module en langage Lua]]")
end
end
return tostring(res)
end
function p.documentation(frame)
local args = {}
local argsParent = frame:getParent().args
--Paramètres vides interprétés par Lua
for cle, val in pairs(argsParent) do
val = mw.text.trim(val)
if val ~= '' then
args[cle] = val
end
end
return p._documentation(args)
end
return p