« Module:Bandeau de rubrique » : différence entre les versions

De Les Archives de Vault-Tec
Kharmitch (discussion | contributions)
Ajout du bandeau jeu
Kharmitch (discussion | contributions)
Aucun résumé des modifications
 
(12 versions intermédiaires par le même utilisateur non affichées)
Ligne 2 : Ligne 2 :


--------------------------------------------------------
--------------------------------------------------------
-----     Référentiel des bandeaux de rubrique     -----
-----   Référentiel des bandeaux de rubrique     -----
--------------------------------------------------------
--------------------------------------------------------


data = {
data = {
["connexe"] = {
warning  = false,
text    = function(args)
local link = args[1]
if not link then return "Lien ?" end
local text
if args[2] then
text = "Articles connexes : "
else
text = "Article connexe : "
end
local linkText = args["t1"] or link
text = text .. "[[:" .. link .. "|" .. linkText .. "]]"
for i = 2, 5 do
link = args[i]
if link then
linkText = args["t" .. i] or link
text = text .. ", [[:" .. link .. "|" .. linkText .. "]]"
else
break
end
end
return text
end
},
["extrait"] = {
["extrait"] = {
        warning  = false,
warning  = false,
        text    = function(args)
text    = function(args)
        local article = args[1]
local article = args[1]
        local title = mw.title.new(article)
local title = mw.title.new(article)
       
        local inclusionType = ''
local inclusionType = ''
        local section = args['section']
local section = args['section']
        local heading = args['rubrique']
local heading = args['rubrique']
       
        if section then
if section then
        inclusionType = ' · Section ' .. section
inclusionType = ' · Section ' .. section
        elseif heading then
elseif heading then
        inclusionType = ' · Rubrique ' .. heading
inclusionType = ' · Rubrique ' .. heading
        else
else
        inclusionType = ' · Introduction'
inclusionType = ' · Introduction'
        end
end
       
return 'Extrait de l\'article [[' .. article .. ']]'
return 'Extrait de l\'article [[' .. article .. ']]'
.. inclusionType
.. inclusionType
.. ' · ([' .. title:fullUrl('action=edit') .. ' modifier])'
.. ' · ([' .. title:fullUrl('action=edit') .. ' modifier])'
.. ' · ([[Aide:Inclusion|Qu\'est ce que c\'est ?]])'
.. ' · ([[Aide:Inclusion|Qu\'est ce que c\'est ?]])'
        end
end
    },
},
    ["jeu"] = {
["jeu"] = {
    warning  = false,
warning  = false,
    text    = function(args)
image    = 'Portail jeux.png',
    local abbModule = require( "Module:Abréviation" )
text    = function(args)
   
local abbModule = require( "Module:Abréviation" )
    -- Il doit y avoir un moins un jeu reconnu, dans le cas
    -- contraire, on ne retourne rien
-- Il doit y avoir un moins un jeu reconnu, dans le cas
    -- Le lien est par défaut le nom de la page mais il peut
-- contraire, on ne retourne rien
    -- être surchargé
-- Le lien est par défaut le nom de la page mais il peut
   
-- être surchargé
    local abb = args[1]
    local link = args["lien"] or mw.title.getCurrentTitle().text
local abb = args[1]
   
local link = args["lien"] or mw.title.getCurrentTitle().text
    if not abb then return "" end
   
if not abb then return "" end
    local game = abbModule.name(abb)
    if not game then return "" end
local game = abbModule.name(abb)
   
if not game then return "" end
    -- Au pluriel si plusieurs jeux
-- Au pluriel si plusieurs jeux


    local text = ''
local text = ''
    if args[2] then
if args[2] then
    text = "Articles associés aux jeux : "
text = "Articles associés aux jeux : "
    else
else
    text = "Article associé au jeu : "
text = "Article associé au jeu : "
    end
end
   
    text = text .. "[[" .. link .. " (" .. game .. ")|''" .. game .. "'']]"
text = text .. "[[" .. (args["lien1"] or link) .. " (" .. game .. ")|''" .. game .. "'']]"
   
    -- On ajoute les jeux 2 à 10 mais on s'arrête si le
-- On ajoute les jeux 2 à 10 mais on s'arrête si le
    -- n-ième est absent.
-- n-ième est absent.
   
    for i = 2, 10 do
for i = 2, 10 do
    abb = args[i]
abb = args[i]
    if abb then
if abb then
    game = abbModule.name(abb)
game = abbModule.name(abb)
    if game then
if game then
    local linkAbb = args["lien" .. i] or link
local linkAbb = args["lien" .. i] or link
    text = text .. ", [[" .. linkAbb .. " (" .. game .. ")|''" .. game .. "'']]"
text = text .. ", [[" .. linkAbb .. " (" .. game .. ")|''" .. game .. "'']]"
    end
end
    else
else
    break
break
    end
end
    end
end
   
    return text
return text
    end
end
    },
},
    ["principal"] = {
["principal"] = {
        warning  = false,
warning  = false,
        text    = function(args)
text    = function(args)
local link = args[1]
local link = args[1]
local display = args['t1'] or link
local display = args['t1'] or link
Ligne 107 : Ligne 137 :
return text
return text
        end
end
    },
},
    ["vide"] = {
["vide"] = {
        warning  = true,
warning  = true,
        category = 'Sections vides ou incomplètes',
image    = 'Portail participation.png',
        text    = function(args)
category = 'Rubrique vide ou incomplète',
        local text = 'Cette rubrique est vide, insuffisamment détaillée ou incomplète. ['
text    = function(args)
        .. mw.title:getCurrentTitle():fullUrl('action=edit') .. ' Votre aide] est la bienvenue'
local text = 'Cette rubrique est vide, insuffisamment détaillée ou incomplète. ['
        local todo = args['à faire']
.. mw.title:getCurrentTitle():fullUrl('action=edit') .. ' Votre aide] est la bienvenue'
        if todo then
local todo = args['à faire']
        text = text .. ' pour ' .. todo
if todo then
        end
text = text .. ' pour ' .. todo
        return text .. '.'
end
        end
return text .. '.'
    },
end
},
}
}


Ligne 143 : Ligne 174 :
local banner = data[args.nom:lower()]
local banner = data[args.nom:lower()]
local image = banner.image or ''
local image = banner.image
local text = banner.text
local text = banner.text
local category = banner.category
local category = banner.category
if category and mw.title.getCurrentTitle().namespace == 0 then
if category and mw.title.getCurrentTitle().namespace == 0 then
local game = args['jeu']
local game = args['jeu'] or args[1]  -- FIXME: args[1] conflit
if game ~= '' then
if game ~= '' then
game = require( 'Module:Abréviation' ).name(game) or ''
game = require( 'Module:Abréviation' ).name(game) or ''
Ligne 160 : Ligne 191 :
end
end
if image ~= '' then
if image then
image = mw.html.create( 'span' )
image = mw.html.create( 'div' )
:addClass( 'avt-section-banner-img' )
:wikitext( '[[Fichier:' .. image .. '|x30px|link=|alt=]]' )
:wikitext( '[[Fichier:' .. image .. '|x30px|link=|alt=]]' )
:done()
:done()
Ligne 173 : Ligne 203 :
local res = mw.html.create( 'div' )
local res = mw.html.create( 'div' )
:addClass( 'avt-section-banner noexcerpt' )
:addClass( 'avt-section-banner noexcerpt' )
:wikitext(tostring(image) .. text)
:node(image)
:tag( 'div' )
:wikitext(text)
:done()
:done()
:done()

Dernière version du 23 janvier 2023 à 22:51

La documentation pour ce module peut être créée à Module:Bandeau de rubrique/doc

local p = {}

--------------------------------------------------------
-----    Référentiel des bandeaux de rubrique      -----
--------------------------------------------------------

data = {
	["connexe"] = {
		warning  = false,
		text     = function(args)
			local link = args[1]
			if not link then return "Lien ?" end
			
			local text
			if args[2] then
				text = "Articles connexes : "
			else
				text = "Article connexe : "
			end
			
			local linkText = args["t1"] or link
			text = text .. "[[:" .. link .. "|" .. linkText .. "]]"
			
			for i = 2, 5 do
				link = args[i]
				if link then
					linkText = args["t" .. i] or link
					text = text .. ", [[:" .. link .. "|" .. linkText .. "]]"
				else
					break
				end
			end
			
			return text
		end
	},
	["extrait"] = {
		warning  = false,
		text     = function(args)
			local article = args[1]
			local title = mw.title.new(article)
			
			local inclusionType = ''
			local section = args['section']
			local heading = args['rubrique']
			
			if section then
				inclusionType = ' · Section ' .. section
			elseif heading then
				inclusionType = ' · Rubrique ' .. heading
			else
				inclusionType = ' · Introduction'
			end
			
			return 'Extrait de l\'article [[' .. article .. ']]'
					.. inclusionType
					.. ' · ([' .. title:fullUrl('action=edit') .. ' modifier])'
					.. ' · ([[Aide:Inclusion|Qu\'est ce que c\'est ?]])'
		end
	},
	["jeu"] = {
		warning  = false,
		image    = 'Portail jeux.png',
		text     = function(args)
			local abbModule = require( "Module:Abréviation" )
			
			-- Il doit y avoir un moins un jeu reconnu, dans le cas
			-- contraire, on ne retourne rien
			-- Le lien est par défaut le nom de la page mais il peut
			-- être surchargé
			
			local abb = args[1]
			local link = args["lien"] or mw.title.getCurrentTitle().text
			
			if not abb then return "" end
			
			local game = abbModule.name(abb)
			if not game then return "" end
			
			-- Au pluriel si plusieurs jeux

			local text = ''
			if args[2] then
				text = "Articles associés aux jeux : "
			else
				text = "Article associé au jeu : "
			end
			
			text = text .. "[[" .. (args["lien1"] or link) .. " (" .. game .. ")|''" .. game .. "'']]"
			
			-- On ajoute les jeux 2 à 10 mais on s'arrête si le
			-- n-ième est absent.
			
			for i = 2, 10 do
				abb = args[i]
				if abb then
					game = abbModule.name(abb)
					if game then
						local linkAbb = args["lien" .. i] or link
						text = text .. ", [[" .. linkAbb .. " (" .. game .. ")|''" .. game .. "'']]"
					end
				else
					break
				end
			end
			
			return text
		end
	},
	["principal"] = {
		warning  = false,
		text     = function(args)
			local link = args[1]
			local display = args['t1'] or link
			
			if not link then return '' end
			
			text = '[[' .. link .. '|' .. display .. ']]'
			
			local many = false
			for i = 2, 5 do
				local link = args[i]
				local display = args['t' .. i] or link
				if link then
					many = true
					text = text .. ', [[' .. link .. '|' .. display .. ']]'
				else
					break
				end
			end
			
			if many then
				text = 'Articles principaux : ' .. text
			else
				text = 'Article principal : ' .. text
			end
			
			return text
		end
	},
	["vide"] = {
		warning  = true,
		image    = 'Portail participation.png',
		category = 'Rubrique vide ou incomplète',
		text     = function(args)
			local text = 'Cette rubrique est vide, insuffisamment détaillée ou incomplète. ['
					.. mw.title:getCurrentTitle():fullUrl('action=edit') .. ' Votre aide] est la bienvenue'
			local todo = args['à faire']
			if todo then
				text = text .. ' pour ' .. todo
			end
			return text .. '.'
		end
	},
}

-----------------------------------------------------------

function p.build(frame)
	local args = {}
	args.nom = frame.args.nom
	
	local argsParent = frame:getParent().args
	for cle, val in pairs(argsParent) do
		if val then
			args[cle] = mw.text.trim(val)
		end
	end
	
	return p._build(args)
end

function p._build(args)
	local banner = data[args.nom:lower()]
	
	local image = banner.image
	local text = banner.text
	local category = banner.category
	
	if category and mw.title.getCurrentTitle().namespace == 0 then
		local game = args['jeu'] or args[1]  -- FIXME: args[1] conflit
		if game ~= '' then
			game = require( 'Module:Abréviation' ).name(game) or ''
			if game ~= '' then
				game = ' (' .. game .. ')'
			end
		end
		category = '[[Catégorie:' .. category .. game .. ']]'
	else
		category = ''
	end
	
	if image then
		image = mw.html.create( 'div' )
			:wikitext( '[[Fichier:' .. image .. '|x30px|link=|alt=]]' )
			:done()
	end
	
	if type(text) == 'function' then
		text = text(args)
	end
	
	local res = mw.html.create( 'div' )
		:addClass( 'avt-section-banner noexcerpt' )
		:node(image)
		:tag( 'div' )
			:wikitext(text)
			:done()
		:done()
	
	return tostring(res) .. category
end

return p