« Module:ZoteroItem » : différence entre les versions
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| Ligne 4 : | Ligne 4 : | ||
local key = frame.args[1] | local key = frame.args[1] | ||
if not key or key == "" then | if not key or key == "" then | ||
return "Erreur : | return "Erreur : itemKey requis" | ||
end | end | ||
| Ligne 10 : | Ligne 10 : | ||
local url = string.format( | local url = string.format( | ||
"https://api.zotero.org/groups/%s/items/%s?format=json&include=data", | "https://api.zotero.org/groups/%s/items/%s?format=json&include=data", | ||
groupId, | |||
key | |||
) | ) | ||
local | local data, errors = mw.ext.externalData.getExternalData{ | ||
url = url, | url = url, | ||
format = "JSON" | format = "JSON", | ||
data = { json = "__json" } | |||
} | } | ||
if errors then | |||
if | return "Erreur ExternalData : " .. table.concat(errors, "; ") | ||
return " | elseif not data or not data.json then | ||
elseif | return "Erreur : aucune donnée retournée" | ||
return " | |||
end | end | ||
local d = data.json.data | |||
if not d then | |||
return "Erreur : champ 'data' manquant dans le JSON" | |||
end | |||
local out = {} | |||
table.insert(out, "<strong>Titre :</strong> " .. mw.text.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, mw.text.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> " .. mw.text.escape(d.dateDecided)) | |||
end | |||
if d.abstractNote then | |||
table.insert(out, "<br><strong>Résumé :</strong> " .. mw.text.escape(d.abstractNote)) | |||
end | |||
if d.url then | |||
table.insert(out, '<br><strong>Lien :</strong> <a href="' .. mw.text.escape(d.url) .. '" target="_blank">Voir</a>') | |||
end | |||
return table.concat(out) | |||
end | end | ||
return p | return p | ||