Модуль:Песочница/Pok: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 1: | Строка 1: | ||
local p = {} | local p = {} | ||
function p.main(frame) | function p.main(frame) | ||
| Строка 47: | Строка 36: | ||
local parts = {} | local parts = {} | ||
table.insert(parts, "<choose before=\"" .. | table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">") | ||
for _, suf in ipairs(found) do | for _, suf in ipairs(found) do | ||
table.insert(parts, "<option>" .. | table.insert(parts, "<option>" .. suf .. "</option>") | ||
end | end | ||
table.insert(parts, "</choose>") | table.insert(parts, "</choose>") | ||
return table.concat(parts, "\n") | return frame:preprocess(table.concat(parts, "\n")) | ||
end | end | ||
return p | return p | ||
Версия от 02:46, 17 марта 2026
Для документации этого модуля может быть создана страница Модуль:Песочница/Pok/doc
local p = {}
function p.main(frame)
local args = frame.args or {}
local name = args[1] or args["name"] or ""
if name == "" then
return "<span class=\"error\">Ошибка: не указано имя файла.</span>"
end
local ext = (args["ext"] or "png"):gsub("^%.", "")
local namespace = args["namespace"] or "Файл"
local max = tonumber(args["max"]) or 50
local include_base = (args["base"] ~= "no")
local found = {}
if include_base then
local t = mw.title.new("File:" .. name .. "." .. ext)
if t and t.exists then
table.insert(found, "")
end
end
for i = 1, max do
local t = mw.title.new("File:" .. name .. "-" .. i .. "." .. ext)
if t and t.exists then
table.insert(found, "-" .. i)
end
end
if #found == 0 then
return ""
end
local before = "[[" .. namespace .. ":" .. name
local after = "." .. ext .. "]]"
local parts = {}
table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">")
for _, suf in ipairs(found) do
table.insert(parts, "<option>" .. suf .. "</option>")
end
table.insert(parts, "</choose>")
return frame:preprocess(table.concat(parts, "\n"))
end
return p