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

De Le Wiki de Lug
Aller à la navigation Aller à la recherche
Modèle>Hlm Z.
(correction de l'ordre des paramètres)
Modèle>Zebulon84
(Adaptation pour les modules (« fusion » avec module:Documentation module) ; ajout d'un bandeau s'il n'y a pas de documentation.)
Ligne 57 : Ligne 57 :
editionLien:wikitext(lienUrl(doc, 'modifier'))
editionLien:wikitext(lienUrl(doc, 'modifier'))
else
else
editionLien:wikitext(lienUrl(doc, 'créer', 'edit', ''))
if args.module then
editionLien:wikitext(lienUrl(doc, 'créer', 'edit', 'Module'))
else
editionLien:wikitext(lienUrl(doc, 'créer', 'edit', ''))
end
end
end


Ligne 94 : Ligne 98 :
end
end


local function contenu(args, titreDoc, existeDoc)
local function contenu(args, doc, existeDoc)
local res = mw.html.create():newline()
local res = mw.html.create():newline()


Ligne 100 : Ligne 104 :
res:wikitext(args.contenu)
res:wikitext(args.contenu)
elseif existeDoc then
elseif existeDoc then
local contenuDoc = args[1] or titreDoc or ''
local frame = mw.getCurrentFrame()
local frame = mw.getCurrentFrame()
if frame.args and frame.args['contenu sous-page'] then
if frame.args and frame.args['contenu sous-page'] then
res:wikitext(frame.args['contenu sous-page'])
res:wikitext(frame.args['contenu sous-page'])
else
else
res:wikitext(frame:expandTemplate{title = contenuDoc})
res:wikitext(frame:expandTemplate{title = doc.prefixedText})
end
else
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.[[Catégorie:%s sans documentation]]'
if args.module then
texteBandeau = texteBandeau:format(
'module',
lienUrl(doc, 'créer cete sous-page', 'edit', 'Module'),
'module',
'module'
)
else
texteBandeau = texteBandeau:format(
'modèle',
lienUrl(doc, 'créer cette sous-page', 'edit', ''),
'modèle',
'modèle'
)
end
end
local param = {
['icône'] = 'Book-cover-A-Z.svg',
alt = 'domaine public',
style = 'width:80%;',
texte = texteBandeau,
}
res:wikitext(require('Module:Bandeau')._bandeau(param))
end
end


Ligne 119 : Ligne 148 :
local function notice(args, page, doc, existeDoc)
local function notice(args, page, doc, existeDoc)
local res = mw.html.create('div')
local res = mw.html.create('div')
 
:css('border-top', '1px solid #aaa')
if args.contenu or existeDoc then
:css('margin', '1em 0 0')
res
:css('border-top', '1px solid #aaa')
:css('margin', '1em 0 0')
end


local contenuParagraphe = res
local contenuParagraphe = res
Ligne 149 : Ligne 174 :
else
else
if existeDoc then
if existeDoc then
local lienAide = '[[Aide:Modèle|modèle]]'
if args.module then
lienAide = '[[Aide:Module|module]]'
end
contenuParagraphe
contenuParagraphe
:wikitext('La [[Aide:Documentation de modèle|documentation]] ')
:wikitext('La [[Aide:Documentation de modèle|documentation]] de ce ')
:wikitext('de ce [[Aide:Modèle|modèle]] est ')
:wikitext(lienAide)
:wikitext('[[Aide:Inclusion|incluse]] depuis sa [[')
:wikitext(' est [[Aide:Inclusion|incluse]] depuis sa [[')
:wikitext(tostring(doc))
:wikitext(tostring(doc))
:wikitext('|sous-page de documentation]]&nbsp;')
:wikitext('|sous-page de documentation]]&nbsp;')
Ligne 190 : Ligne 219 :
:wikitext(')')
:wikitext(')')
end
end
contenuParagraphe:wikitext(' et la page de ')
if not args.module then
contenuParagraphe:wikitext(' et la page de ')


local titrePageTest = doc.subjectNsText .. ':' .. doc.baseText .. '/Test'
local titrePageTest = doc.subjectNsText .. ':' .. doc.baseText .. '/Test'
local pageTest = mw.title.new(titrePageTest)
local pageTest = mw.title.new(titrePageTest)
if existePage(pageTest) then
if existePage(pageTest) then
contenuParagraphe
:wikitext('[[' .. titrePageTest .. '|test]]&nbsp;')
:tag('span')
:css('font-size', '89%')
:css('font-style', 'normal')
:wikitext('(')
:wikitext(lienUrl(pageTest, 'modifier'))
:wikitext(')')
else
contenuParagraphe
:wikitext('test&nbsp;')
:tag('span')
:css('font-size', '89%')
:css('font-style', 'normal')
:wikitext('(')
:wikitext(lienUrl(pageTest, 'créer', 'edit', '3'))
:wikitext(')')
end
contenuParagraphe
contenuParagraphe
:wikitext('[[' .. titrePageTest .. '|test]]&nbsp;')
:wikitext('.<br />Veuillez placer les catégories dans la sous-page ')
:tag('span')
:css('font-size', '89%')
if existeDoc then
:css('font-style', 'normal')
contenuParagraphe:wikitext(lienUrl(doc, '/Documentation'))
:wikitext('(')
else
:wikitext(lienUrl(pageTest, 'modifier'))
contenuParagraphe:wikitext(lienUrl(doc, '/Documentation', 'edit', ''))
:wikitext(')')
end
else
contenuParagraphe
:wikitext('test&nbsp;')
:tag('span')
:css('font-size', '89%')
:css('font-style', 'normal')
:wikitext('(')
:wikitext(lienUrl(pageTest, 'créer', 'edit', '3'))
:wikitext(')')
end
 
contenuParagraphe
:wikitext('.<br />Veuillez placer les catégories dans la sous-page ')
if existeDoc then
contenuParagraphe:wikitext(lienUrl(doc, '/Documentation'))
else
contenuParagraphe:wikitext(lienUrl(doc, '/Documentation', 'edit', ''))
end
end
contenuParagraphe:wikitext('.')
contenuParagraphe:wikitext('.')
Ligne 235 : Ligne 267 :
local existeDoc = existePage(doc)
local existeDoc = existePage(doc)
local res = mw.html.create()
local res = mw.html.create()
 
--Bandeau pour les sous-pages /Bac à sable
--Bandeau pour les sous-pages /Bac à sable
if page.subpageText == 'Bac à sable' then
if page.subpageText == 'Bac à sable' then
Ligne 254 : Ligne 286 :
:node(entete(args, page, doc, existeDoc))
:node(entete(args, page, doc, existeDoc))
:wikitext(protection(page, doc, existeDoc))
:wikitext(protection(page, doc, existeDoc))
:node(contenu(args, titreDoc, existeDoc))
:node(contenu(args, doc, existeDoc))
:node(notice(args, page, doc, existeDoc))
:node(notice(args, page, doc, existeDoc))



Version du 12 janvier 2016 à 05:22

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 nomDocumentation(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
	local sousPage = page.subpageText
	if sousPage == 'Documentation'
	or sousPage == 'Bac à sable'
	or sousPage == 'Test' then
		return page.subjectNsText .. ':' .. page.baseText .. '/Documentation'
	else
		return page.subjectNsText .. ':' .. page.text .. '/Documentation'
	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:Template-info.png|50px|alt=Documentation|link=]]')
	 	:tag('span')
	 		:css('font-weight', 'bold')
	 		:css('font-size', '125%')
	 		:wikitext('&nbsp;')
	 		:wikitext(args.titre or 'Documentation')
	 		:done()

	if not args.contenu then
		local editionLien = res:tag('span')
			:addClass('mw-editsection plainlinks')
			:wikitext('&#91;')

		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('&#93;&#32;&#91;')
			:wikitext(lienUrl(page, 'purger', 'purge'))
			:wikitext('&#93;')
	end

	return res
end

local function protection(page, doc, existeDoc)
	-- 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*l?o?n?g?u?e?[|}]'},
			sysop = {'protection', '{{%s*[Pp]rotection%s*[|}]'},
		}
		local protection = tableProtection[niveauProtection[1]]
		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]) then
				protection = false
			end
		end

		if protection then
			return require('Module:Protection').main({}, protection[1], page)
		end
	end
end

local function contenu(args, doc, existeDoc)
	local res = mw.html.create():newline()

	if args.contenu then
		res:wikitext(args.contenu)
	elseif existeDoc then
		local frame = mw.getCurrentFrame()
		if frame.args and frame.args['contenu sous-page'] then
			res:wikitext(frame.args['contenu sous-page'])
		else
			res:wikitext(frame:expandTemplate{title = doc.prefixedText})
		end
	else
		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.[[Catégorie:%s sans documentation]]'
		if args.module then
			texteBandeau = texteBandeau:format(
				'module',
				lienUrl(doc, 'créer cete sous-page', 'edit', 'Module'),
				'module',
				'module'
			)
		else
			texteBandeau = texteBandeau:format(
				'modèle',
				lienUrl(doc, 'créer cette sous-page', 'edit', ''),
				'modèle',
				'modèle'
			)
		end
		local param = {
			['icône'] = 'Book-cover-A-Z.svg',
			alt = 'domaine public',
			style = 'width:80%;',
			texte = texteBandeau,
		}
		res:wikitext(require('Module:Bandeau')._bandeau(param))
	end

	res
		:newline()
		:tag('div', {selfClosing = true})
			: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', '1em 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)
		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('.')
		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]]&nbsp;')
				:tag('span')
					:css('font-size', '89%')
					:css('font-style', 'normal')
					:wikitext('(')
					:wikitext(lienUrl(doc, 'modifier'))
					:wikitext('&nbsp;|&nbsp;')
					:wikitext(lienUrl(doc, 'historique', 'history'))
					:wikitext(').<br />')
					:done()
		end

		contenuParagraphe:wikitext('Les éditeurs peuvent travailler dans le ')

		local titrePageBacasable = doc.subjectNsText .. ':' .. doc.baseText .. '/Bac à sable'
		local pageBacasable = mw.title.new(titrePageBacasable)

		if existePage(pageBacasable) then
			contenuParagraphe
				:wikitext('[[' .. titrePageBacasable .. '|bac à sable]]&nbsp;')
				:tag('span')
					:css('font-size', '89%')
					:css('font-style', 'normal')
					:wikitext('(')
					:wikitext(lienUrl(pageBacasable, 'modifier'))
					:wikitext(')')
		else
			contenuParagraphe
				:wikitext('bac à sable&nbsp;')
				:tag('span')
					:css('font-size', '89%')
					:css('font-style', 'normal')
					:wikitext('(')
					:wikitext(lienUrl(pageBacasable, 'créer', 'edit', '2'))
					:wikitext(')')
		end
		
		if not args.module then
			contenuParagraphe:wikitext(' et la page de ')

			local titrePageTest = doc.subjectNsText .. ':' .. doc.baseText .. '/Test'
			local pageTest = mw.title.new(titrePageTest)
	 
			if existePage(pageTest) then
				contenuParagraphe
					:wikitext('[[' .. titrePageTest .. '|test]]&nbsp;')
					:tag('span')
						:css('font-size', '89%')
						:css('font-style', 'normal')
						:wikitext('(')
						:wikitext(lienUrl(pageTest, 'modifier'))
						:wikitext(')')
			else
				contenuParagraphe
					:wikitext('test&nbsp;')
					:tag('span')
						:css('font-size', '89%')
						:css('font-style', 'normal')
						:wikitext('(')
						:wikitext(lienUrl(pageTest, 'créer', 'edit', '3'))
						:wikitext(')')
			end
		
			contenuParagraphe
				:wikitext('.<br />Veuillez placer les catégories dans la sous-page ')
	 
			if existeDoc then
				contenuParagraphe:wikitext(lienUrl(doc, '/Documentation'))
			else
				contenuParagraphe:wikitext(lienUrl(doc, '/Documentation', 'edit', ''))
			end
		end
		contenuParagraphe:wikitext('.')
	end

	return res
end

function p._documentation(args)
	local page = mw.title.getCurrentTitle()
	local titreDoc = nomDocumentation(page)
	local doc = mw.title.new(args[1] or 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', {selfClosing = true})
			: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))
			:node(contenu(args, doc, existeDoc))
			:node(notice(args, page, doc, existeDoc))

	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
		if val ~= '' then
			args[cle] = mw.text.trim(val)
		end
	end

	return p._documentation(args)
end

function p.nomDocumentation(frame)
	if frame.args[1] and mw.text.trim(frame.args[1]) ~= '' then
		return frame.args[1]
	else
		local titreDoc = nomDocumentation(mw.title.getCurrentTitle())
		if mw.title.new(titreDoc).exists then
			return titreDoc
		end 
	end
end

return p