Moduł:Lokalizacja: Różnice pomiędzy wersjami
Z Nonsensopedii, polskiej encyklopedii humoru
Ostrzyciel (dyskusja • edycje) M |
Ostrzyciel (dyskusja • edycje) M (AAA) |
||
(Nie pokazano 3 pośrednich wersji utworzonych przez tego samego użytkownika) | |||
Linia 11: | Linia 11: | ||
local geocoded = frame:callParserFunction('#geocode', name) |
local geocoded = frame:callParserFunction('#geocode', name) |
||
if geocoded == 'Geocoding failed' then |
if geocoded == 'Geocoding failed' then |
||
return false, name .. |
return false, name .. ' ' .. mw.smw.info('Nieprawidłowa lokalizacja', 'warning'), {} |
||
end |
end |
||
Linia 22: | Linia 22: | ||
local fParts = mw.text.split( geoF, ', ', true ) |
local fParts = mw.text.split( geoF, ', ', true ) |
||
local text = ' |
local text = '[https://www.openstreetmap.org/?mlat=' |
||
.. fParts[1] .. '&mlon=' .. fParts[2] .. '#map=13 ' .. geocoded .. ']</span>' |
.. fParts[1] .. '&mlon=' .. fParts[2] .. '#map=13 ' .. geocoded .. ']</span>' |
||
if |
if mw.ustring.find(name, '^[0-9%.,][0-9%.,]') then |
||
text = '<span style="font-style: italic;">' .. text |
|||
⚫ | |||
else |
|||
text = name .. ', <span style="font-style: italic; font-size: 0.8em">' |
|||
⚫ | |||
.. mw.uri.encode(name) .. '&polygon_geojson=1 zobacz miejsce].' |
|||
props['Ma nazwę miejsca'] = name |
props['Ma nazwę miejsca'] = name |
||
end |
end |
||
Linia 32: | Linia 36: | ||
if addInvisibleTag then |
if addInvisibleTag then |
||
-- format ma być zgodny z tym na Commons |
-- format ma być zgodny z tym na Commons |
||
-- vide https://github.com/wikimedia/mediawiki-extensions-CommonsMetadata/blob/ |
-- vide https://github.com/wikimedia/mediawiki-extensions-CommonsMetadata/blob/ea2e82fed9f1e261f4d4672ff67a9bc0f8e98662/src/TemplateParser.php#L149 |
||
⚫ | |||
local geocodedFloat = frame:callParserFunction('#geocode', { name, format = 'float', directional = 'no' }) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
Aktualna wersja na dzień 11:42, 12 sty 2021
local tools = require('Moduł:Narzędzia')
local p = {}
-- parsuje nazwę lokalizacji i zwraca trzy wartości:
-- * koordynaty wg OSM
-- * tekst do wyświetlenia w szablonie
-- * tablicę z atrybutami SMW do ustawienia
-- ustawienie drugiego parametru na true zwraca w tekście dodatkowo niewidzialny
-- tag dla różnych programistycznych cudaków
function p.parseLocation(frame, name, addInvisibleTag)
local geocoded = frame:callParserFunction('#geocode', name)
if geocoded == 'Geocoding failed' then
return false, name .. ' ' .. mw.smw.info('Nieprawidłowa lokalizacja', 'warning'), {}
end
local geoF = frame:callParserFunction( '#geocode',
{ name, format = 'float', directional = 'no' } )
local props = {
['Ma lokalizację'] = geocoded
}
local fParts = mw.text.split( geoF, ', ', true )
local text = '[https://www.openstreetmap.org/?mlat='
.. fParts[1] .. '&mlon=' .. fParts[2] .. '#map=13 ' .. geocoded .. ']</span>'
if mw.ustring.find(name, '^[0-9%.,][0-9%.,]') then
text = '<span style="font-style: italic;">' .. text
else
text = name .. ', <span style="font-style: italic; font-size: 0.8em">'
.. text .. ', [https://nominatim.openstreetmap.org/search.php?q='
.. mw.uri.encode(name) .. '&polygon_geojson=1 zobacz miejsce].'
props['Ma nazwę miejsca'] = name
end
if addInvisibleTag then
-- format ma być zgodny z tym na Commons
-- vide https://github.com/wikimedia/mediawiki-extensions-CommonsMetadata/blob/ea2e82fed9f1e261f4d4672ff67a9bc0f8e98662/src/TemplateParser.php#L149
geoF = mw.ustring.gsub(geoF, ',', ';')
text = text .. '<span class="geo" style="display:none">' .. geoF .. '</span>'
end
return geocoded, text, props
end
return p