Modulo:Coord: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
m applico fix di Titore per le anteprime di MediaWiki
non generare indicatore quando non va mostrato, fix per Special:Permalink/140491317#Anomalia_coordinate
 
(4 versioni intermedie di 2 utenti non mostrate)
Riga 3:
]]
 
require('Modulo:No globalsstrict')
 
local mWikidata = require('Modulo:Wikidata')
Riga 61:
debug = args.display == 'debug'
}
end
 
local function getZoom( extraparams )
local scale = extraparams:match( '%f[%w]scale: ?(%d+)' )
if scale then
return math.floor(math.log10( 5 / tonumber( scale ) ) * 3 + 25)
end
 
local extraType = extraparams:match( '%f[%w]type: ?(%w+)' )
if extraType then
local zoomType = {
country = 5,
state = 6,
adm1st = 7,
adm2nd = 8,
city = 9,
isle = 10,
mountain = 10,
waterbody = 10,
airport = 12,
landmark = 13,
}
return zoomType[ extraType ]
end
return 13
end
 
Riga 297 ⟶ 323:
-- Legge la P625 e la utilizza come latitudine e longitudine se non fornite dall'utente.
function Coord:_checkWikidata()
self.wdEntityId = self.args.from or mw.wikibase.getEntityIdForCurrentPage();
if self.args.prop then
self.wdLat = mWikidata._getQualifier({ self.args.prop, 'P625', coord = 'latitude', n = 1, nq = 1, from = self.args.fromwdEntityId })
self.wdLong = mWikidata._getQualifier({ self.args.prop, 'P625', coord = 'longitude', n = 1, nq = 1, from = self.args.fromwdEntityId })
else
self.wdLat = mWikidata._getProperty({ 'P625', coord = 'latitude', n = 1, from = self.args.fromwdEntityId })
self.wdLong = mWikidata._getProperty({ 'P625', coord = 'longitude', n = 1, from = self.args.fromwdEntityId })
end
if self.wdLat and self.wdLong then
Riga 370 ⟶ 397:
local currFormat = cfg.params[self.reqFormat]
local globe = self.args[#self.args]:match('globe:(%w+)')
local earthself.isEarth = not globe or globe == 'earth'
for k, v in ipairs(self.args) do
if currFormat[k] then
Riga 382 ⟶ 409:
local num = tonumber(v)
if num then
if earthself.isEarth and num < parMin then
err = string.format('* %s format: %s < %s', self.reqFormat, parName, parMin)
elseif earthself.isEarth and math.floor(num) > parMax then
err = string.format('* %s format: %s > %s', self.reqFormat, parName, parMax)
end
Riga 431 ⟶ 458:
end
 
-- Restituisce l'HTML contenentedi leun coordinateelemento in<maplink> formatodi decKartographer eper dmsle come collegamento esterno a geohack.php.coordinate
--
-- @return {string}
function Coord:getHTML_buildMaplinkHTML()
local defaultFormat, geohackParams, display, root, html, url, htmlTitle
 
-- con args.from restitusce una stringa vuota se non c'è nessun dato
if self.args.from and #self.args < 2 and not tonumber(self.args[1]) then
return ''
elseif self.args.display == 'debug' then
return self:getDebugCoords()
end
 
-- legge il parametro display
display = getDisplay(self.args)
 
if self.args.format then
defaultFormat = self.args.format
Riga 455 ⟶ 471:
end
 
local linkText;
if defaultFormat == 'dec' then
linkText = self.decLat .. ' ' .. self.decLong
else
linkText = tostring(self.dmsLat) .. ' ' .. tostring(self.dmsLong)
end
 
local jsonParams = {
type = 'Feature',
geometry = {
type ='Point',
coordinates = {
round( self.decLong:getDeg(), 6 ), -- max precision in GeoJSON format
round( self.decLat:getDeg(), 6 )
}
},
properties = {
['marker-color'] = "228b22",
}
}
 
if self.wdEntityId then
-- geoshape da Wikidata
jsonParams = {
jsonParams,
{
type = 'ExternalData',
service = 'geoshape',
ids = self.wdEntityId,
properties = {
['fill-opacity'] = 0.2
}
}
}
end
 
return mw.getCurrentFrame():extensionTag{
name = 'maplink',
content = mw.text.jsonEncode( jsonParams ),
args = {
text = linkText,
zoom = getZoom( self.args[#self.args] or '' ),
latitude = self.decLat:getDeg(),
longitude = self.decLong:getDeg(),
}
}
end
 
 
-- Restituisce l'HTML di un link a geohack con le coordinate (usato solo quando
-- non è possibile usare maplink).
--
-- @return {string}
function Coord:_buildGeohackLink()
-- crea la stringa per il parametro params di geohack.php
local geohackParams
 
if self.reqFormat == 'dec' then
geohackParams = string.format('%s_N_%s_E', self.args[1], self.args[2])
Riga 465 ⟶ 537:
geohackParams = table.concat(self.args, '_')
end
 
-- geohack url e parametri
local url = string.format('%s&pagename=%s&params=%s', cfg.geohackUrl,
mw.uri.encode(mw.title.getCurrentTitle().prefixedText, 'WIKI'), geohackParams)
if self.args.name then
url = url .. '&title=' .. mw.uri.encode(self.args.name)
end
local linkNode = mw.html.create('span')
:addClass('plainlinks nourlexpansion')
:wikitext('[' .. url .. ' ' .. tostring(self.dmsLat) .. ' ' .. tostring(self.dmsLong) .. ']')
:done()
return tostring(linkNode)
end
 
-- Restituisce l'HTML per il microformat Geo.
root = mw.html.create('')
-- FIXME Serve ancora nel 2024? La documentazione in proposito è scarsissima, e tutti
root
-- i link a strumenti che lo usano non vanno più. Inoltre, qui usiamo un elemento nascosto;
-- va bene lo stesso? Come verificarlo? Le specifiche non ne parlano.
--
-- @return {string}
function Coord:_buildGeoMarkup()
return mw.html.create('')
:wikitext(self.args.name and '<span class="vcard">' or '')
:tag('span')
:addClassattr('plainlinksstyle', nourlexpansion'display:none')
:wikitextaddClass('[geo' .. url)
:tag('span')
:addClass(defaultFormat == 'dec' and 'geo-nondefault' or 'geo-default')
:tag('span')
:addClass('geo-dms')
:attr('title', 'Mappe, foto aeree e altri dati per questa posizione')
:tag('span')
:addClass('latitude')
:wikitext(tostring(self.dmsLat))
:done()
:wikitext(' ')
:tag('span')
:addClass('longitude')
:wikitext(tostring(self.dmsLong))
:done()
:done()
:done()
:tag('span')
:addClass('geo-multi-punctlatitude')
:wikitext('&#xfeff; / &#xfeff;'tostring(self.dmsLat))
:done()
:wikitext( ', ' )
:tag('span')
:addClass(defaultFormat == 'dec' and 'geo-default' or 'geo-nondefaultlongitude')
:wikitext(tostring(self.args.name and '<span class="vcard">' or ''dmsLong))
:tag('span')
:addClass('geo-dec')
:attr('title', 'Mappe, foto aeree e altri dati per questa posizione')
:wikitext(self.decLat .. ' ' .. self.decLong)
:done()
:tag('span')
:attr('style', 'display:none')
:tag('span')
:addClass('geo')
:wikitext(self.decLat:getDeg() .. '; ' .. self.decLong:getDeg())
:done()
:done()
:wikitext(self.args.name and ('<span style="display:none"> (<span class="fn org">' ..
self.args.name .. '</span>)</span></span>') or '')
:done()
:wikitext(self.args.name and ('<span style="display:none"> (<span class="fn org">' ..
:wikitext(']')
self.args.name .. '</span>)</span></span>') or '')
:done()
end
 
-- Restituisce l'HTML contenente le coordinate con link che utilizza <maplink> (Kartographer)
html = tostring(root) .. (self.args.notes or '')
-- se possibile, e geohack altrimenti.
--
-- @return {string}
function Coord:getHTML()
-- con args.from restitusce una stringa vuota se non c'è nessun dato
if self.args.from and #self.args < 2 and not tonumber(self.args[1]) then
return ''
elseif self.args.display == 'debug' then
return self:getDebugCoords()
end
 
local display = getDisplay(self.args)
-- formatta il risultato a seconda di args.display (nil, 'inline', 'title', 'inline,title')
 
-- se inline e title, in stampa visualizza solo il primo
local coordLink
htmlTitle = string.format('<div style="font-size: small"><span %s id="coordinates">[[Coordinate geografiche|Coordinate]]: %s</span></div>',
if self.isEarth then
display.inline and 'class="noprint"' or '', html)
-- Usa maplink se possibile. A maggio 2024 supporta solo coordinate terrestri,
-- vedi T151138.
coordLink = self:_buildMaplinkHTML()
else
coordLink = self:_buildGeohackLink()
end
 
local geo = self:_buildGeoMarkup();
 
local html = coordLink .. tostring(geo) .. (self.args.notes or '')
 
local frame = mw.getCurrentFrame()
local ret = frame:extensionTag('templatestyles', '', {src = 'Modulo:Coord/styles.css'}) ..
(display.inline and html or '');
 
if display.title then
-- formatta il risultato a seconda di args.display (nil, 'inline', 'title', 'inline,title')
-- se inline e title, in stampa visualizza solo il primo
local htmlTitle = string.format(
'<div style="font-size: small"><span %s id="coordinates">[[Coordinate geografiche|Coordinate]]: %s</span></div>',
display.inline and 'class="noprint"' or '',
html
)
ret = ret .. frame:extensionTag( 'indicator', htmlTitle, { name = 'coordinates' } )
end
 
return ret ..
return mw.getCurrentFrame():extensionTag('templatestyles', '', {src = 'Modulo:Coord/styles.css'}) ..
self:_setGeoData(display.inline and html or '') ..
(displaymw.title.getCurrentTitle().namespace == 0 and htmlTitleself.wdCat or '') ..
self:_setGeoData(display) ..
(mw.title.getCurrentTitle().namespace == 0 and self.wdCat or '')
end