Notice: Template failed integrity check: /home/jvzmxxx/wiki/extensions/MobileFrontend/includes/skins/minerva.mustache in /home/jvzmxxx/wiki/includes/TemplateParser.php on line 121
Zmiany – Czarnobyl Wiki
Otwórz menu główne

Czarnobyl Wiki β

Zmiany

Moduł:Mapa

Dodane 327 bajtów, 18:44, 4 wrz 2019
Anulowanie wersji 57383732 autorstwa Paweł Ziemian (dyskusja) działało ale nie chcemy ukrywać błędów
mw.log("„"..map.."” nie jest prawidłową nazwą definicji mapy lokalizacyjnej")
elseif moduletitle.exists then
mw.log("Ładuję mapę z „"..moduletitle.fullText.."”")
local status, mapData = pcall(mw.loadData, moduletitle.fullText)
if status then
return function(name, variant)
if name == nil then
--mw.logObject(moduletitle.fullText, "GET module title")
return moduletitle.fullText
end
local variants = variant and mw.text.split(variant, "%s*#%s*") or {}
--mw.logObject(variants, "GET map variants")
if name == true then
for _, v in ipairs(variants) do --mw.logObject(mapData[variantv], "GET map variant") return if type(mapData[variantv]) == "table" then return v end end return 1 end for _, v in ipairs(variants) do if mapData[v] and mapData[v][name] ~= nil then --mw.logObject({variant or 1=v, name=name, result=mapData[v][name] }, "GET") return mapData[v][name] end
end
if variant and mapData[variant] and mapData[variant1][name] ~= nil then --mw.logObject({variantname=variantname, nameresult=mapData[1][name] }, "GET") return mapData[variant1][name]
end
--mw.logObject({name=name}, "GET") return mapData[1][name] or ""
end
end
local function formatCoordinates(parameters)
mw.logObject(parameters, "formatCoordinates parameters")
if not parameters.coordinates then
return false
placement = ((parameters.linkFlag == false) or (mw.title.getCurrentTitle().namespace ~= 0)) and "w tekście" or "w tekście i na górze"
end
local frame = { args = return require("Moduł:Współrzędne")["współrzędne"]({
parameters.coordinates,
parameters.geohack,
["umieść"] = placement,
["dokładność"] = parameters.precision, }} local m = require( ["Moduł:Koordynatylinkuj") local result ] = (parameters.linkFlag == false) and m.format(frame) "nie" or m.link(frame)"tak", mw symbol = parameters.logObject(resultsymbol, "formatCoordinates result") return result})
end
local function decodePoints(pointsData)
if pointsData and (#pointsData > 0) then
mw.logObject("["..pointsData.."{\"dummy\":false}]", "pda")
local data = mw.text.jsonDecode("["..pointsData.."{\"dummy\":false}]")
mw.logObject(data, "data")
table.remove(data) -- remove last dummy
mw.logObject(data, "data last removed")
return data
end
local function estimateTextWidth(wikicode, fontSize)
mw.logObject({ wikikode, fontSize }, "estimateTextWidth")
local text = mw.ustring.gsub(wikicode, "%[%[[^\n|%]%[]+|([^\n|%]%[]+)%]%]", "%1")
mw.logObject(text, "estimateTextWidth 1")
text = mw.ustring.gsub(text, "%[%[([^\n|%]%[]+)%]%]", "%1")
mw.logObject(text, "estimateTextWidth 2")
text = mw.ustring.gsub(text, "<[^>]*>", "")
mw.logObject(text, "estimateTextWidth 3")
return mw.ustring.len(text) * fontSize
end
local function drawMap(builder, get, width, fontSize, data)
local reliefImage = mw.text.trim(get("mapa"))
mw.logObject(reliefImage, "DRAWMAP reliefImage")
local reliefTitle = mw.title.new("Plik:"..reliefImage)
mw.logObject(reliefTitle, "DRAWMAP reliefTitle")
if not reliefTitle.file.exists then
reliefTitle = mw.title.new("Plik:Image of nothing.svg")
end
local file = reliefTitle.file
mw.logObject(file, "DRAWMAP file")
local height = file.height * width / file.width
local outside = {}
local errors = {}
local hoverPoints = false
if data and (#data > 0) then
local x_func = mw.text.trim(get("x"))
local y_func = mw.text.trim(get("y"))
mw.logObject({x=x_func, y=y_func, }, "xy")
local top = get("top")
local left = get("left")
else
table.insert(inside, v)
if not hoverPoints and (v.position == "hover") and v.description then
hoverPoints = true
end
end
elseif v.error then
end
mw.logObject(outside, "outside")
mw.logObject(inside, "inside")
mw.logObject(errors, "errors")
 
-- tło mapy
local relief = builder:tag("div")
relief:css({ position = "relative", border = "0 solid #aaa", padding = "0", width = tostring(width).."px" })
relief:wikitext("[[Plik:", reliefImage, "|", width, "px|link=")
if not hoverPoints then local reliefInfo = get("dopełniacz") if reliefInfo then relief:wikitext("|Mapa lokalizacyjna ", reliefInfo) end
end
local v = inside[1]
if (v.longitude == 0) and (v.latitude == 0) then
--mw.log("dummy (0 0) bez mapy nie jest rysowany")
return
end
for i, v in ipairs(outside) do
mw.logObject(v, "outside["..tostring(i).."]")
showError("współrzędne spoza mapy", v.latitude, v.longitude)
end
for i, v in ipairs(errors) do
mw.logObject(v, "error["..tostring(i).."]")
showError(true, v.error or "?")
end
-- punkty na mapie
for i, v in ipairs(inside) do
mw.logObject(v, "inside["..tostring(i).."]")
local hsize = tostring(v.size/2).."px"
local size = tostring(v.size).."px"
file:wikitext("]]")
-- TODO description
if v.description and (v.position ~= "hover") then
local desc = absolute:tag("div")
:css( { ["font-size"] = tostring(fontSize).."px", ["line-height"] = tostring(1.2*fontSize).."px", ["z-index"] = "90", ["position"] = "relativeabsolute", ["width"] = "10em", } )
local css = {}
if v.position == "right" then
css = { top = "-10.1em5em", left = tostring((v.size / 2) + 2).."px", ["text-align"] = "left", float = "left" }
elseif v.position == "left" then
css = { top = "-10.1em5em", left right = "-"..tostring((v.size / 2) + 2).."px", ["text-align"] = "right", float = "right" }
elseif v.position == "top" then
css = { top bottom = "-tostring((v.size / 4) + 2)..0em"px", left = "-5em", ["text-align"] = "center", float = "center" }
elseif v.position == "bottom" then
css = { top = tostring((v.size / 4) + 2).."-0.1empx", left = "-5em", ["text-align"] = "center", float = "center" }
else -- auto
local textWidth = estimateTextWidth(v.description, fontSize) * 0.6
mw.logObject( { x = v.x, rx = v.rx, tw = textWidth, w = width, rw = v.rx + textWidth }, "auto position: "..v.description)
if (v.x < 50) or ((v.rx + textWidth + (v.size / 2) + 2) < width) then -- right
css = { top = "-0.5em", left = tostring((v.size / 2) + 2).."px", ["text-align"] = "left", float = "left" } else elseif ((v.rx - (v.size / 2) - 2) > textWidth) or (v.x > 70) then -- left css = { top = "-10.1em5em", left right = tostring((v.size / 2) + 2).."px", ["text-align"] = "right", float = "right" } elseif (v.y > 50) then -- top css = { bottom = tostring((v.size / 4) + 2).."px", left = "-5em", ["text-align"] = "center", float = "center" } else -- bottom css = { top = tostring((v.size / 24) + 2).."px", left = "-5em", ["text-align"] = "rightcenter", float = "rightcenter" }
end
css.top = v.y < 10 and "-0.85em" or "-1.1em"
end
local linkAlias = get("link alias")
local mapVariant = get(true)
mw.logObject({group=group, name=linkAlias, variant=mapVariant}, "makeTrakcingLinks")
if not linkAlias or (#linkAlias == 0) then
return
local trackingLink = "Moduł:Mapa/linkujące/"..linkAlias.."/"..group
mw.logObject({trackingLink, trackingLink.."/"..mapVariant}, "links")
_ = mw.title.new(trackingLink).id
_ = mw.title.new(trackingLink.."/"..mapVariant).id
end
 
local function adjustPointParams(points, mapgeohack)
for i, p in ipairs(points) do
local link = p.link
if link then
if mapgeohack==false then
p.link = ""
elseif mapgeohack then
p.link = link.."_"..mapgeohack
elseif p.geohack then
p.link = link.."_"..p.geohack
end
end
end
end
["Infobox"] = function(frame)
-- log wskazujący na początek wywołania funkcji
mw.log("{{#invoke:Moduł:Mapa|Infobox}}")
local args = require('Module:Arguments').getArgs(frame, {
trim = true,
removeBlanks = true,
wrappers = "Szablon:Infobox mapa lokalizacyjna",
})
local defaultIcon = "[[Plik:Geographylogo.svg|20px|alt=Ziemia|link=Ziemia]]"
local markSize = tonumber(args["wielkość znaku"]) or 6
local coordinates = args["współrzędne"]
local extraCategory = false
if not coordinates then
local latitude = tonumber(args["szerokość"]) local longitude = tonumber(args["długość"]) if latitude and longitude then coordinates = tostring(latitude).." "..tostring(longitude) mw.log("współrzędne tylko w starym stylu: "..coordinates) extraCategory = "[[Kategoria:Infobox mapa lokalizacyjna - szerokość i długość]]" else mw.log("infobox może wyszukać współrzędne w wikidanych") end
else
mw.log("współrzędne: "..coordinates)
if args["wikidane"] == "nie" then
mw.log("brak punktów na mapę, a nie ma pozwolenia na Wikidane")
elseelseif map ~= "pusta" then
mw.log("brak punktów na mapę i współrzędnych, nadszedł czas na Wikidane")
local display = true
if (map ~= "osobna") and (map ~= "pusta") and (map ~= "niedostępna") then
display = "#coordinates"
end
local p = require("Moduł:KoordynatyWspółrzędne").punkt({
["opcje geohack"] = geohack,
["znak"] = mark,
["dokładność"] = precision,
display = display,
symbol = false,
})
if not p then
end
mw.logObject(p, "p")
points = p
end
end
if not points and not coordinates and (mw.title.getCurrentTitle().fullText == frame:getParent():getTitle()) and (type(frame.getParent) == "function") then
mw.log("--TEST ANY ARG")
local any = false
for k, v in pairs(frame:getParent().args) do
mw.log({k=k, v=v}, "ANY ARG")
any = true
break
if not any then
-- demo mw.log("brak jakichkolwiek argumentów w szablonie to tryb demo") points = require("Moduł:KoordynatyWspółrzędne").punkt({ "0 0", display = true , symbol = false, })
map = "brak"
end
end
mw.log("[[Kategoria:Szablony lokalizacyjne – brak współrzędnych – "..category.."]]")
return '|- style="display:none;"\n!colspan="2"|brak współrzędnych[[Kategoria:Szablony lokalizacyjne – brak współrzędnych – '..category..']]\n|-'
end
if coordinates then
local p = require("Moduł:Koordynaty").punkt({
coordinates,
["opcje geohack"] = geohack,
["znak"] = mark,
["rozmiar znaku"] = markSize,
["opis"] = description,
["pozycja"] = position,
})
mw.logObject(p, "p")
points = points and (p..points) or p
mw.logObject(points, "points (2)")
end
local pointsData = decodePoints(points)
local result = {}
if extraCategory then
table.insert(result, '|- style="display:none;"\n!colspan="2"|stare współrzędne '..extraCategory..']]\n|-')
end
local coords = false
local icon = false
if (map == "żadna") or (map == "none") then
_ = mw.title.new("Moduł:Mapa/linkujące/żadna").id
-- TODO współrzędne, geohack, linkuj=tak, dokładność=kątowo, umieść=w tekście (i na górze)
icon = defaultIcon
coords = formatCoordinates({
coordinates = coordinates,
geohack = geohack,
linkFlag = true,
precision = precision or "kątowo",
})
elseif map == "osobna" then
_ = mw.title.new("Moduł:Mapa/linkujące/osobna").id
-- TODO współrzędne, geohack, linkuj=tak, dokładność=kątowo, umieść=w tekście
icon = defaultIcon
coords = formatCoordinates({
coordinates = coordinates,
geohack = "globe:none"geohack,
linkFlag = true,
precision = precision or "kątowo", placement = "w tekście",
})
elseif map == "pusta" then
_ = mw.title.new("Moduł:Mapa/linkujące/pusta").id
-- no map nor coordinates
elseif map == "niedostępna" then
_ = mw.title.new("Moduł:Mapa/linkujące/niedostępna").id
-- TODO współrzędne, globe:none, linkuj=nie, dokładność=dziesiętnie, normalizacja=auto, ikona=
coords = formatCoordinates({
coordinates = coordinates,
geohack = "globe:none",
linkFlag = false,
precision = precision or "dziesiętnie",
else
local maps = {}
local list = string.match(map, "#")
for v in mw.ustring.gmatch(map, "[^#]+") do
table.insert(maps, mw.text.trim(v))
table.insert(maps, map)
end
if not list and (twoMaps ~= "nie") then while #map > 0 do local get = loadMap(frame, map, variant) map = mw.text.trim(get("nadrzędna") or "") if #map > 0 then table.insert(maps, 2, map) end end end 
local mapIndex = 1
local map = maps[mapIndex]
local get = loadMap(frame, map, variant)
-- prepare coordinates under the map
local icon = mw.text.trim(get("ikona") or "")
if #icon == 0 then
icon = defaultIcon
end
local mapPrecision = get("dokładność")
if mapPrecision and (#mapPrecision <= 0) then
mapPrecision = nil
end
coords = formatCoordinates({
coordinates = coordinates,
geohack = geohack or get("globe") or geohack"", linkFlag = trueget("globe") ~= false, precision = precision or mapPrecision or "kątowo", symbol = icon,
})
if coordinates then
local p = require("Moduł:Współrzędne").punkt({
coordinates,
["opcje geohack"] = geohack,
["znak"] = mark,
["rozmiar znaku"] = markSize,
["opis"] = description,
["pozycja"] = position,
symbol = false,
})
points = points and (p..points) or p
end
 
local pointsData = decodePoints(points)
if pointsData then
adjustPointParams(pointsData, get("globe"))
end
if not coords and pointsData and (#pointsData > 0) then
icon = false
-- draw maps
while map do
mw.logObject(map, "infobox-draw-map")
map = nil
-- draw map
table.insert(result, "\n")
-- next parent
if (#maps == 1) and (twoMaps ~= "nie") then local second = mw.text.trim(get("nadrzędna") or "") if second and (#second > 0) then map = second get = loadMap(frame, map, variant) end elseif mapIndex < #maps then
mapIndex = mapIndex + 1
map = maps[mapIndex]
if coords then
table.insert(result, '|-\n|colspan="2" style="background-color:white; text-align:center; border-bottom:1px solid #aaa;"|')
table.insert(result, icon and (icon.." ") or "")
table.insert(result, coords)
table.insert(result, "\n")
trim = true,
removeBlanks = false,
wrappers = "Szablon:Mapa lokalizacyjna",
})
local map = args["mapa"] or args[1] or "{{{1}}}"
local get = loadMap(frame, map, variant)
if pointsData then
adjustPointParams(pointsData, get("globe"))
end
-- tracking link, pseudo reference to this map
:css({ margin = "0 auto", width = tostring(width).."px" })
drawMap(builder, get, width, fontSize, pointsData)
if pointsData and (#pointsData == 1) and (mw.title.getCurrentTitle().namespace == 0) then
builder:wikitext("[[Kategoria:Mapa lokalizacyjna z jednym punktem]]")
end
thumbinner
:wikitext('\n')
trim = true,
removeBlanks = false,
wrappers = "Szablon:Mapa lokalizacyjna",
})
local map = args["mapa"] or args[1] or "{{{1}}}"
local get = loadMap(frame, map, variant)
if pointsData then adjustPointParams(pointsData, get("globe")) end
-- tracking link, pseudo reference to this map
makeTrackingLinks(get, "standalone")
:css({ margin ="0 auto", width = tostring(width + 2).."px", padding = "3px", margin = "3px" })
drawMap(builder, get, width, fontSize, pointsData)
if pointsData and (#pointsData == 1) and (mw.title.getCurrentTitle().namespace == 0) then
builder:wikitext("[[Kategoria:Mapa lokalizacyjna z jednym punktem]]")
end
return builder:allDone()
end,
}
Anonimowy użytkownik