« Module:ZoteroItem » : différence entre les versions

De alcolois
Aller à la navigation Aller à la recherche
Aucun résumé des modifications
Aucun résumé des modifications
Ligne 30 : Ligne 30 :
         return "Erreur : champ 'data' manquant dans le JSON"
         return "Erreur : champ 'data' manquant dans le JSON"
     end
     end
    local escape = mw.text.nowiki  -- alias utile


     local out = {}
     local out = {}
     table.insert(out, "<strong>Titre :</strong> " .. mw.text.escape(d.title or d.caseName or "(sans titre)"))
     table.insert(out, "<strong>Titre :</strong> " .. escape(d.title or d.caseName or "(sans titre)"))


     if d.creators then
     if d.creators then
         local authors = {}
         local authors = {}
         for _, c in ipairs(d.creators) do
         for _, c in ipairs(d.creators) do
             table.insert(authors, mw.text.escape((c.firstName or "") .. " " .. (c.lastName or "")))
             table.insert(authors, escape((c.firstName or "") .. " " .. (c.lastName or "")))
         end
         end
         table.insert(out, "<br><strong>Auteurs :</strong> " .. table.concat(authors, ", "))
         table.insert(out, "<br><strong>Auteurs :</strong> " .. table.concat(authors, ", "))
Ligne 43 : Ligne 45 :


     if d.dateDecided then
     if d.dateDecided then
         table.insert(out, "<br><strong>Date :</strong> " .. mw.text.escape(d.dateDecided))
         table.insert(out, "<br><strong>Date :</strong> " .. escape(d.dateDecided))
     end
     end


     if d.abstractNote then
     if d.abstractNote then
         table.insert(out, "<br><strong>Résumé :</strong> " .. mw.text.escape(d.abstractNote))
         table.insert(out, "<br><strong>Résumé :</strong> " .. escape(d.abstractNote))
     end
     end


     if d.url then
     if d.url then
         table.insert(out, '<br><strong>Lien :</strong> <a href="' .. mw.text.escape(d.url) .. '" target="_blank">Voir</a>')
         table.insert(out, '<br><strong>Lien :</strong> <a href="' .. escape(d.url) .. '" target="_blank">Voir</a>')
     end
     end



Version du 12 juin 2025 à 17:32

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

local p = {}

function p.getItem(frame)
    local key = frame.args[1]
    if not key or key == "" then
        return "Erreur : itemKey requis"
    end

    local groupId = "4893620"
    local url = string.format(
        "https://api.zotero.org/groups/%s/items/%s?format=json&include=data",
        groupId,
        key
    )

    local data, errors = mw.ext.externalData.getExternalData{
        url = url,
        format = "JSON",
        data = { json = "__json" }
    }

    if errors then
        return "Erreur ExternalData : " .. table.concat(errors, "; ")
    elseif not data or not data.json then
        return "Erreur : aucune donnée retournée"
    end

    local d = data.json.data
    if not d then
        return "Erreur : champ 'data' manquant dans le JSON"
    end

    local escape = mw.text.nowiki  -- alias utile

    local out = {}
    table.insert(out, "<strong>Titre :</strong> " .. escape(d.title or d.caseName or "(sans titre)"))

    if d.creators then
        local authors = {}
        for _, c in ipairs(d.creators) do
            table.insert(authors, escape((c.firstName or "") .. " " .. (c.lastName or "")))
        end
        table.insert(out, "<br><strong>Auteurs :</strong> " .. table.concat(authors, ", "))
    end

    if d.dateDecided then
        table.insert(out, "<br><strong>Date :</strong> " .. escape(d.dateDecided))
    end

    if d.abstractNote then
        table.insert(out, "<br><strong>Résumé :</strong> " .. escape(d.abstractNote))
    end

    if d.url then
        table.insert(out, '<br><strong>Lien :</strong> <a href="' .. escape(d.url) .. '" target="_blank">Voir</a>')
    end

    return table.concat(out)
end

return p