مۆدیوول:Databox: جیاوازیی نێوان پێداچوونەوەکان

ناوەڕۆکی سڕاو ناوەڕۆکی زیادکراو
لابردنی ڕەنگە شینەکەی ناونیشانەکان (بەپێی ئێرە)
Fixed Lua error in 'getBestStatementById' function by checking existence of datavalue field. The problem in the old version was that it didn't handle cases where the datavalue field was missing, causing a Lua error. The new version checks if datavalue exists before accessing its value field, preventing the error. Resolves issue with accessing qualifiers. (here) #Lua #Wikidata #BugFix #DataQualifiers
 
ھێڵی ٢٥٨:
-- Returns the best statements for the first property this item has
function getBestStatementById(id, ...)
for i, v in ipairs(arg) do
local statements = mw.wikibase.getBestStatements( id, v)
if len(#statements) >= 1 and statements[1] then
return local mainsnak = statements[1].mainsnak.datavalue.value
if mainsnak.snaktype == "value" and mainsnak.datavalue then
return mainsnak.datavalue.value
end
end
end
return nil
 
return nil
end