Модуль:Entity Sprite/all: различия между версиями

Нет описания правки
Метка: отменено
Нет описания правки
Метка: ручная отмена
 
(не показана 1 промежуточная версия этого же участника)
Строка 199: Строка 199:
end
end


local function collectFileTitles(data)
local function buildFileLink(id, project)
local titles = {}
return "[[:Файл:" .. prefix .. id .. ".png]]"
 
for id, _ in pairs(data) do
table.insert(titles, "Файл:" .. prefix .. id .. ".png")
end
 
return titles
end
 
local function buildFileExistenceMap(data)
local titlesList = collectFileTitles(data)
 
local titleObjs = mw.title.newBatch(titlesList)
:lookupExistence()
:getTitles()
 
local map = {}
 
for _, title in ipairs(titleObjs) do
if title and title.prefixedText then
map[title.prefixedText] = title.exists and not title.isRedirect
end
end
 
return map
end
 
local function buildFileLink(id, existenceMap)
local name = "Файл:" .. prefix .. id .. ".png"
local link = "[[:" .. name .. "]]"
 
if existenceMap[name] then
return "<code>" .. link .. "</code>"
end
 
return link
end
end


Строка 284: Строка 249:
end
end


local function generateRepeatTemplate(data, project, baseUrl, existenceMap)
local function generateRepeatTemplate(data, project, baseUrl)
local spriteGroups = {}
local spriteGroups = {}


Строка 301: Строка 266:


for _, obj in ipairs(group) do
for _, obj in ipairs(group) do
table.insert(idLinks, buildFileLink(obj.id, existenceMap))
table.insert(idLinks, buildFileLink(obj.id, project))
end
end


Строка 368: Строка 333:


if action == "repeat" then
if action == "repeat" then
local existenceMap = buildFileExistenceMap(filteredData)
return generateRepeatTemplate(filteredData, project, baseUrl)
return generateRepeatTemplate(filteredData, project, baseUrl, existenceMap)
elseif action == "image" then
elseif action == "image" then
local result = {}
local result = {}