Модуль:ТранспортнаяСхема: различия между версиями

мНет описания правки
мНет описания правки
Строка 1: Строка 1:
local p = {}
local p = {}


-- Универсальное слияние аргументов
local function getArgs(frame)
local function getArgs(frame)
     local args = {}
     local args = {}
Строка 15: Строка 16:
end
end


-- Безопасная загрузка JSON
local function loadData(args)
local function loadData(args)
     local dataParam = args['данные'] or args[1]
     local dataParam = args['данные'] or args[1]
Строка 51: Строка 53:
end
end


-- Генерация кода <imagemap> с защитой от пустых параметров
local function buildImageMap(jsonData, imageFile, width, defaultRadius)
local function buildImageMap(jsonData, imageFile, width, defaultRadius)
     local radius = defaultRadius or '16'
     local radius = defaultRadius or '16'
    local mapText = 'Файл:' .. imageFile .. '|' .. width .. '|center|alt=' .. (jsonData.title or 'Схема транспорта') .. '\n'
      
      
     for _, line in ipairs(jsonData.lines or {}) do
     -- Жесткая проверка на наличие имени файла
        if line.box and line.article then
    if not imageFile or imageFile == '' then
            mapText = mapText .. 'rect ' .. line.box .. ' [[' .. line.article .. '|' .. (line.name or line.article) .. ']]\n'
        imageFile = 'Схема_Муроморского_метрополитена.png'
        end
    end
       
   
        for _, station in ipairs(line.stations or {}) do
    -- Жесткая проверка на наличие ширины
            if station.coords and station.article then
    if not width or width == '' then
                local stRadius = station.radius or radius
        width = '850px'
                mapText = mapText .. 'circle ' .. station.coords .. ' ' .. stRadius .. ' [[' .. station.article .. '|' .. (station.name or station.article) .. ']]\n'
    end
 
    -- Первая строка imagemap (используем File: для стабильности парсера)
    local mapText = 'File:' .. imageFile .. '|' .. width .. '|center\n'
   
    if jsonData and jsonData.lines then
        for _, line in ipairs(jsonData.lines) do
            if line.box and line.article then
                mapText = mapText .. 'rect ' .. line.box .. ' [[' .. line.article .. '|' .. (line.name or line.article) .. ']]\n'
            end
           
            if line.stations then
                for _, station in ipairs(line.stations) do
                    if station.coords and station.article then
                        local stRadius = station.radius or radius
                        mapText = mapText .. 'circle ' .. station.coords .. ' ' .. stRadius .. ' [[' .. station.article .. '|' .. (station.name or station.article) .. ']]\n'
                    end
                end
             end
             end
         end
         end
Строка 86: Строка 105:
      
      
     local isInfobox = (args['карточка'] == 'да' or args['тип'] == 'карточка')
     local isInfobox = (args['карточка'] == 'да' or args['тип'] == 'карточка')
     local width = args['ширина'] or (isInfobox and '280px') or jsonData.width or '850px'
   
     local imageFile = args['файл'] or jsonData.image or 'Схема_Муроморского_метрополитена.png'
    -- Определение ширины с учетом карточки
     local caption = args['подпись'] or jsonData.caption or ''
     local width = args['ширина'] or (isInfobox and '280px') or (jsonData and jsonData.width) or '850px'
     local defaultRadius = args['радиус'] or jsonData.defaultRadius or '16'
     local imageFile = args['файл'] or (jsonData and jsonData.image) or 'Схема_Муроморского_метрополитена.png'
     local caption = args['подпись'] or (jsonData and jsonData.caption) or ''
     local defaultRadius = args['радиус'] or (jsonData and jsonData.defaultRadius) or '16'
      
      
     local root = mw.html.create('div')
     local root = mw.html.create('div')
Строка 99: Строка 120:
             ['text-align'] = 'center'
             ['text-align'] = 'center'
         })
         })
    -- Принудительное ограничение стилей для картинок внутри схемы (чтобы не ломали инфобокс)
    root:wikitext('<style>.ts-transport-map-card img { max-width: 100% !important; width: 100% !important; height: auto !important; box-sizing: border-box; }</style>')


     -- Контейнер карты
     -- Контейнер карты