« Module:Infobox/Core » : différence entre les versions
De Nefald
Autres actions
m map |
Port depuis codex.nefald.fr : masquage des sections vides, champs sans label pleine largeur, icône configurable par fonction (via update-page on MediaWiki MCP Server) |
||
| (3 versions intermédiaires par le même utilisateur non affichées) | |||
| Ligne 72 : | Ligne 72 : | ||
-- Fonction pour gérer la catégorisation automatique | -- Fonction pour gérer la catégorisation automatique | ||
local function addCategories(args, config, frame) | local function addCategories(args, config, frame) | ||
-- Vérifier qu'on est dans le namespace principal (0) | -- Vérifier qu'on est dans le namespace principal (0) ou namespace plugin (3000) | ||
local title = mw.title.getCurrentTitle() | local title = mw.title.getCurrentTitle() | ||
if title.namespace ~= 0 then | if title.namespace ~= 0 and title.namespace ~= 3000 then | ||
return '' | return '' | ||
end | end | ||
| Ligne 152 : | Ligne 152 : | ||
for _, section in ipairs(config.sections or {}) do | for _, section in ipairs(config.sections or {}) do | ||
-- Les lignes de la section sont accumulées ici et intégrées au body seulement | |||
-- si au moins une a du contenu — sinon le section-title reste orphelin (ex. une | |||
-- section "Sous-pages" ou "Compatibilité" entièrement vide sur cette page). | |||
local sectionRows = {} | |||
for _, champ in ipairs(section.champs or {}) do | for _, champ in ipairs(section.champs or {}) do | ||
| Ligne 174 : | Ligne 172 : | ||
rowDiv:node(labelDiv):node(valueDiv) | rowDiv:node(labelDiv):node(valueDiv) | ||
table.insert(sectionRows, rowDiv) | |||
coordinatesDisplayed = true | coordinatesDisplayed = true | ||
| Ligne 195 : | Ligne 193 : | ||
:addClass('infobox-row') | :addClass('infobox-row') | ||
local valueDiv = mw.html.create('div') | local valueDiv = mw.html.create('div') | ||
:addClass('infobox-value') | :addClass('infobox-value') | ||
-- Champ sans label (ex. liste pleine largeur type Sous-pages) : | |||
-- pas de colonne label, la valeur devient seule enfant flex du | |||
-- row et occupe donc naturellement 100% de la largeur. | |||
if champ.label and champ.label ~= '' then | |||
local labelDiv = mw.html.create('div') | |||
:addClass('infobox-label') | |||
:wikitext(champ.label) | |||
rowDiv:node(labelDiv) | |||
end | |||
-- Formatage spécial pour le champ "type" | -- Formatage spécial pour le champ "type" | ||
| Ligne 209 : | Ligne 213 : | ||
end | end | ||
rowDiv | rowDiv:node(valueDiv) | ||
table.insert(sectionRows, rowDiv) | |||
end | end | ||
end | end | ||
end | |||
end | |||
if #sectionRows > 0 then | |||
if section.titre then | |||
local sectionDiv = mw.html.create('div') | |||
:addClass('infobox-section-title') | |||
:wikitext(section.titre) | |||
body:node(sectionDiv) | |||
end | |||
for _, rowDiv in ipairs(sectionRows) do | |||
body:node(rowDiv) | |||
end | end | ||
end | end | ||
| Ligne 223 : | Ligne 239 : | ||
if config.icone then | if config.icone then | ||
local | local iconeConfig = config.icone | ||
local iconeNom = | if type(iconeConfig) == 'function' then | ||
iconeConfig = iconeConfig(args) or {} | |||
end | |||
local iconeType = iconeConfig.type or 'fas' | |||
local iconeNom = iconeConfig.nom | |||
-- Utiliser mw.getCurrentFrame() si frame n'est pas disponible | -- Utiliser mw.getCurrentFrame() si frame n'est pas disponible | ||