Content deleted Content added
Sync sandbox |
Prune code duplication |
||
Line 1,061:
return nil
end
-------------------------------------------------------------------------------
-- getValueByQual gets the value of a property which has a qualifier with a given entity value
Line 1,071 ⟶ 1,069:
-- The usual whitelisting, blacklisting, onlysourced, etc. are implemented
-------------------------------------------------------------------------------
-- Dependencies: _getvaluebyqual; parseParam; setRanks; parseInput; sourced;
-- assembleoutput;
-------------------------------------------------------------------------------
p.getValueByQual = function(frame)
local qualID = frame.args[2]
-- The Q-id of the value for the qualifier we want to match is in named parameter |qvalue=
local qval = frame.args.qvalue or ""
if qval == "" then return "no qualifier value supplied" end
local function checkQID(id)
return id == qval
end
return _getvaluebyqual(frame, qualID, checkQID)
end
-------------------------------------------------------------------------------
-- getValueByLang gets the value of a property which has a qualifier P407
Line 1,144 ⟶ 1,090:
-- (if no code is supplied, it uses the default language)
-- The usual whitelisting, blacklisting, onlysourced, etc. are implemented
-------------------------------------------------------------------------------
-- Dependencies: _getvaluebyqual; parseParam; setRanks; parseInput; sourced; assembleoutput;
-------------------------------------------------------------------------------
p.getValueByLang = function(frame)
-- The language code for the qualifier we want to match is in named parameter |lang=
local langcode = frame.args.lang or ""
if langcode == "" then
langcode = frame:callParserFunction{ name = "int", args = "lang" }
end
function checkLanguage(id)
-- id should represent a language like "British English (Q7979)"
-- it should have string property "Wikimedia language code (P424)"
-- qlcode will be a table:
local qlcode = mw.wikibase.getBestStatements(id, "P424")
if (#qlcode > 0) and (qlcode[1].mainsnak.datavalue.value == langcode) then
return true
end
end
return _getvaluebyqual(frame, "P407", checkLanguage)
end
-------------------------------------------------------------------------------
-- Common code for p.getValueByQual and p.getValueByLang
-------------------------------------------------------------------------------
-- Dependencies: parseParam; setRanks; parseInput; sourced; assembleoutput;
-------------------------------------------------------------------------------
-- The property ID that will have a qualifier is the first unnamed parameter
Line 1,153 ⟶ 1,122:
if propertyID == "" then return "no property supplied" end
-- The property ID of the qualifier
local qualID = frame.args.qualID or "
if qualID == "" then return "no qualifier supplied" end
-- onlysourced is a boolean passed to return property values
Line 1,179 ⟶ 1,143:
-- Scan through the values of the property
-- we want something like property is "pronunciation audio (P443)" in propertyID
-- with a qualifier like "language of work or name (P407)" in qualID
-- whose value has the required ID,
for k1, v1 in pairs(props) do
if v1.mainsnak.snaktype == "value" and v1.mainsnak.datavalue.type == "string" then
Line 1,193 ⟶ 1,156:
-- We'll only deal with wikibase-items for now
if v1q[qualID][1].datatype == "wikibase-item" then
out[#out + 1] = v1.mainsnak.datavalue.value
end
end
end -- of check for sourced
end -- of check for matching required value and has qualifiers
else
return "not string"
Line 1,214 ⟶ 1,172:
return nil
end
-------------------------------------------------------------------------------
|