Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:CommonChemistry
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
-- 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 == 'P248' then for i, value in ipairs(values) do if value.snaktype == 'value' and value.datavalue.value.id == 'Q18907859' then return true end end end if ref_prop_qualifier == 'P854' then for i, value in ipairs(values) do if value.snaktype == 'value' and value.datavalue.value == '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 for end local function check_claim(statement, cas_from_template) if statement.rank == 'deprecated' then return false -- ignore claim with deprecated rank end 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 found end local p = {} function p.entry_CAS_Common_Chemistry(frame) local cas_from_template = mw.text.trim(frame.args['cas'] or '') if cas_from_template == nil or #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 == nil or #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 Wikidata end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:CommonChemistry/doc
(
edit
)