« Module:Infobox/Core » : différence entre les versions
De Nefald
Autres actions
Ajout catégorisation automatique (namespace 0) selon le type Balises : Modification par mobile Modification par le web mobile |
m liens des champs (processed) |
||
| Ligne 44 : | Ligne 44 : | ||
-- Fonction pour gérer la catégorisation automatique | -- Fonction pour gérer la catégorisation automatique | ||
local function | 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) | ||
local title = mw.title.getCurrentTitle() | local title = mw.title.getCurrentTitle() | ||
| Ligne 51 : | Ligne 51 : | ||
end | end | ||
local categoryString = '' | |||
local typeValue = args.type or args['type'] | -- Catégories automatiques du type (ancien système) | ||
if config.typeField and config.typeField.allowedValues then | |||
local typeValue = args.type or args['type'] | |||
if typeValue and typeValue ~= '' then | |||
local cleanType = mw.text.trim(mw.ustring.lower(typeValue)) | |||
local typeConfig = config.typeField.allowedValues[cleanType] | |||
if typeConfig and typeConfig.category then | |||
categoryString = categoryString .. '[[Catégorie:' .. typeConfig.category .. ']]' | |||
end | |||
end | |||
end | end | ||
-- | -- Nouvelles catégories configurables (fonction categories) | ||
if type(config.categories) == 'function' then | |||
local cats = config.categories(args, config, frame) | |||
if cats then | |||
for _, cat in ipairs(cats) do | |||
categoryString = categoryString .. '[[Catégorie:' .. cat .. ']]' | |||
end | |||
end | |||
end | end | ||
return | return categoryString | ||
end | end | ||
| Ligne 166 : | Ligne 171 : | ||
coordinatesDisplayed = true | coordinatesDisplayed = true | ||
-- | -- *** NOUVELLE LOGIQUE POUR TRAITEMENT DES CHAMPS *** | ||
elseif not (hasCoordinates and (champ.cle == 'x' or champ.cle == 'y' or champ.cle == 'z')) | elseif not (hasCoordinates and (champ.cle == 'x' or champ.cle == 'y' or champ.cle == 'z')) then | ||
local rawValue = args[champ.cle] | |||
-- Si le champ a une valeur OU une fonction process qui peut générer une valeur | |||
if (rawValue and rawValue ~= '') or champ.process then | |||
local finalValue = rawValue | |||
-- Appliquer la fonction process si elle existe | |||
if champ.process and type(champ.process) == 'function' then | |||
finalValue = champ.process(rawValue, args, frame) | |||
end | |||
-- N'afficher que si on a une valeur finale | |||
if finalValue and finalValue ~= '' then | |||
local rowDiv = mw.html.create('div') | |||
:addClass('infobox-row') | |||
local labelDiv = mw.html.create('div') | |||
:addClass('infobox-label') | |||
:wikitext(champ.label) | |||
local valueDiv = mw.html.create('div') | |||
:addClass('infobox-value') | |||
-- Formatage spécial pour le champ "type" | |||
if champ.cle == 'type' and typeValidation.displayValue then | |||
valueDiv:wikitext(typeValidation.displayValue) | |||
else | |||
valueDiv:wikitext(finalValue) | |||
end | |||
rowDiv:node(labelDiv):node(valueDiv) | |||
body:node(rowDiv) | |||
end | |||
end | end | ||
end | end | ||
end | end | ||
| Ligne 218 : | Ligne 238 : | ||
end | end | ||
-- Ajouter les catégories automatiques | -- Ajouter les catégories automatiques (ancien + nouveau système) | ||
local categories = | local categories = addCategories(args, config, frame) | ||
return finalResult .. categories | return finalResult .. categories | ||