Module:WikidataIB/sandbox1: Difference between revisions

Content deleted Content added
sync with sandbox
sync with sandbox
Line 95:
-- and returns it rounded to (sf) significant figures
local function roundto(x, sf)
if x == 0 then return 0 end
x = math.abs(x)
if sf < 1 then sf = 1 end
Line 311 ⟶ 312:
-- if a pen icon is wanted add it the end of the last value
if not noic then
local icon = " &nbsp;[[" .. i18n["filespace"]
icon = icon .. ":Blue pencil.svg |frameless |text-top |10px |alt="
icon = icon .. i18n["editonwikidata"]
Line 550 ⟶ 551:
out[#out+1] = amount .. unit
------------------------------------
-- datatypes which are global coordinates:
elseif datatype == "globe-coordinate" then
local display = args.display or ""
local format = args.format or ""
if display=="decimal" then
local latdecimal = 0
local longdecimal = 0
local coords = entity:formatPropertyValues(propertyID).value
-- the latitude and longitude are returned like this: nn°nn&#39;nn.n&#34;
-- using html entities with hex values really screws up parsing the numbers
local lat = mw.ustring.match(coords, "^[^,]*") -- everything from the start to before the comma
local long = mw.ustring.match(coords, "[^ ]*$") -- everything from after the space to the end
lat = lat:gsub("&#%d%d;", ":") -- clean out the html entities
long = long:gsub("&#%d%d;", ":") -- clean out the html entities
-- read the latitude numbers into a table
local newlat = {}
for num in mw.ustring.gmatch(lat, "%d+%.?%d*") do
newlat[#newlat + 1] = num
end
if #newlat==3 then
latdecimal = newlat[1] + newlat[2]/60 + newlat[3]/3600
elseif #newlat==2 then
latdecimal = newlat[1] + newlat[2]/60
else
latdecimal = newlat[1]
end
if lat:sub(-1)=="S" then
latdecimal = -latdecimal
end
local newlong = {}
for num in mw.ustring.gmatch(long, "%d+%.?%d*") do
newlong[#newlong + 1] = num
end
if #newlong==3 then
longdecimal = newlong[1] + newlong[2]/60 + newlong[3]/3600
elseif #newlat==2 then
longdecimal = newlong[1] + newlong[2]/60
else
longdecimal = newlong[1]
end
if long:sub(-1)=="W" then
longdecimal = -longdecimal
end
if format == "longlat" then
out[#out+1] = longdecimal .. ", " .. latdecimal
elseif format == "lat" then
out[#out+1] = latdecimal
elseif format == "long" then
out[#out+1] = longdecimal
else
out[#out+1] = latdecimal .. ", " .. longdecimal
end
else
out[#out+1] = entity:formatPropertyValues(propertyID).value
end
else
-- some other data type
-- e.g. globe-coordinate where mainsnak.datavalue.value is a table
-- either write a specific handler
-- or we can use formatPropertyValues() as a temporary measure.
Line 938 ⟶ 993:
return s
end
end
 
 
-------------------------------------------------------------------------------
-- labelorid is a public function to expose the output of labelOrId()
-- pass the Q-number as |qid= or as an unnamed parameter
p.labelorid = function(frame)
local id = frame.args.qid or frame.args[1]
return labelOrId(id)
end