« Module:ZoteroItem » : différence entre les versions
Aller à la navigation
Aller à la recherche
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| Ligne 1 : | Ligne 1 : | ||
local p = {} | local p = {} | ||
function p.getItem(frame) | function p.getItem(frame) | ||
local key = frame.args[1] | local key = frame.args[1] | ||
| Ligne 16 : | Ligne 6 : | ||
return "Erreur : aucun itemKey fourni" | return "Erreur : aucun itemKey fourni" | ||
end | end | ||
local groupId = | |||
local groupId = "4893620" | |||
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", | ||
| Ligne 28 : | Ligne 19 : | ||
} | } | ||
-- 🔍 Diagnostic détaillé | |||
if errs then | if errs then | ||
return " | return "DEBUG: erreurs rencontrées : " .. table.concat(errs, "; ") | ||
elseif | elseif t == nil then | ||
return " | return "DEBUG: t est nil — la requête n’a rien retourné" | ||
elseif type(t) == "string" then | elseif type(t) == "string" then | ||
return " | return "DEBUG: t est une chaîne ! Contenu brut = " .. mw.text.escape(t) | ||
elseif not t.__json then | elseif not t.__json then | ||
return " | return "DEBUG: t est une table, mais sans champ '__json'. Contenu brut = " .. mw.text.jsonEncode(t) | ||
else | |||
return "DEBUG: succès ! Contenu de __json = " .. mw.text.jsonEncode(t.__json) | |||
end | end | ||
end | end | ||
return p | return p | ||
Version du 12 juin 2025 à 17:24
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 : aucun itemKey fourni"
end
local groupId = "4893620"
local url = string.format(
"https://api.zotero.org/groups/%s/items/%s?format=json&include=data",
mw.uri.encode(groupId),
mw.uri.encode(key)
)
local t, errs = mw.ext.externalData.getWebData{
url = url,
format = "JSON"
}
-- 🔍 Diagnostic détaillé
if errs then
return "DEBUG: erreurs rencontrées : " .. table.concat(errs, "; ")
elseif t == nil then
return "DEBUG: t est nil — la requête n’a rien retourné"
elseif type(t) == "string" then
return "DEBUG: t est une chaîne ! Contenu brut = " .. mw.text.escape(t)
elseif not t.__json then
return "DEBUG: t est une table, mais sans champ '__json'. Contenu brut = " .. mw.text.jsonEncode(t)
else
return "DEBUG: succès ! Contenu de __json = " .. mw.text.jsonEncode(t.__json)
end
end
return p