Module:ConstraintCheck
Documentation for this module may be created at Module:ConstraintCheck/doc
Code
-- based on Module:Constraint
local d = require('Module:Wikidata')
local frame = mw.getCurrentFrame()
local entity, lang, namespace
local Cats = {}
function addCat(name, key)
table.insert( Cats, '[[Category:' .. name .. '|' .. key .. ']]' )
end
local p = {}
-- todo: inactive
function p.check()
local args = frame and frame.args or {}
local params = parent and parent.args or {}
namespace = frame:preprocess("{{NAMESPACE}}")
id = frame:preprocess("{{BASEPAGENAME}}")
entity = d.getEntityFromId(id)
local test = ""
local claims
local argid
if args[1] == "countryrelated" then
argid = tonumber(string.sub(args[2], 2))
end
local parasid = string.sub(id, 2)
local c = {["Unique value"] = 21502410, ["countryrelated"] = argid }
local propid = args[3] or "P2302"
if namespace == "Property talk" then
for anchor,value in pairs(c) do
local ok = false
if anchor == args[1] then
if entity.claims then
claims = entity.claims[propid]
end
if claims then
for i, statement in pairs(claims) do
if claims[i]
and claims[i].mainsnak.snaktype == "value"
and claims[i].mainsnak.datavalue.type == "wikibase-entityid"
and claims[i].mainsnak.datavalue.value["numeric-id"]
and claims[i].mainsnak.datavalue.value["numeric-id"] == value
then
ok = true
end
end
end
if ok then
test = "pass"
else
addCat('Properties to add ' .. propid .. ':Q' .. value , string.sub(id, 2) )
test = "failed: anchor was " .. anchor .. ", property was " .. propid .. ", value was " .. value .. " // end"
end
end
end
end
return table.concat(Cats)
--- return test .. namespace .. id .. args[1] .. table.concat(Cats)
end
return p