end  
return p._getValue(args)
end  
---
-- getPreferredValue is used to get a value,
-- (or a comma separated list of them if multiple values exist).
-- If preferred ranks are set, it will return those values, otherwise values with normal ranks
-- now redundant to getValue with |rank=best
---
-- Dependencies: p.getValue; setRanks; parseInput; propertyvalueandquals; assembleoutput;
-- parseParam; sourced; labelOrId; i18n.latestdatequalifier; format_Date;
-- makeOrdinal; roundto; decimalPrecision; decimalToDMS;
---
p.getPreferredValue = function
.args.rank = "best"
return p.getValue
end  
---
-- getCoords is used to get coordinates for display in an infobox
-- whitelist and blacklist are implemented
-- optional 'display' parameter is allowed, defaults to nil - was "inline, title"
---
-- Dependencies: setRanks; parseInput; decimalPrecision;
---
p.getCoords = function
local propertyID = "P625"  
-- if there is a 'display' parameter supplied, use it
-- otherwise default to nothing
local disp = .args.display or ""
if disp == "" then
disp = nil -- default to not supplying display parameter, was "inline, title"
end  
-- there may be a format parameter to switch from deg/min/sec to decimal degrees
-- default is deg/min/sec
-- decimal degrees needs |format = dec
local form = (.args.format or ""):lower:sub(1,3)
if form ~= "dec" then
form = "dms"
end  
-- just deal with best values
.args.reqranks = setRanks("best")  
local qid, props = parseInput(, .args[1], propertyID)
if not qid then
return props -- either local parameter or nothing
else
local dv = props[1].mainsnak.datavalue.value
local lat, long, prec = dv.latitude, dv.longitude, dv.precision
lat = decimalPrecision(lat, prec)
long = decimalPrecision(long, prec)
local lat_long = { lat, long }
lat_long["display"] = disp
lat_long["format"] = form
-- invoke template Coord with the values stored in the table
return :expandTemplate{title = 'coord', args = lat_long}
end
end  
---
-- getQualifierValue is used to get a formatted value of a qualifier
---
-- The call needs: a property (the unnamed parameter or 1=)
-- a target value for that property (pval=)
-- a qualifier for that target value (qual=)
-- The usual whitelisting and blacklisting of the property is implemented
-- The boolean onlysourced= parameter can be set to return nothing
-- when the property is unsourced (or only sourced to Wikipedia)
---
-- Dependencies: parseParam; setRanks; parseInput; sourced;
-- propertyvalueandquals; assembleoutput;
-- labelOrId; i18n.latestdatequalifier; format_Date;
-- findLang; makeOrdinal; roundto; decimalPrecision; decimalToDMS;
---
p.getQualifierValue = function  
-- The property ID that will have a qualifier is the first unnamed parameter
local propertyID = mw.text.trim(.args[1] or "")  
-- The value of the property we want to match whose qualifier value is to be returned
-- is passed in named parameter |pval=
local propvalue = .args.pval  
-- The property ID of the qualifier
-- whose value is to be returned is passed in named parameter |qual=
local qualifierID = .args.qual  
-- A filter can be set like this: filter=P642==Q22674854
local filter, fprop, fval
local ftable = mw.text.split(.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
-- only when property values are sourced to something other than Wikipedia
-- if nothing or an empty string is passed set it true
-- if "false" or "no" or 0 is passed set it false
local onlysrc = parseParam(.args.onlysourced or .args.osd, true)  
-- set a language object and language code in the .args table
.args.langobj = findLang(.args.lang)
.args.lang = .args.langobj.code  
-- set the requested ranks flags
.args.reqranks = setRanks(.args.rank)  
-- check for locally supplied parameter in second unnamed parameter
-- success means no local parameter and the property exists
local qid, props = parseInput(, .args[2], propertyID)
if qid then
local out = {}
-- Scan through the values of the property
-- we want something like property is P793, significant event (in propertyID)
-- whose value is something like Q385378, construction (in propvalue)
-- then we can return the value(s) of a qualifier such as P580, start time (in qualifierID)
for k1, v1 in pairs(props) do
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) and if it has qualifiers
if v1.mainsnak.datavalue.value.id == propvalue and v1.qualifiers then
if onlysrc == false or sourced(v1) then
-- if we've got this far, we have a (sourced) claim with qualifiers
-- which matches the target, so apply the filter and find the value(s) of the qualifier we want
if not filter or (v1.qualifiers[fprop] and v1.qualifiers[fprop][1].datavalue.value.id == fval) then
local quals = v1.qualifiers[qualifierID]
if quals then
-- can't reference qualifer, so set onlysourced = "no" (args are strings, not boolean)
local qargs = .args
qargs.onlysourced = "no"
local vals = propertyvalueandquals(quals, qargs, qid)
for k, v in ipairs(vals) do
out[#out + 1] = v
end
end
end
end -- of check for sourced
end -- of check for matching required value and has qualifiers
end -- of check for wikibase entity
end -- of loop through values of propertyID
return assembleoutput(out, .args, qid, propertyID)
else
return props -- either local parameter or nothing
end -- of test for success
return nil
end  
---
-- getSumOfParts scans the property 'has part' (P527) for values matching a list.
-- The list is passed in parameter vlist.
-- It consists of a string of Qids separated by spaces or any usual punctuation.
-- If the matched values have a qualifier 'quantity' (P1114), those quantities are summed.
-- The sum is returned as a number or nothing if zero.
---
-- Dependencies: _getsumofparts;
---
p.getSumOfParts = function
local sum = _getsumofparts(.args)
if sum == 0 then return end
return sum
end  
---
-- getValueByQual gets the value of a property which has a qualifier with a given entity value
-- The call needs:
-- a property ID (the unnamed parameter or 1=Pxxx)
-- the ID of a qualifier for that property (qualID=Pyyy)
-- either the Wikibase-entity ID of a value for that qualifier (qvalue=Qzzz)
-- or a string value for that qualifier (qvalue=abc123)
-- The usual whitelisting, blacklisting, onlysourced, etc. are implemented
---
-- Dependencies: _getvaluebyqual; parseParam; setRanks; parseInput; sourced;
-- assembleoutput;
---
p.getValueByQual = function
local qualID = .args.qualID
-- The Q-id of the value for the qualifier we want to match is in named parameter |qvalue=
local qval = .args.qvalue or ""
if qval == "" then return "no qualifier value supplied" end
local function checkQID(id)
return id == qval
end
return _getvaluebyqual(, qualID, checkQID)
end  
---
-- getValueByLang gets the value of a property which has a qualifier P407
-- ("language of work or name") whose value has the given language code
-- The call needs:
-- a property ID (the unnamed parameter or 1=Pxxx)
-- the MediaWiki language code to match the language (lang=xx[-yy])
-- (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
-- The language code for the qualifier we want to match is in named parameter |lang=
local langcode = findLang(.args.lang).code
local 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(, "P407", checkLanguage)
end  
---