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:PageInfo » : différence entre les versions

De Nefald
Hiob (discussion | contributions)
Page créée avec « local p = {} -- Fonction pour extraire la description function p.getDescription(frame) local pageName = frame.args[1] if not pageName or pageName == '' then return "''Erreur : nom de page manquant''" end local pageObj = mw.title.new(pageName) if not pageObj or not pageObj.exists then return "''Page inexistante''" end local texte = pageObj:getContent() if not texte then return "''Auc... »
 
Hiob (discussion | contributions)
Annulation des modifications 735 de Hiob (discussion)
Balise : Annulation
 
(4 versions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
local p = {}
local p = {}


-- Fonction pour extraire la description
-- Fonction principale qui retourne toutes les infos d'une page
function p.getDescription(frame)
function p.getInfo(frame)
     local pageName = frame.args[1]
     local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return "'''Erreur :''' Aucun nom de page fourni"
    end
      
      
    local pageObj = mw.title.new(pageName)
    if not pageObj then
        return "'''Erreur :''' Titre invalide : " .. pageName
    end
   
    if not pageObj.exists then
        return "'''Erreur :''' La page '" .. pageName .. "' n'existe pas"
    end
   
    local result = {}
   
    -- Informations de base
    table.insert(result, "=== Informations de la page ===")
    table.insert(result, "* '''Titre complet :''' " .. pageObj.prefixedText)
    table.insert(result, "* '''Namespace :''' " .. pageObj.nsText)
    table.insert(result, "* '''Titre (sans namespace) :''' " .. pageObj.text)
    table.insert(result, "* '''URL :''' " .. pageObj:fullUrl())
    table.insert(result, "* '''ID de la page :''' " .. pageObj.id)
   
    -- Contenu
    local content = pageObj:getContent()
    if content then
        local contentLength = mw.ustring.len(content)
        table.insert(result, "* '''Taille du contenu :''' " .. contentLength .. " caractères")
       
        -- Compter les sections
        local _, sectionCount = content:gsub('\n==', '\n==')
        table.insert(result, "* '''Nombre de sections :''' " .. sectionCount)
    end
   
    -- Catégories
    local categories = pageObj.categories
    if categories and #categories > 0 then
        table.insert(result, "* '''Catégories :''' " .. #categories)
        local catList = {}
        for _, cat in ipairs(categories) do
            table.insert(catList, cat.text)
        end
        table.insert(result, "** " .. table.concat(catList, ", "))
    else
        table.insert(result, "* '''Catégories :''' Aucune")
    end
   
    -- Protection
    if pageObj.protectionLevels and next(pageObj.protectionLevels) then
        table.insert(result, "* '''Protection :''' Oui")
        for action, level in pairs(pageObj.protectionLevels) do
            table.insert(result, "** " .. action .. " : " .. table.concat(level, ", "))
        end
    else
        table.insert(result, "* '''Protection :''' Non")
    end
   
    -- Redirection
    if pageObj.isRedirect then
        table.insert(result, "* '''Type :''' Page de redirection")
    else
        table.insert(result, "* '''Type :''' Page normale")
    end
   
    return table.concat(result, "\n")
end
-- Fonction pour obtenir uniquement le titre
function p.getTitle(frame)
    local pageName = frame.args[1]
     if not pageName or pageName == '' then
     if not pageName or pageName == '' then
         return "''Erreur : nom de page manquant''"
         return ''
     end
     end
      
      
     local pageObj = mw.title.new(pageName)
     local pageObj = mw.title.new(pageName)
    if not pageObj or not pageObj.exists then
        return "''Page inexistante''"
    end
   
    return pageObj.text
end
-- Fonction pour obtenir le namespace
function p.getNamespace(frame)
    local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return ''
    end
      
      
    local pageObj = mw.title.new(pageName)
     if not pageObj or not pageObj.exists then
     if not pageObj or not pageObj.exists then
         return "''Page inexistante''"
         return "''Page inexistante''"
     end
     end
      
      
     local texte = pageObj:getContent()
     return pageObj.nsText ~= '' and pageObj.nsText or 'Principal'
end
 
-- Fonction pour obtenir l'URL complète
function p.getUrl(frame)
    local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return ''
    end
      
      
     if not texte then
    local pageObj = mw.title.new(pageName)
         return "''Aucune description''"
     if not pageObj or not pageObj.exists then
         return "''Page inexistante''"
    end
   
    return pageObj:fullUrl()
end
 
-- Fonction pour obtenir les catégories
function p.getCategories(frame)
    local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return ''
     end
     end
      
      
     -- 1. Chercher {{Short description|...}}
     local pageObj = mw.title.new(pageName)
    local shortDesc = texte:match('{{[Ss]hort%s+description|([^}]+)}}')
     if not pageObj or not pageObj.exists then
     if shortDesc then
         return "''Page inexistante''"
         return mw.text.trim(shortDesc)
     end
     end
      
      
     -- 2. Chercher dans les infobox (paramètre description)
     local categories = pageObj.categories
     local infoboxDesc = texte:match('|%s*description%s*=%s*([^\n|]+)')
     if not categories or #categories == 0 then
    if infoboxDesc then
         return "''Aucune catégorie''"
         infoboxDesc = mw.text.trim(infoboxDesc)
        if #infoboxDesc > 10 then
            return infoboxDesc
        end
     end
     end
      
      
     -- 3. Utiliser TextExtract (premier paragraphe nettoyé)
     local catList = {}
     local extract = getTextExtract(texte)
     for _, cat in ipairs(categories) do
    if extract and #extract > 10 then
         table.insert(catList, cat.text)
         return extract
     end
     end
      
      
     return "''Aucune description''"
     return table.concat(catList, ', ')
end
end


-- Fonction pour extraire le lien de documentation
-- Fonction pour extraire la description d'une page
function p.getDocumentation(frame)
function p.getDescription(frame)
     local pageName = frame.args[1]
     local pageName = frame.args[1]
   
     if not pageName or pageName == '' then
     if not pageName or pageName == '' then
         return ''
         return ''
     end
     end
      
      
     local pageObj = mw.title.new(pageName)
     local pageObj = mw.title.new(pageName)
    if not pageObj or not pageObj.exists then
        return "''Page inexistante''"
    end
      
      
     if not pageObj or not pageObj.exists then
    local content = pageObj:getContent()
         return ''
     if not content then
        return ''
    end
   
    -- PRIORITÉ 1 : Chercher {{SHORTDESC:...}} (magic word de l'extension)
    local desc = content:match('{{SHORTDESC:([^}]+)}}')
    if desc then
         desc = mw.text.trim(desc)
        if desc ~= '' then
            return desc
        end
     end
     end
      
      
     local texte = pageObj:getContent()
     -- PRIORITÉ 1bis : Chercher aussi {{Short description|...}} (template standard)
    desc = content:match('{{[Ss]hort%s+description%s*|%s*([^}]+)}}')
    if desc then
        desc = mw.text.trim(desc)
        desc = desc:gsub('|.*$', '') -- Nettoyer paramètres supplémentaires
        if desc ~= '' then
            return desc
        end
    end
      
      
     if not texte then
    -- PRIORITÉ 2 : Chercher dans un champ description d'infobox
         return ''
    desc = content:match('|%s*description%s*=%s*([^\n|]+)')
     if desc then
         desc = mw.text.trim(desc)
        if desc ~= '' and #desc > 10 then
            return desc
        end
     end
     end
      
      
     -- Chercher le paramètre documentation dans n'importe quelle infobox
     -- PRIORITÉ 3 : Extraire le premier paragraphe après l'infobox
     local docParam = texte:match('|%s*documentation%s*=%s*([^\n|]+)')
     local afterInfobox = content:match('}}%s*\n(.+)')
      
      
     if docParam then
     if afterInfobox then
         docParam = mw.text.trim(docParam)
         local beforeSection = afterInfobox:match('^(.-)%s*\n%s*==')
          
          
        -- Si c'est déjà un lien wiki formaté [url texte]
         if not beforeSection then
         if docParam:match('^%[http') then
             beforeSection = afterInfobox
             return docParam
         end
         end
          
          
         -- Si c'est une URL brute
         local cleaned = beforeSection
        if docParam:match('^https?://') then
            return '[' .. docParam .. ' 📖 Documentation]'
        end
          
          
         -- Si c'est un lien wiki interne [[Page]]
         -- Supprimer les magic words et templates
         if docParam:match('^%[%[') then
        cleaned = cleaned:gsub('{{SHORTDESC:[^}]+}}', '')
            return docParam
        cleaned = cleaned:gsub('{{[^}]+}}', '')
         end
         cleaned = cleaned:gsub('%[%[[Cc]ategor[yi]e?:[^%]]+%]%]', '')
        cleaned = cleaned:gsub('<[^>]+>', '')
        cleaned = cleaned:gsub('\n\n+', '\n')
        cleaned = cleaned:gsub("'''", '')
         cleaned = cleaned:gsub("''", '')
          
          
         -- Si c'est juste du texte
         for line in cleaned:gmatch('[^\n]+') do
        if #docParam > 0 then
            line = mw.text.trim(line)
             return docParam
           
            if line ~= ''
              and not line:match('^[*#:;]')
              and not line:match('^%s*{|')
              and not line:match('^%s*|}')
              and not line:match('^%s*|[^%[]')
              and #line > 30 then
               
                if #line > 300 then
                    local cut = line:sub(1, 297)
                    local lastPeriod = cut:match('.*()%.%s')
                    if lastPeriod and lastPeriod > 200 then
                        line = cut:sub(1, lastPeriod)
                    else
                        line = cut .. '...'
                    end
                end
               
                return line
             end
         end
         end
     end
     end
      
      
     -- Chercher aussi |lien=, |url=, |site=
     return "''Aucune description disponible''"
    for _, param in ipairs({'lien', 'url', 'site', 'website'}) do
end
        local link = texte:match('|%s*' .. param .. '%s*=%s*([^\n|]+)')
 
         if link then
-- Fonction pour obtenir la taille de la page
            link = mw.text.trim(link)
function p.getSize(frame)
            if link:match('^https?://') then
    local pageName = frame.args[1]
                return '[' .. link .. ' 🔗 Lien]'
    if not pageName or pageName == '' then
            end
        return ''
         end
    end
   
    local pageObj = mw.title.new(pageName)
    if not pageObj or not pageObj.exists then
        return "''Page inexistante''"
    end
   
    local content = pageObj:getContent()
    if not content then
        return '0'
    end
   
    return tostring(mw.ustring.len(content))
end
 
-- Fonction pour compter les sections
function p.countSections(frame)
    local pageName = frame.args[1]
    if not pageName or pageName == '' then
         return '0'
    end
   
    local pageObj = mw.title.new(pageName)
    if not pageObj or not pageObj.exists then
        return "''Page inexistante''"
    end
   
    local content = pageObj:getContent()
    if not content then
         return '0'
     end
     end
      
      
     return ''
     local _, count = content:gsub('\n==', '\n==')
    return tostring(count)
end
end


-- Fonction interne pour extraire le premier paragraphe (façon TextExtract)
-- Fonction pour vérifier si une page est protégée
function getTextExtract(texte)
function p.isProtected(frame)
     -- Supprimer les infobox et templates au début
     local pageName = frame.args[1]
     texte = texte:gsub('{{.-}}', '')
     if not pageName or pageName == '' then
        return 'Non'
    end
      
      
     -- Supprimer les balises HTML
     local pageObj = mw.title.new(pageName)
     texte = texte:gsub('<[^>]+>', '')
     if not pageObj or not pageObj.exists then
        return "''Page inexistante''"
    end
      
      
     -- Supprimer les références
     if pageObj.protectionLevels and next(pageObj.protectionLevels) then
     texte = texte:gsub('<ref[^>]*>.-</ref>', '')
        return 'Oui'
     texte = texte:gsub('<ref[^/>]*/', '')
    else
        return 'Non'
    end
end
 
-- Fonction pour vérifier si une page est une redirection
function p.isRedirect(frame)
     local pageName = frame.args[1]
     if not pageName or pageName == '' then
        return 'Non'
    end
      
      
     -- Supprimer les liens internes mais garder le texte affiché
     local pageObj = mw.title.new(pageName)
    texte = texte:gsub('%[%[([^%]|]+)|([^%]]+)%]%]', '%2')
     if not pageObj or not pageObj.exists then
     texte = texte:gsub('%[%[([^%]]+)%]%]', '%1')
        return "''Page inexistante''"
    end
      
      
     -- Supprimer les liens externes
     return pageObj.isRedirect and 'Oui' or 'Non'
     texte = texte:gsub('%[http[^%]]+%]', '')
end
 
-- Fonction pour obtenir l'ID de la page
function p.getId(frame)
     local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return ''
    end
      
      
     -- Supprimer les balises wiki (gras, italique)
     local pageObj = mw.title.new(pageName)
     texte = texte:gsub("'''", '')
     if not pageObj or not pageObj.exists then
     texte = texte:gsub("''", '')
        return "''Page inexistante''"
     end
      
      
     -- Supprimer les fichiers/images
     return tostring(pageObj.id)
     texte = texte:gsub('%[%[[Ff]ichier:.-]]', '')
end
     texte = texte:gsub('%[%[[Ii]mage:.-]]', '')
 
     texte = texte:gsub('%[%[[Ff]ile:.-]]', '')
-- Fonction pour obtenir le titre complet (avec namespace)
function p.getFullTitle(frame)
     local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return ''
     end
   
    local pageObj = mw.title.new(pageName)
    if not pageObj or not pageObj.exists then
        return "''Page inexistante''"
    end
   
    return pageObj.prefixedText
end
 
-- Fonction pour extraire l'image principale de la page
function p.getMainImage(frame)
    local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return ''
     end
   
    local pageObj = mw.title.new(pageName)
    if not pageObj or not pageObj.exists then
        return "''Page inexistante''"
    end
   
    local content = pageObj:getContent()
    if not content then
        return ''
    end
      
      
     -- Trouver le premier paragraphe significatif
     -- Chercher dans l'infobox d'abord
     for ligne in texte:gmatch('[^\n]+') do
     local image = content:match('|%s*image%s*=%s*([^\n|]+)')
         ligne = mw.text.trim(ligne)
    if image then
       
         image = mw.text.trim(image)
         -- Ignorer les lignes vides, titres, listes
         -- Nettoyer les éventuels paramètres de taille
         if #ligne > 30 and not ligne:match('^[=*#:;]') and not ligne:match('^{|') then
         image = image:gsub('%s*|.*$', '')
            -- Limiter à 200 caractères
        if image ~= '' then
            if #ligne > 200 then
             return image
                ligne = ligne:sub(1, 197) .. '...'
            end
             return ligne
         end
         end
     end
     end
      
      
     return nil
     -- Chercher la première image dans le contenu
    image = content:match('%[%[Fichier:([^%]|]+)')
    if not image then
        image = content:match('%[%[File:([^%]|]+)')
    end
    if not image then
        image = content:match('%[%[Image:([^%]|]+)')
    end
   
    if image then
        return mw.text.trim(image)
    end
   
    return "''Aucune image''"
end
 
-- Fonction pour obtenir la date de dernière modification
function p.getLastModified(frame)
    local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return ''
    end
   
    local pageObj = mw.title.new(pageName)
    if not pageObj or not pageObj.exists then
        return "''Page inexistante''"
    end
   
    -- Utiliser l'API pour obtenir la date de dernière modification
    local revId = pageObj.latest
    if not revId then
        return "''Indisponible''"
    end
   
    return "Révision #" .. revId
end
end


return p
return p

Dernière version du 7 octobre 2025 à 11:52

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

local p = {}

-- Fonction principale qui retourne toutes les infos d'une page
function p.getInfo(frame)
    local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return "'''Erreur :''' Aucun nom de page fourni"
    end
    
    local pageObj = mw.title.new(pageName)
    if not pageObj then
        return "'''Erreur :''' Titre invalide : " .. pageName
    end
    
    if not pageObj.exists then
        return "'''Erreur :''' La page '" .. pageName .. "' n'existe pas"
    end
    
    local result = {}
    
    -- Informations de base
    table.insert(result, "=== Informations de la page ===")
    table.insert(result, "* '''Titre complet :''' " .. pageObj.prefixedText)
    table.insert(result, "* '''Namespace :''' " .. pageObj.nsText)
    table.insert(result, "* '''Titre (sans namespace) :''' " .. pageObj.text)
    table.insert(result, "* '''URL :''' " .. pageObj:fullUrl())
    table.insert(result, "* '''ID de la page :''' " .. pageObj.id)
    
    -- Contenu
    local content = pageObj:getContent()
    if content then
        local contentLength = mw.ustring.len(content)
        table.insert(result, "* '''Taille du contenu :''' " .. contentLength .. " caractères")
        
        -- Compter les sections
        local _, sectionCount = content:gsub('\n==', '\n==')
        table.insert(result, "* '''Nombre de sections :''' " .. sectionCount)
    end
    
    -- Catégories
    local categories = pageObj.categories
    if categories and #categories > 0 then
        table.insert(result, "* '''Catégories :''' " .. #categories)
        local catList = {}
        for _, cat in ipairs(categories) do
            table.insert(catList, cat.text)
        end
        table.insert(result, "** " .. table.concat(catList, ", "))
    else
        table.insert(result, "* '''Catégories :''' Aucune")
    end
    
    -- Protection
    if pageObj.protectionLevels and next(pageObj.protectionLevels) then
        table.insert(result, "* '''Protection :''' Oui")
        for action, level in pairs(pageObj.protectionLevels) do
            table.insert(result, "** " .. action .. " : " .. table.concat(level, ", "))
        end
    else
        table.insert(result, "* '''Protection :''' Non")
    end
    
    -- Redirection
    if pageObj.isRedirect then
        table.insert(result, "* '''Type :''' Page de redirection")
    else
        table.insert(result, "* '''Type :''' Page normale")
    end
    
    return table.concat(result, "\n")
end

-- Fonction pour obtenir uniquement le titre
function p.getTitle(frame)
    local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return ''
    end
    
    local pageObj = mw.title.new(pageName)
    if not pageObj or not pageObj.exists then
        return "''Page inexistante''"
    end
    
    return pageObj.text
end

-- Fonction pour obtenir le namespace
function p.getNamespace(frame)
    local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return ''
    end
    
    local pageObj = mw.title.new(pageName)
    if not pageObj or not pageObj.exists then
        return "''Page inexistante''"
    end
    
    return pageObj.nsText ~= '' and pageObj.nsText or 'Principal'
end

-- Fonction pour obtenir l'URL complète
function p.getUrl(frame)
    local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return ''
    end
    
    local pageObj = mw.title.new(pageName)
    if not pageObj or not pageObj.exists then
        return "''Page inexistante''"
    end
    
    return pageObj:fullUrl()
end

-- Fonction pour obtenir les catégories
function p.getCategories(frame)
    local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return ''
    end
    
    local pageObj = mw.title.new(pageName)
    if not pageObj or not pageObj.exists then
        return "''Page inexistante''"
    end
    
    local categories = pageObj.categories
    if not categories or #categories == 0 then
        return "''Aucune catégorie''"
    end
    
    local catList = {}
    for _, cat in ipairs(categories) do
        table.insert(catList, cat.text)
    end
    
    return table.concat(catList, ', ')
end

-- Fonction pour extraire la description d'une page
function p.getDescription(frame)
    local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return ''
    end
    
    local pageObj = mw.title.new(pageName)
    if not pageObj or not pageObj.exists then
        return "''Page inexistante''"
    end
    
    local content = pageObj:getContent()
    if not content then
        return ''
    end
    
    -- PRIORITÉ 1 : Chercher {{SHORTDESC:...}} (magic word de l'extension)
    local desc = content:match('{{SHORTDESC:([^}]+)}}')
    if desc then
        desc = mw.text.trim(desc)
        if desc ~= '' then
            return desc
        end
    end
    
    -- PRIORITÉ 1bis : Chercher aussi {{Short description|...}} (template standard)
    desc = content:match('{{[Ss]hort%s+description%s*|%s*([^}]+)}}')
    if desc then
        desc = mw.text.trim(desc)
        desc = desc:gsub('|.*$', '') -- Nettoyer paramètres supplémentaires
        if desc ~= '' then
            return desc
        end
    end
    
    -- PRIORITÉ 2 : Chercher dans un champ description d'infobox
    desc = content:match('|%s*description%s*=%s*([^\n|]+)')
    if desc then
        desc = mw.text.trim(desc)
        if desc ~= '' and #desc > 10 then
            return desc
        end
    end
    
    -- PRIORITÉ 3 : Extraire le premier paragraphe après l'infobox
    local afterInfobox = content:match('}}%s*\n(.+)')
    
    if afterInfobox then
        local beforeSection = afterInfobox:match('^(.-)%s*\n%s*==')
        
        if not beforeSection then
            beforeSection = afterInfobox
        end
        
        local cleaned = beforeSection
        
        -- Supprimer les magic words et templates
        cleaned = cleaned:gsub('{{SHORTDESC:[^}]+}}', '')
        cleaned = cleaned:gsub('{{[^}]+}}', '')
        cleaned = cleaned:gsub('%[%[[Cc]ategor[yi]e?:[^%]]+%]%]', '')
        cleaned = cleaned:gsub('<[^>]+>', '')
        cleaned = cleaned:gsub('\n\n+', '\n')
        cleaned = cleaned:gsub("'''", '')
        cleaned = cleaned:gsub("''", '')
        
        for line in cleaned:gmatch('[^\n]+') do
            line = mw.text.trim(line)
            
            if line ~= '' 
               and not line:match('^[*#:;]') 
               and not line:match('^%s*{|')
               and not line:match('^%s*|}')
               and not line:match('^%s*|[^%[]')
               and #line > 30 then
                
                if #line > 300 then
                    local cut = line:sub(1, 297)
                    local lastPeriod = cut:match('.*()%.%s')
                    if lastPeriod and lastPeriod > 200 then
                        line = cut:sub(1, lastPeriod)
                    else
                        line = cut .. '...'
                    end
                end
                
                return line
            end
        end
    end
    
    return "''Aucune description disponible''"
end

-- Fonction pour obtenir la taille de la page
function p.getSize(frame)
    local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return ''
    end
    
    local pageObj = mw.title.new(pageName)
    if not pageObj or not pageObj.exists then
        return "''Page inexistante''"
    end
    
    local content = pageObj:getContent()
    if not content then
        return '0'
    end
    
    return tostring(mw.ustring.len(content))
end

-- Fonction pour compter les sections
function p.countSections(frame)
    local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return '0'
    end
    
    local pageObj = mw.title.new(pageName)
    if not pageObj or not pageObj.exists then
        return "''Page inexistante''"
    end
    
    local content = pageObj:getContent()
    if not content then
        return '0'
    end
    
    local _, count = content:gsub('\n==', '\n==')
    return tostring(count)
end

-- Fonction pour vérifier si une page est protégée
function p.isProtected(frame)
    local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return 'Non'
    end
    
    local pageObj = mw.title.new(pageName)
    if not pageObj or not pageObj.exists then
        return "''Page inexistante''"
    end
    
    if pageObj.protectionLevels and next(pageObj.protectionLevels) then
        return 'Oui'
    else
        return 'Non'
    end
end

-- Fonction pour vérifier si une page est une redirection
function p.isRedirect(frame)
    local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return 'Non'
    end
    
    local pageObj = mw.title.new(pageName)
    if not pageObj or not pageObj.exists then
        return "''Page inexistante''"
    end
    
    return pageObj.isRedirect and 'Oui' or 'Non'
end

-- Fonction pour obtenir l'ID de la page
function p.getId(frame)
    local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return ''
    end
    
    local pageObj = mw.title.new(pageName)
    if not pageObj or not pageObj.exists then
        return "''Page inexistante''"
    end
    
    return tostring(pageObj.id)
end

-- Fonction pour obtenir le titre complet (avec namespace)
function p.getFullTitle(frame)
    local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return ''
    end
    
    local pageObj = mw.title.new(pageName)
    if not pageObj or not pageObj.exists then
        return "''Page inexistante''"
    end
    
    return pageObj.prefixedText
end

-- Fonction pour extraire l'image principale de la page
function p.getMainImage(frame)
    local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return ''
    end
    
    local pageObj = mw.title.new(pageName)
    if not pageObj or not pageObj.exists then
        return "''Page inexistante''"
    end
    
    local content = pageObj:getContent()
    if not content then
        return ''
    end
    
    -- Chercher dans l'infobox d'abord
    local image = content:match('|%s*image%s*=%s*([^\n|]+)')
    if image then
        image = mw.text.trim(image)
        -- Nettoyer les éventuels paramètres de taille
        image = image:gsub('%s*|.*$', '')
        if image ~= '' then
            return image
        end
    end
    
    -- Chercher la première image dans le contenu
    image = content:match('%[%[Fichier:([^%]|]+)')
    if not image then
        image = content:match('%[%[File:([^%]|]+)')
    end
    if not image then
        image = content:match('%[%[Image:([^%]|]+)')
    end
    
    if image then
        return mw.text.trim(image)
    end
    
    return "''Aucune image''"
end

-- Fonction pour obtenir la date de dernière modification
function p.getLastModified(frame)
    local pageName = frame.args[1]
    if not pageName or pageName == '' then
        return ''
    end
    
    local pageObj = mw.title.new(pageName)
    if not pageObj or not pageObj.exists then
        return "''Page inexistante''"
    end
    
    -- Utiliser l'API pour obtenir la date de dernière modification
    local revId = pageObj.latest
    if not revId then
        return "''Indisponible''"
    end
    
    return "Révision #" .. revId
end

return p