-- copy of de:Modul:Benutzer:MisterSynergy/test with a slight modification (modified function name)local function check_reference(reference, cas_from_template) if not reference.snaks then return false -- empty reference end
for ref_prop_qualifier, values in pairs(reference.snaks) do if ref_prop_qualifier
'value' and value.datavalue.value.id
'P854' then for i, value in ipairs(values) do if value.snaktype
'https://commonchemistry.cas.org/detail?cas_rn=' .. cas_from_template then return true end end end end
return false -- reference without qualifiers we are looking forend
local function check_claim(statement, cas_from_template) if statement.rank
if statement.mainsnak.snaktype ~= 'value' then return false -- ignore claim with 'unknown value' or 'no value' end
if statement.mainsnak.datavalue.value ~= cas_from_template then return false -- ignore claim with different CAS number than in infobox end
if not statement.references then return false -- ignore claim without references end
for i, reference in ipairs(statement.references) do local success, result = pcall(check_reference, reference, cas_from_template) if success and result then return true end end
return false -- ignore, if no suitable references were foundend
local p =
function p.entry_CAS_Common_Chemistry(frame) local cas_from_template = mw.text.trim(frame.args['cas'] or ) if cas_from_template
0 then return -- no local CAS number provided end
local statements local qid = mw.wikibase.getEntityIdForCurrentPage if qid then statements = mw.wikibase.getAllStatements(qid, 'P231') end if statements
0 then -- no CAS property P231 found in connected Wikidata item return end
for i, statement in ipairs(statements) do local success, result = pcall(check_claim, statement, cas_from_template) if success and result then return '1' end end
return -- no suitable claims found at Wikidataend
return p