Content deleted Content added
rm marker |
sync with sandbox |
||
Line 51:
["abbr"] =
{
["Q828224"]
["Q11573"]
["Q174728"]
["Q174789"]
["
["
["
["
["
["Q7727"] = "min",
["Q11574"] = "s",
},
}
Line 242 ⟶ 244:
-- sourced takes a table representing a statement that may or may not have references
-- it counts how many references are sourced to something not containing the word "wikipedia"
-- it returns a boolean = true if there are any sourced references.
local sourced = function(claim)
if claim.references then
for kr, vr in pairs(claim.references) do
local ref = mw.wikibase.renderSnaks(vr.snaks)
if not ref:find("Wikipedia") then
return true
end
end
end
end
-------------------------------------------------------------------------------
-- setRanks takes a flag (parameter passed) that requests the values to return
-- "b[est]" returns preferred if available, otherwise normal
-- "p[referred]" returns preferred
-- "n[ormal]" returns normal
-- "d[eprecated]" returns deprecated
-- multiple values are allowed, e.g. "preferred normal" (which is the default)
-- "best" will override the other flags, and set p and n
local function setRanks(rank)
rank = (rank or ""):lower()
-- if nothing passed, return preferred and normal
-- if rank == "" then rank = "p n" end
local ranks = {}
for w in string.gmatch(rank, "%a+") do
w = w:sub(1,1)
if w == "b" or w == "p" or w == "n" or w == "d" then
ranks[w] = true
end
end
-- check if "best" is requested or no ranks requested; and if so, set preferred and normal
if ranks.b or not next(ranks) then
ranks.p = true
ranks.n = true
end
return ranks
end
Line 261 ⟶ 290:
-- it returns (1) either the qid or nil indicating whether or not the call should continue
-- and (2) a table containing all of the statements for the propertyID and relevant Qid
-- if "best" ranks are requested, it returns those instead of all ranks
local parseInput = function(frame, input_parm, property_id)
-- There may be a local parameter supplied, if it's blank, set it to nil
Line 307 ⟶ 337:
-- See what's on Wikidata (the call always returns a table, but it may be empty):
local props =
if args.reqranks.b then
props = mw.wikibase.getBestStatements(qid, property_id)
else
props = mw.wikibase.getAllStatements(qid, property_id)
end
if props[1] then
return qid, props
Line 381 ⟶ 416:
-------------------------------------------------------------------------------
-- propertyvalueandquals takes a property object, the arguments passed from frame,
--
-- It returns a sequence (table) of values representing the values of that property
-- and qualifiers that match the qualifierID if supplied.
--
local function propertyvalueandquals(objproperty, args
-- onlysourced is a boolean passed to return only values sourced to other than Wikipedia
Line 444 ⟶ 479:
local datavalue = snak.datavalue
datavalue = datavalue and datavalue.value
if
-- nothing added to 'out': it
------------------------------------
elseif v.rank == "deprecated" and not args.reqranks.d then
-- nothing added to 'out': value is deprecated but not requested
------------------------------------
elseif v.rank == "normal" and not args.reqranks.n then
-- nothing added to 'out': value is normal but not requested
------------------------------------
elseif v.rank == "preferred" and not args.reqranks.p then
-- nothing added to 'out': value is preferred but not requested
------------------------------------
elseif snak.snaktype == "somevalue" then -- value is unknown
Line 523 ⟶ 565:
if dateprecision >= 11 then -- prepend day
fpvdate = tonumber(timestamp:sub(10, 11)) .. " " .. fpvdate
end
end
if timestamp:sub(1, 1) == "-" then
fpvdate = fpvdate .. " BCE"
end
fdate = format_Date(fpvdate, dateformat, args.bc)
-- testing the ability to add "circa" from P1480 "sourcing circumstances"
-- just testing on years for now
if dateprecision == 9 and v.qualifiers then
local sc = v.qualifiers.P1480
if sc then
local circa = ""
for k1, v1 in pairs(sc) do
if v1.datavalue.value.id == "Q5727902" then
circa = '<abbr title="circa">c.</abbr> '
break
end
end
fdate = circa .. fdate
end
end
elseif dateprecision == 7 then -- century
local century = math.floor((fpvdate - 1) / 100) + 1
Line 663 ⟶ 720:
}
if qualID == "DATES" then qargs.maxvals = 1 end
local qlist = {}
local t1, t2, dsep = "", "", ""
Line 672 ⟶ 726:
if qualID == "DATES" then
if k1 == "P580" then -- P580 is "start time"
t1 = propertyvalueandquals(v1, qargs
elseif k1 == "P582" then -- P582 is "end time"
t2 = propertyvalueandquals(v1, qargs
end
-- check for latest date qualifier:
Line 681 ⟶ 735:
-- otherwise see if we want this qualifier:
elseif qualID == "ALL" or qualID == k1 then
local ql = propertyvalueandquals(v1, qargs
for k2, v2 in ipairs(ql) do
qlist[#qlist + 1] = v2
Line 714 ⟶ 768:
local qualID = mw.text.trim(frame.args.qual or ""):upper()
if qualID == "" then qualID = nil end
-- table 'out' stores the return value(s):
local out = propertyvalueandquals(props, frame.args
-- format the table of values and return it as a string:
Line 771 ⟶ 795:
local propertyID = mw.text.trim(frame.args[1] or "")
frame.args.reqranks = setRanks(frame.args.rank)
local entityid, props = parseInput(frame, frame.args[2], propertyID)
if not entityid then
return props -- either the input parameter or nothing
end
return _getvalue(frame, props, propertyID, entityid)
end
Line 789 ⟶ 812:
-- (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
p.getPreferredValue = function(frame)
frame.args.rank = "
return p.getValue(frame)
end
Line 800 ⟶ 823:
-- (or a comma separated list of them if multiple values exist).
-- If normal ranks are set, it will return those values, otherwise all values
-- now redundant to getValue with |rank=normal
p.getNormalValue = function(frame)
frame.args.rank = "normal"
Line 875 ⟶ 898:
-- if "false" or "no" or 0 is passed set it false
local onlysrc = parseParam(frame.args.onlysourced or frame.args.osd, true)
-- set the requested ranks flags
frame.args.reqranks = setRanks(frame.args.rank)
-- check for locally supplied parameter in second unnamed parameter
Line 895 ⟶ 921:
local quals = v1.qualifiers[qualifierID]
if quals then
local
for k, v in pairs(vals) do
out[#out + 1] = v
|