「モジュール:Wd」の版間の差分

en:Module:Wd 2018年9月15日 (土) 13:55(UTC)より
(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:smaller\">(%q)</span>][%s][%r]",
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 = "wikidata-" .. valuesArray[i].refHash .. "-v" .. i18n['cite']['version']})
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 = tostring(yRound * sign)
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 latValue, latitude, latDegrees, latMinutes, latSeconds
local latitude, latConv, latValue, latLink
local lonValue, longitude, lonDegrees, lonMinutes, lonSeconds
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
numDigits = math.ceil(-math.log10(3600 * 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 < 0 or numDigits == -0 then
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"
-- use string.format() to strip decimal point followed by a zero (.0) for whole numbers
if precision >= 1 then
latSeconds = tonumber(strFormat:format(math.floor(latitude * 3600 * 10^numDigits + 0.5) / 10^numDigits))
latDegrees = strFormat:format(latitude)
lonSeconds = tonumber(strFormat:format(math.floor(longitude * 3600 * 10^numDigits + 0.5) / 10^numDigits))
lonDegrees = strFormat:format(longitude)
latMinutes = math.floor(latSeconds / 60)
lonMinutes = math.floor(lonSeconds / 60)
latSeconds = latSeconds - (latMinutes * 60)
lonSeconds = lonSeconds - (lonMinutes * 60)
latDegrees = math.floor(latMinutes / 60)
lonDegrees = math.floor(lonMinutes / 60)
latMinutes = latMinutes - (latDegrees * 60)
lonMinutes = lonMinutes - (lonDegrees * 60)
latValue = latDegrees .. degSymbol
lonValue = lonDegrees .. degSymbol
if precision < 1 then
latValue = latValue .. latMinutes .. minSymbol
lonValue = lonValue .. lonMinutes .. minSymbol
end
if precision < (1 / 60) then
latSeconds = strFormat:format(latSeconds)
lonSeconds = strFormat:format(lonSeconds)
if not raw then
if not raw then
-- replace decimal marks based on locale
latDegSym = replaceDecimalMark(latDegrees) .. degSymbol
latSeconds = replaceDecimalMark(latSeconds)
lonDegSym = replaceDecimalMark(lonDegrees) .. degSymbol
lonSeconds = replaceDecimalMark(lonSeconds)
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
latValue = latValue .. latSeconds .. secSymbol
latDegrees = math.floor(latMinutes / 60)
lonValue = lonValue .. lonSeconds .. secSymbol
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 .. latDirection
latValue = latDegSym .. latMinSym .. latSecSym .. latDirection
lonValue = lonValue .. lonDirection
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.."&params="..latitude.."_"..latDirectionEN.."_"..longitude.."_"..lonDirectionEN.."_globe:"..globe.." "..value.."]"
latLink = table.concat({latDegrees, latMinutes, latSeconds}, "_")
lonLink = table.concat({lonDegrees, lonMinutes, lonSeconds}, "_")
value = "[https://tools.wmflabs.org/geohack/geohack.php?language="..self.langCode.."&params="..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
匿名利用者