en:Module:Wd 2018年9月15日 (土) 13:55(UTC)より
Triple-Zeta (トーク | 投稿記録) 細 (1版 をインポートしました) |
template>K-iczn (en:Module:Wd 2018年9月15日 (土) 13:55(UTC)より) |
||
84行目: | 84行目: | ||
qualifier = "%q[%s][%r]", | qualifier = "%q[%s][%r]", | ||
reference = "%r", | reference = "%r", | ||
propertyWithQualifier = "%p[ <span style=\"font-size: | propertyWithQualifier = "%p[ <span style=\"font-size:85%\">(%q)</span>][%s][%r]", | ||
alias = "%a[%s]", | alias = "%a[%s]", | ||
badge = "%b[%s]" | badge = "%b[%s]" | ||
160行目: | 160行目: | ||
-- somewhat reliable way of determining global site ID in the absence of a library function, targeting the Wikipedia project (i.e. appending "wiki") | -- somewhat reliable way of determining global site ID in the absence of a library function, targeting the Wikipedia project (i.e. appending "wiki") | ||
cfg.siteID = (function() for i,v in pairs(mw.site.interwikiMap("local")) do if v.isCurrentWiki then return mw.ustring.gsub(i,"-","_").."wiki" end end end)() | cfg.siteID = (function() for i,v in pairs(mw.site.interwikiMap("local")) do if v.isCurrentWiki and i~="w" then return mw.ustring.gsub(i,"-","_").."wiki" end end end)() | ||
cfg.states = {} | cfg.states = {} | ||
217行目: | 217行目: | ||
function replaceDecimalMark(num) | function replaceDecimalMark(num) | ||
return mw.ustring.gsub(num, "[.]", i18n['numeric']['decimal-mark'], 1) | return mw.ustring.gsub(num, "[.]", i18n['numeric']['decimal-mark'], 1) | ||
end | |||
function padZeros(num, numDigits) | |||
local numZeros | |||
local negative = false | |||
if num < 0 then | |||
negative = true | |||
num = num * -1 | |||
end | |||
num = tostring(num) | |||
numZeros = numDigits - num:len() | |||
for i = 1, numZeros do | |||
num = "0"..num | |||
end | |||
if negative then | |||
num = "-"..num | |||
end | |||
return num | |||
end | end | ||
724行目: | 747行目: | ||
if not skip then | if not skip then | ||
-- add <ref> tag with the reference's hash as its name (to deduplicate references) | -- add <ref> tag with the reference's hash as its name (to deduplicate references) | ||
outString = outString .. mw.getCurrentFrame():extensionTag("ref", valuesArray[i][1], {name = | outString = outString .. mw.getCurrentFrame():extensionTag("ref", valuesArray[i][1], {name = valuesArray[i].refHash}) | ||
end | end | ||
else | else | ||
1,030行目: | 1,053行目: | ||
value = prefix .. value .. suffix .. calendar | value = prefix .. value .. suffix .. calendar | ||
else | else | ||
value = | value = padZeros(yRound * sign, 4) | ||
if m then | if m then | ||
value = value .. "-" .. m | value = value .. "-" .. padZeros(m, 2) | ||
if d then | if d then | ||
value = value .. "-" .. d | value = value .. "-" .. padZeros(d, 2) | ||
end | end | ||
end | end | ||
1,045行目: | 1,068行目: | ||
return value | return value | ||
elseif datatype == 'globecoordinate' then | elseif datatype == 'globecoordinate' then | ||
-- logic from https://github.com/DataValues/Geo | -- logic from https://github.com/DataValues/Geo (v4.0.1) | ||
local precision, numDigits, strFormat, value, globe | local precision, unitsPerDegree, numDigits, strFormat, value, globe | ||
local | local latitude, latConv, latValue, latLink | ||
local | local longitude, lonConv, lonValue, lonLink | ||
local latDirection, latDirectionN, latDirectionS, latDirectionEN | local latDirection, latDirectionN, latDirectionS, latDirectionEN | ||
local lonDirection, lonDirectionE, lonDirectionW, lonDirectionEN | local lonDirection, lonDirectionE, lonDirectionW, lonDirectionEN | ||
local latDegrees = nil | |||
local latMinutes = nil | |||
local latSeconds = nil | |||
local lonDegrees = nil | |||
local lonMinutes = nil | |||
local lonSeconds = nil | |||
local latDegSym = "" | |||
local latMinSym = "" | |||
local latSecSym = "" | |||
local lonDegSym = "" | |||
local lonMinSym = "" | |||
local lonSecSym = "" | |||
local latDirectionEN_N = "N" | local latDirectionEN_N = "N" | ||
1,101行目: | 1,138行目: | ||
end | end | ||
precision = datavalue['precision'] or 1 | precision = datavalue['precision'] | ||
if not precision or precision <= 0 then | |||
precision = 1 / 3600 -- precision not set (correctly), set to arcsecond | |||
end | |||
-- remove insignificant detail | |||
latitude = math.floor(latitude / precision + 0.5) * precision | latitude = math.floor(latitude / precision + 0.5) * precision | ||
longitude = math.floor(longitude / precision + 0.5) * precision | longitude = math.floor(longitude / precision + 0.5) * precision | ||
if precision >= 1 - (1 / 60) and precision < 1 then | |||
precision = 1 | |||
elseif precision >= (1 / 60) - (1 / 3600) and precision < (1 / 60) then | |||
precision = 1 / 60 | |||
end | |||
if precision >= 1 then | |||
unitsPerDegree = 1 | |||
elseif precision >= (1 / 60) then | |||
unitsPerDegree = 60 | |||
else | |||
unitsPerDegree = 3600 | |||
end | |||
if numDigits < | numDigits = math.ceil(-math.log10(unitsPerDegree * precision)) | ||
if numDigits <= 0 then | |||
numDigits = tonumber("0") -- for some reason, 'numDigits = 0' may actually store '-0', so parse from string instead | numDigits = tonumber("0") -- for some reason, 'numDigits = 0' may actually store '-0', so parse from string instead | ||
end | end | ||
1,114行目: | 1,170行目: | ||
strFormat = "%." .. numDigits .. "f" | strFormat = "%." .. numDigits .. "f" | ||
if precision >= 1 then | |||
latDegrees = strFormat:format(latitude) | |||
lonDegrees = strFormat:format(longitude) | |||
if precision | |||
if not raw then | if not raw then | ||
-- | latDegSym = replaceDecimalMark(latDegrees) .. degSymbol | ||
lonDegSym = replaceDecimalMark(lonDegrees) .. degSymbol | |||
else | |||
latDegSym = latDegrees .. degSymbol | |||
lonDegSym = lonDegrees .. degSymbol | |||
end | |||
else | |||
latConv = math.floor(latitude * unitsPerDegree * 10^numDigits + 0.5) / 10^numDigits | |||
lonConv = math.floor(longitude * unitsPerDegree * 10^numDigits + 0.5) / 10^numDigits | |||
if precision >= (1 / 60) then | |||
latMinutes = latConv | |||
lonMinutes = lonConv | |||
else | |||
latSeconds = latConv | |||
lonSeconds = lonConv | |||
latMinutes = math.floor(latSeconds / 60) | |||
lonMinutes = math.floor(lonSeconds / 60) | |||
latSeconds = strFormat:format(latSeconds - (latMinutes * 60)) | |||
lonSeconds = strFormat:format(lonSeconds - (lonMinutes * 60)) | |||
if not raw then | |||
latSecSym = replaceDecimalMark(latSeconds) .. secSymbol | |||
lonSecSym = replaceDecimalMark(lonSeconds) .. secSymbol | |||
else | |||
latSecSym = latSeconds .. secSymbol | |||
lonSecSym = lonSeconds .. secSymbol | |||
end | |||
end | end | ||
latDegrees = math.floor(latMinutes / 60) | |||
lonDegrees = math.floor(lonMinutes / 60) | |||
latDegSym = latDegrees .. degSymbol | |||
lonDegSym = lonDegrees .. degSymbol | |||
latMinutes = latMinutes - (latDegrees * 60) | |||
lonMinutes = lonMinutes - (lonDegrees * 60) | |||
if precision >= (1 / 60) then | |||
latMinutes = strFormat:format(latMinutes) | |||
lonMinutes = strFormat:format(lonMinutes) | |||
if not raw then | |||
latMinSym = replaceDecimalMark(latMinutes) .. minSymbol | |||
lonMinSym = replaceDecimalMark(lonMinutes) .. minSymbol | |||
else | |||
latMinSym = latMinutes .. minSymbol | |||
lonMinSym = lonMinutes .. minSymbol | |||
end | |||
else | |||
latMinSym = latMinutes .. minSymbol | |||
lonMinSym = lonMinutes .. minSymbol | |||
end | |||
end | end | ||
latValue = | latValue = latDegSym .. latMinSym .. latSecSym .. latDirection | ||
lonValue = | lonValue = lonDegSym .. lonMinSym .. lonSecSym .. lonDirection | ||
value = latValue .. separator .. lonValue | value = latValue .. separator .. lonValue | ||
1,166行目: | 1,247行目: | ||
end | end | ||
value = "[https://tools.wmflabs.org/geohack/geohack.php?language="..self.langCode.."¶ms=".. | latLink = table.concat({latDegrees, latMinutes, latSeconds}, "_") | ||
lonLink = table.concat({lonDegrees, lonMinutes, lonSeconds}, "_") | |||
value = "[https://tools.wmflabs.org/geohack/geohack.php?language="..self.langCode.."¶ms="..latLink.."_"..latDirectionEN.."_"..lonLink.."_"..lonDirectionEN.."_globe:"..globe.." "..value.."]" | |||
end | end | ||
1,700行目: | 1,784行目: | ||
local value = "" | local value = "" | ||
local ref = {} | local ref = {} | ||
local version = 1 -- increase this each time the below logic is changed to avoid conflict errors | |||
if statement.snaks then | if statement.snaks then | ||
1,705行目: | 1,791行目: | ||
if statement.snaks[p.aliasesP.importedFrom] then | if statement.snaks[p.aliasesP.importedFrom] then | ||
statement.snaks[p.aliasesP.importedFrom] = nil | statement.snaks[p.aliasesP.importedFrom] = nil | ||
end | |||
-- don't include "inferred from", which is added by a bot | |||
if statement.snaks[p.aliasesP.inferredFrom] then | |||
statement.snaks[p.aliasesP.inferredFrom] = nil | |||
end | |||
-- don't include "type of reference" | |||
if statement.snaks[p.aliasesP.typeOfReference] then | |||
statement.snaks[p.aliasesP.typeOfReference] = nil | |||
end | |||
-- don't include "image" to prevent littering | |||
if statement.snaks[p.aliasesP.image] then | |||
statement.snaks[p.aliasesP.image] = nil | |||
end | end | ||
1,842行目: | 1,943行目: | ||
if not self.rawValue then | if not self.rawValue then | ||
-- this should become a <ref> tag, so safe the reference's hash for later | -- this should become a <ref> tag, so safe the reference's hash for later | ||
value.refHash = statement.hash | value.refHash = "wikidata-" .. statement.hash .. "-v" .. (tonumber(i18n['cite']['version']) + version) | ||
end | end | ||