Jump to content
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)
m Catégorie multiple selon champ 'type'
Hiob (discussion | contributions)
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)
 
(7 versions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
local p = {}
local p = {}
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
-- Fonction pour générer le lien de carte dynamique
local function buildMapLink(args)
    -- Vérifier les champs obligatoires
    if not args.x or args.x == '' then return nil end
    if not args.y or args.y == '' then return nil end
    if not args.z or args.z == '' then return nil end
    if not args.worldname or args.worldname == '' then return nil end
   
    -- Valeurs par défaut pour les champs optionnels
    local mapname = args.mapname or 'flat'
    local zoom = args.zoom or '4'
   
    -- Construction de l'URL
    local url = string.format(
        'https://map.nefald.fr/?worldname=%s&mapname=%s&zoom=%s&x=%s&y=%s&z=%s',
        mw.uri.encode(args.worldname, 'PATH'),
        mw.uri.encode(mapname, 'PATH'),
        zoom,
        args.x,
        args.y,
        args.z
    )
   
    -- Retourner le lien formaté
    return string.format('[%s %s, %s, %s]', url, args.x, args.y, args.z)
end


-- Fonction de validation du champ "type"
-- Fonction de validation du champ "type"
Ligne 45 : 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 65 : Ligne 92 :
     return categoryString
     return categoryString
end
end


function p.build(args, config, frame)
function p.build(args, config, frame)
Ligne 120 : Ligne 146 :
     local body = mw.html.create('div')
     local body = mw.html.create('div')
         :addClass('infobox-body')
         :addClass('infobox-body')
    -- Vérifier si on a des coordonnées complètes
    local mapLink = buildMapLink(args)
    local coordinatesDisplayed = false


     for _, section in ipairs(config.sections or {}) do
     for _, section in ipairs(config.sections or {}) do
         if section.titre then
         -- Les lignes de la section sont accumulées ici et intégrées au body seulement
            local sectionDiv = mw.html.create('div')
        -- si au moins une a du contenu — sinon le section-title reste orphelin (ex. une
                :addClass('infobox-section-title')
         -- section "Sous-pages" ou "Compatibilité" entièrement vide sur cette page).
                :wikitext(section.titre)
         local sectionRows = {}
            body:node(sectionDiv)
        end
 
         -- Vérifier si on doit afficher les coordonnées automatiquement
        local hasCoordinates = args.x and args.x ~= '' and args.y and args.y ~= '' and args.z and args.z ~= ''
         local coordinatesDisplayed = false


         for _, champ in ipairs(section.champs or {}) do
         for _, champ in ipairs(section.champs or {}) do
             -- Détection automatique des coordonnées
             -- Gestion spéciale pour les coordonnées
             if hasCoordinates and not coordinatesDisplayed and (champ.cle == 'x' or champ.cle == 'y' or champ.cle == 'z' or champ.cle == 'spawn' or champ.cle == 'coordonnees') then
             if mapLink and not coordinatesDisplayed and (champ.cle == 'x' or champ.cle == 'y' or champ.cle == 'z' or champ.cle == 'worldname' or champ.cle == 'coordonnees') then
                 local rowDiv = mw.html.create('div')
                 local rowDiv = mw.html.create('div')
                     :addClass('infobox-row')
                     :addClass('infobox-row')
Ligne 145 : Ligne 169 :
                 local valueDiv = mw.html.create('div')
                 local valueDiv = mw.html.create('div')
                     :addClass('infobox-value')
                     :addClass('infobox-value')
               
                     :wikitext(mapLink)
                -- Construction du lien vers la carte si le paramètre monde existe
                if args.monde and args.monde ~= '' then
                     local mapUrl = string.format('[https://map.nefald.fr/?worldname=%s&mapname=surface&zoom=4&x=%s&y=%s&z=%s %s, %s, %s]',
                        args.monde, args.x, args.y, args.z, args.x, args.y, args.z)
                    valueDiv:wikitext("''" .. mapUrl .. "''")
                else
                    -- Affichage simple sans lien
                    valueDiv:wikitext(string.format('%s, %s, %s', args.x, args.y, args.z))
                end
                  
                  
                 rowDiv:node(labelDiv):node(valueDiv)
                 rowDiv:node(labelDiv):node(valueDiv)
                 body:node(rowDiv)
                 table.insert(sectionRows, rowDiv)
                 coordinatesDisplayed = true
                 coordinatesDisplayed = true
                  
                  
             -- *** NOUVELLE LOGIQUE POUR TRAITEMENT DES CHAMPS ***
             -- Traitement normal des autres champs (ignorer x, y, z, worldname s'ils sont déjà affichés comme coordonnées)
             elseif not (hasCoordinates and (champ.cle == 'x' or champ.cle == 'y' or champ.cle == 'z')) then
             elseif not (mapLink and (champ.cle == 'x' or champ.cle == 'y' or champ.cle == 'z' or champ.cle == 'worldname' or champ.cle == 'mapname' or champ.cle == 'zoom')) then
                 local rawValue = args[champ.cle]
                 local rawValue = args[champ.cle]
                  
                  
Ligne 178 : Ligne 193 :
                             :addClass('infobox-row')
                             :addClass('infobox-row')


                        local labelDiv = mw.html.create('div')
                            :addClass('infobox-label')
                            :wikitext(champ.label)
                       
                         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 192 : Ligne 213 :
                         end
                         end


                         rowDiv:node(labelDiv):node(valueDiv)
                         rowDiv:node(valueDiv)
                         body:node(rowDiv)
                         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 206 : Ligne 239 :
      
      
     if config.icone then
     if config.icone then
         local iconeType = config.icone.type or 'fas'
         local iconeConfig = config.icone
         local iconeNom = config.icone.nom
        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
Ligne 227 : Ligne 264 :
     end
     end
      
      
     -- Ajouter les catégories automatiques (ancien + nouveau système)
     -- Ajouter les catégories automatiques
     local categories = addCategories(args, config, frame)
     local categories = addCategories(args, config, frame)
      
      
Les témoins (''cookies'') nous aident à fournir nos services. En utilisant nos services, vous acceptez notre utilisation de témoins.