Content deleted Content added
sync with sandbox |
major update to use getAllStatements instead of getEntity |
||
Line 1:
-- 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
-- if not supplied, it will use the Wikidata ID associated with the current page.
-- Fields in blacklist are never to be displayed, i.e. module must return nil in all circumstances
-- Fields in whitelist return local value if it exists or the Wikidata value otherwise
Line 51:
["abbr"] =
{
["Q828224"] = "km",
["Q11573"] = "m",
["Q174728"] = "cm",
["Q174789"] = "mm",
["Q11570"] = "kg",
["Q41803"] = "g",
["Q3241121"] = "mg",
["Q2332346"] = "ml",
["Q7727"] = "min",
},
}
Line 214 ⟶ 215:
-- parseInput processes the Q-id , the blacklist and the whitelist
-- if an input parameter is supplied, it returns that and ends the call.
-- it returns
-- and
local parseInput = function(frame, input_parm, property_id)
-- There may be a local parameter supplied, if it's blank, set it to nil
if input_parm == "" then input_parm = nil end
Line 224 ⟶ 225:
-- can take a named parameter |qid which is the Wikidata ID for the article.
--
local qid = args.qid or ""
if qid == "" then qid =
-- The blacklist is passed in named parameter |suppressfields
Line 240 ⟶ 241:
if blacklist then
-- The name is compulsory when blacklist is used, so return nil if it is not supplied
if not fieldname or fieldname == "" then return false
-- If this field is on the blacklist, then return nil
if blacklist:find(fieldname) then return false
end
Line 248 ⟶ 249:
-- The blacklist overrides any locally supplied parameter as well
-- If a non-blank input parameter was supplied return it
if input_parm then return false, input_parm
-- Otherwise see if this field is on the whitelist:
Line 256 ⟶ 257:
found = ((found or 0) > 0)
if whitelist ~= 'ALL' and (whitelist:upper() == "NONE" or not found) then
return false
end
-- See what's on Wikidata (the call always returns a table, but it may be empty):
local
if
return qid, props
end
-- no property on Wikidata
return false
end
Line 275 ⟶ 273:
-- assembleoutput takes the sequence table containing the property values
-- and formats it according to switches given
-- it needs the entityID and propertyID to link from the pen icon
local function assembleoutput(out, args, entityID, propertyID)
Line 553 ⟶ 552:
-- datatypes which are global coordinates:
elseif datatype == "globe-coordinate" then
local
if
-- format parameter switches 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 == "" then form = "dms" end
local lat, long = datavalue.latitude, datavalue.longitude
if form == "dec" then
lat_long[1] = lat
lat_long[2] = long
else
local ns, ew
else
end
local latdeg = math.floor(lat)
local latmin = math.floor(latms)
local
if long < 0 then
else
end
local longdeg = math.floor(long)
local longms = (long - longdeg) * 60
local longmin = math.floor(longms)
local longsec = (longms - longmin) * 60
if latmin == 0 and longmin == 0 then
out[#out + 1] = latdeg .. "°" .. ns .. " " .. longdeg .. "°" .. ew
else
out[#out + 1] = latdeg .. "°" .. latmin .. "′" .. ns .. " "
out[#out] = out[#out] .. longdeg .. "°".. longmin .. "′" .. ew
end
else
out[#out + 1] =
out[#out] = out[#out] .. longdeg .. "°" .. longmin .. "′" .. longsec .. "″" .. ew
end
end
------------------------------------
else
-- some other data type so write a specific handler
out[#out+1] = "unknown data type"
end -- of datatype/unknown value/sourced check
Line 676 ⟶ 667:
-------------------------------------------------------------------------------
-- _getvalue is the
--
local function _getvalue(frame
-- qual is a string containing the property ID of the qualifier(s) to be returned
Line 721 ⟶ 712:
-- format the table of values and return it as a string:
return assembleoutput(out, frame.args,
end
Line 741 ⟶ 732:
if not frame.args[1] then return i18n.errors["No property supplied"] end
end
local propertyID = mw.text.trim(frame.args[1] or "")
local
if not
return props -- either the input parameter or nothing
end
--[[
local function filter(claim)
return true
end
--]]
return _getvalue(frame, props, propertyID, entityid)
end
Line 779 ⟶ 772:
-------------------------------------------------------------------------------
-- getCoords is used to get coordinates for display in an infobox
-- whitelist and blacklist
-- optional 'display' parameter is allowed, defaults to "inline, title"
--
Line 787 ⟶ 780:
-- if there is a 'display' parameter supplied, use it
-- otherwise default to "inline, title"
local disp = frame.args.display or ""
if
disp = "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 = (frame.args.format or ""):lower():sub(1,3)
if form == "" then
form = "dms"
end
local qid, props = parseInput(frame, frame.args[1], propertyID)
if not success then
return props -- either local parameter or nothing
else
local lat_long = {}
dv = props[1].mainsnak.datavalue.value
local lat, long, prec = dv.latitude, dv.longitude, dv.precision
if form == "dec" then
lat_long[1] = lat
lat_long[2] = long
else
local ns, ew
if lat < 0 then
ns = "S"
lat = - lat
else
ns = "N"
end
local latdeg = math.floor(lat)
local latms = (lat - latdeg) * 60
local latmin = math.floor(latms)
local latsec = (latms - latmin) * 60
if long < 0 then
ew = "W"
long = - long
else
ew = "E"
end
local longdeg = math.floor(long)
local longms = (long - longdeg) * 60
local longmin = math.floor(longms)
local longsec = (longms - longmin) * 60
if latsec == 0 and longsec == 0 then
if latmin == 0 and longmin == 0 then
lat_long = { latdeg, ns, longdeg, ew }
else
lat_long = { latdeg, latmin, ns, longdeg, longmin, ew }
end
else
lat_long = { latdeg, latmin, latsec, ns, longdeg, longmin, longsec, ew }
end
end
lat_long["display"] = disp
-- invoke template Coord with the values stored in the table
Line 856 ⟶ 878:
-- check for locally supplied parameter in second unnamed parameter
-- success means no local parameter and the property exists
local success, errorOrEntity, props = parseInput(frame, frame.args[2], propertyID) --$$$
if success then
local entity = errorOrEntity --$$$
local out = {}
-- Scan through the values of the property
|