Basculer le menu
Changer de menu des préférences
Basculer le menu personnel
Non connecté(e)
Votre adresse IP sera visible au public si vous faites des modifications.

« Module:Infobox/Core » : différence entre les versions

De Nefald
Hiob (discussion | contributions)
Ajout catégorisation automatique (namespace 0) selon le type
Balises : Modification par mobile Modification par le web mobile
Hiob (discussion | contributions)
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 addTypeCategories(args, config)
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
      
      
     -- Pas de configuration de type, pas de catégorie
     local categoryString = ''
    if not config.typeField or not config.typeField.allowedValues then
        return ''
    end
      
      
     local typeValue = args.type or args['type']
     -- Catégories automatiques du type (ancien système)
    if not typeValue or typeValue == '' then
    if config.typeField and config.typeField.allowedValues then
        return ''
        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
      
      
     -- Nettoyer la valeur
     -- Nouvelles catégories configurables (fonction categories)
     local cleanType = mw.text.trim(mw.ustring.lower(typeValue))
     if type(config.categories) == 'function' then
   
        local cats = config.categories(args, config, frame)
    -- Récupérer la catégorie correspondante
        if cats then
    local typeConfig = config.typeField.allowedValues[cleanType]
            for _, cat in ipairs(cats) do
    if typeConfig and typeConfig.category then
                categoryString = categoryString .. '[[Catégorie:' .. cat .. ']]'
        return '[[Catégorie:' .. typeConfig.category .. ']]'
            end
        end
     end
     end
      
      
     return ''
     return categoryString
end
end


Ligne 166 : Ligne 171 :
                 coordinatesDisplayed = true
                 coordinatesDisplayed = true
                  
                  
             -- Traitement normal des autres champs avec formatage spécial pour le type
             -- *** NOUVELLE LOGIQUE POUR TRAITEMENT DES CHAMPS ***
             elseif not (hasCoordinates and (champ.cle == 'x' or champ.cle == 'y' or champ.cle == 'z')) and args[champ.cle] and args[champ.cle] ~= '' then
             elseif not (hasCoordinates and (champ.cle == 'x' or champ.cle == 'y' or champ.cle == 'z')) then
                local rowDiv = mw.html.create('div')
                local rawValue = args[champ.cle]
                    :addClass('infobox-row')
               
                -- 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


                local labelDiv = mw.html.create('div')
                        rowDiv:node(labelDiv):node(valueDiv)
                    :addClass('infobox-label')
                        body:node(rowDiv)
                    :wikitext(champ.label)
                     end
               
                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(args[champ.cle])
                 end
                 end
                rowDiv:node(labelDiv):node(valueDiv)
                body:node(rowDiv)
             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 = addTypeCategories(args, config)
     local categories = addCategories(args, config, frame)
      
      
     return finalResult .. categories
     return finalResult .. categories
Les témoins (''cookies'') nous aident à fournir nos services. En utilisant nos services, vous acceptez notre utilisation de témoins.