Difference between pages "Module:WikidataIB" and "Module:WikidataIB/sandbox"

(Difference between pages)
Jump to: navigation, search
Page 1
Page 2
m (1 revision imported)
 
m (1 revision imported)
 
Line 1: Line 1:
-- Version: 2020-12-15
+
-- Version: 2020-12-26
 
-- Module to implement use of a blacklist and whitelist for infobox fields
 
-- Module to implement use of a blacklist and whitelist for infobox fields
 
-- Can take a named parameter |qid which is the Wikidata ID for the article
 
-- Can take a named parameter |qid which is the Wikidata ID for the article
Line 567: Line 567:
 
-- uselbl is boolean switch to force display of the label instead of the sitelink (default: false)
 
-- uselbl is boolean switch to force display of the label instead of the sitelink (default: false)
 
-- linkredir is boolean switch to allow linking to a redirect (default: false)
 
-- linkredir is boolean switch to allow linking to a redirect (default: false)
 +
-- formatvalue is boolean switch to allow formatting as italics or quoted (default: false)
 
-------------------------------------------------------------------------------
 
-------------------------------------------------------------------------------
 
-- Dependencies: labelOrId(); donotlink[]
 
-- Dependencies: labelOrId(); donotlink[]
Line 582: Line 583:
 
local linkredir = args.linkredir
 
local linkredir = args.linkredir
 
linkredir = parseParam(linkredir, false)
 
linkredir = parseParam(linkredir, false)
 +
local formatvalue = args.formatvalue or args.fv
 +
formatvalue = parseParam(formatvalue, false)
 
-- see if item might need italics or quotes
 
-- see if item might need italics or quotes
 
local fmt = ""
 
local fmt = ""
if next(formats) then
+
if next(formats) and formatvalue then
 
for k, v in ipairs( mw.wikibase.getBestStatements(id, "P31") ) do
 
for k, v in ipairs( mw.wikibase.getBestStatements(id, "P31") ) do
 
if v.mainsnak.datavalue and formats[v.mainsnak.datavalue.value.id] then
 
if v.mainsnak.datavalue and formats[v.mainsnak.datavalue.value.id] then
Line 1,895: Line 1,898:
 
-- whose value is to be returned is passed in named parameter |qual=
 
-- whose value is to be returned is passed in named parameter |qual=
 
local qualifierID = frame.args.qual
 
local qualifierID = frame.args.qual
 +
 +
-- A filter can be set like this: filter=P642==Q22674854
 +
local filter, fprop, fval
 +
local ftable = mw.text.split(frame.args.filter or "", "==")
 +
if ftable[2] then
 +
fprop = mw.text.trim(ftable[1])
 +
fval = mw.text.trim(ftable[2])
 +
filter = true
 +
end
  
 
-- onlysourced is a boolean passed to return qualifiers
 
-- onlysourced is a boolean passed to return qualifiers
Line 1,920: Line 1,932:
 
for k1, v1 in pairs(props) do
 
for k1, v1 in pairs(props) do
 
if v1.mainsnak.snaktype == "value" and v1.mainsnak.datavalue.type == "wikibase-entityid" then
 
if v1.mainsnak.snaktype == "value" and v1.mainsnak.datavalue.type == "wikibase-entityid" then
-- It's a wiki-linked value, so check if it's the target (in propvalue)
+
-- It's a wiki-linked value, so check if it's the target (in propvalue) and if it has qualifiers
-- and if it has qualifiers
 
 
if v1.mainsnak.datavalue.value.id == propvalue and v1.qualifiers then
 
if v1.mainsnak.datavalue.value.id == propvalue and v1.qualifiers then
 
if onlysrc == false or sourced(v1) then
 
if onlysrc == false or sourced(v1) then
 
-- if we've got this far, we have a (sourced) claim with qualifiers
 
-- if we've got this far, we have a (sourced) claim with qualifiers
-- which matches the target, so find the value(s) of the qualifier we want
+
-- which matches the target, so apply the filter and find the value(s) of the qualifier we want
local quals = v1.qualifiers[qualifierID]
+
if not filter or (v1.qualifiers[fprop] and v1.qualifiers[fprop][1].datavalue.value.id == fval) then
if quals then
+
local quals = v1.qualifiers[qualifierID]
-- can't reference qualifer, so set onlysourced = "no" (not boolean)
+
if quals then
local qargs = frame.args
+
-- can't reference qualifer, so set onlysourced = "no" (args are strings, not boolean)
qargs.onlysourced = "no"
+
local qargs = frame.args
local vals = propertyvalueandquals(quals, qargs, qid)
+
qargs.onlysourced = "no"
for k, v in ipairs(vals) do
+
local vals = propertyvalueandquals(quals, qargs, qid)
out[#out + 1] = v
+
for k, v in ipairs(vals) do
 +
out[#out + 1] = v
 +
end
 
end
 
end
 
end
 
end