Changes

Jump to: navigation, search

Module:WikidataIB

4,377 bytes added, 19:15, 5 November 2018
ensure sc is string
["qualifier-not-found"] = "Qualifier not found.",
["site-not-found"] = "Wikimedia project not found.",
["labels-not-found"] = "No labels found.",
["descriptions-not-found"] = "No descriptions found.",
["aliases-not-found"] = "No aliases found.",
["unknown-datetime-format"] = "Unknown datetime format.",
["local-article-not-found"] = "Article is available on Wikidata, but not on Wikipedia",
["datenumbersuffix"] = "",
["list separator"] = ", ",
["multipliers"] = {
[0] = "",
[3] = " thousand",
[6] = " million",
[9] = " billion",
[12] = " trillion",
}
}
-- This allows a internationisation module to override the above table
return disp
end
 
-------------------------------------------------------------------------------
return false, nil
end
 
-------------------------------------------------------------------------------
-- monolingualtext
-- It also requires linked, the link/pre/postfixes, uabbr, and the arguments passed from frame.
-- The optional filter parameter allows quantities to be be filtered by unit.
-------------------------------------------------------------------------------
-- Dependencies: parseParam(); labelOrId(); i18n[]; dateFormat();
-- implement a switch to turn on/off numerical formatting later
local fnum = true
--
-- a switch to turn on/off conversions - only for en-wiki
local conv = parseParam(args.conv or args.convert, false)
-- if we have conversions, we canwon't have formatted numbersor scales if conv then fnum = false args.scale = 0 end --
-- convert amount to a number
local amount = tonumber(dv.amount) or i18n["NaN"]
--
-- scale factor for millions, billions, etc.
local sc = tostring(args.scale or ""):sub(1,1):lower()
local scale
if sc == "a" then
-- automatic scaling
if amount > 1e15 then
scale = 12
elseif amount > 1e12 then
scale = 9
elseif amount > 1e9 then
scale = 6
elseif amount > 1e6 then
scale = 3
else
scale = 0
end
else
scale = tonumber(args.scale) or 0
if scale < 0 or scale > 12 then scale = 0 end
scale = math.floor(scale/3) * 3
end
local factor = 10^scale
amount = amount / factor
-- ranges:
local range = ""
-- check if upper and/or lower bounds are given and significant
if upb and lowb then
-- differences rounded to 2 sig fig:
local posdif = roundto(upb - amount, 2)/ factor local negdif = roundto(amount - lowb, 2)/ factor
upb, lowb = amount + posdif, amount - negdif
-- round scaled numbers to integers or 4 sig fig
if (scale > 0 or sc == "a") then
if amount < 1e4 then
amount = roundto(amount, 4)
else
amount = math.floor(amount + 0.5)
end
end
if fnum then amount = args.langobj:formatNum( amount ) end
if posdif ~= negdif then
end
else
-- round scaled numbers to integers or 4 sig fig
if (scale > 0 or sc == "a") then
if amount < 1e4 then
amount = roundto(amount, 4)
else
amount = math.floor(amount + 0.5)
end
end
if fnum then amount = args.langobj:formatNum( amount ) end
end
-- unit names and symbols:
-- extract the qid in the form 'Qnnn' from the value.unit url
-- and then fetch the label from that - or symbol if unitabbr is true
end
end
-- format display:
if conv and usym ~= "" then
if range == "" then
end
elseif unit == "$" or unit == "£" then
val = unit .. amount .. range.. i18n.multipliers[scale]
else
val = amount .. range .. i18n.multipliers[scale] .. usep .. unit
end
------------------------------------
else
val = latdeg .. "°" .. latmin .. "′" .. ns .. " "
out[#out] val = out[#out] val .. longdeg .. "°".. longmin .. "′" .. ew
end
else
return ret
end
 
 
-------------------------------------------------------------------------------
-- getAllLabels fetches the set of labels and formats it for display as wikitext.
-- It takes a parameter 'qid' for arbitrary access, otherwise it uses the current page.
-------------------------------------------------------------------------------
-- Dependencies: none
-------------------------------------------------------------------------------
p.getAllLabels = function(frame)
local args = frame.args or frame:getParent().args or {}
 
local qid = args.qid
if qid == "" then qid = nil end
 
local entity = mw.wikibase.getEntity(qid)
if not entity then return i18n["entity-not-found"] end
 
local labels = entity.labels
if not labels then return i18n["labels-not-found"] end
 
out = {}
for k, v in pairs(labels) do
out[#out+1] = v.value .. " (" .. v.language .. ")"
end
 
return table.concat(out, "; ")
end
 
 
-------------------------------------------------------------------------------
-- getAllDescriptions fetches the set of descriptions and formats it for display as wikitext.
-- It takes a parameter 'qid' for arbitrary access, otherwise it uses the current page.
-------------------------------------------------------------------------------
-- Dependencies: none
-------------------------------------------------------------------------------
p.getAllDescriptions = function(frame)
local args = frame.args or frame:getParent().args or {}
 
local qid = args.qid
if qid == "" then qid = nil end
 
local entity = mw.wikibase.getEntity(qid)
if not entity then return i18n["entity-not-found"] end
 
local descriptions = entity.descriptions
if not descriptions then return i18n["descriptions-not-found"] end
 
out = {}
for k, v in pairs(descriptions) do
out[#out+1] = v.value .. " (" .. v.language .. ")"
end
 
return table.concat(out, "; ")
end
 
 
-------------------------------------------------------------------------------
-- getAllAliases fetches the set of descriptions and formats it for display as wikitext.
-- It takes a parameter 'qid' for arbitrary access, otherwise it uses the current page.
-------------------------------------------------------------------------------
-- Dependencies: none
-------------------------------------------------------------------------------
p.getAllAliases = function(frame)
local args = frame.args or frame:getParent().args or {}
 
local qid = args.qid
if qid == "" then qid = nil end
 
local entity = mw.wikibase.getEntity(qid)
if not entity then return i18n["entity-not-found"] end
 
local aliases = entity.aliases
if not aliases then return i18n["aliases-not-found"] end
 
out = {}
for k1, v1 in pairs(aliases) do
local lang = v1[1].language
local val = {}
for k1, v2 in ipairs(v1) do
val[#val+1] = v2.value
end
out[#out+1] = table.concat(val, ", ") .. " (" .. lang .. ")"
end
 
return table.concat(out, "; ")
end
Anonymous user

Navigation menu