Module:Sandbox/Umarxon III explained
--getImageLegend | PARAMETER | lang= |id=}}Returns PARAMETER, unless it is equal to "FETCH_WIKIDATA" from Item QID (expensive call)If QID is omitted or blank, the current article is used (not expensive call)If lang is omitted, it uses the local wiki language, otherwise it uses the provided ISO-639 language codeISO-639: https://docs.oracle.com/cd/E13214_01/wli/docs92/xref/xqisocodes.html#wp1252447Ranks are: 'preferred' > 'normal'At present this just works with 'preferred'ToDo: We could just look at normal ranks if preferred returns nothingRanks: https://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua
In South Pole Telescope, the structure of P18 is: ["P18"] = table#26,
local p =
p.getImageLegend = function(frame) -- look for named parameter id; if it's blank make it nil local id = frame.args.id if id and (#id
0) then id = nil end -- look for named parameter lang -- it should contain a two-character ISO-639 language code -- if it's blank fetch the language of the local wiki local lang = frame.args.lang if (not lang) or (#lang < 2) then lang = mw.language.getContentLanguage.code end -- first unnamed parameter is the local parameter, if supplied local input_parm = mw.text.trim(frame.args[1] or "") if input_parm
"FETCH_WIKIDATA" then local ent = mw.wikibase.getEntityObject(id) local imgs if ent and ent.claims then imgs = ent.claims.P18 end local imglbl if imgs then -- look for an image with 'preferred' rank for k1, v1 in pairs(imgs) do if v1.rank
"preferred" and v1.qualifiers.P2096 then local imglbls = v1.qualifiers.P2096 for k2, v2 in pairs(imglbls) do if v2.datavalue.value.language
lang then imglbl = v2.datavalue.value.text break end end end end -- if we don't find one, look for an image with 'normal' rank if (not imglbl) then for k1, v1 in pairs(imgs) do if v1.rank
"normal" and v1.qualifiers.P2096 then local imglbls = v1.qualifiers.P2096 for k2, v2 in pairs(imglbls) do if v2.datavalue.value.language
lang then imglbl = v2.datavalue.value.text break end end end end end end return imglbl else return input_parm endend
return p