Модуль:Песочница/Pok: различия между версиями

м Содержимое страницы заменено на «local p = {} local frame = mw.getCurrentFrame() function p.listUncategorizedGIFs() local uncategorized = {} local allFiles = mw.site.allPages('', 'File') for title in allFiles do local filename = title.text if filename:match("%.gif$") then local file = mw.title.new('File:' .. filename) if file then local content = file:getContent() if content and not content:match('%[%[Category:') then table.insert(...»
Метка: замена
Нет описания правки
 
(не показано 75 промежуточных версий этого же участника)
Строка 1: Строка 1:
local p = {}
local p = {}
local frame = mw.getCurrentFrame()
local getArgs = require('Module:Arguments').getArgs


function p.listUncategorizedGIFs()
function p.main(frame)
local uncategorized = {}
    local args = getArgs(frame, { removeBlanks = false })
local allFiles = mw.site.allPages('', 'File')  
    local name = args[1] or ""
    local attributes = args[2] 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")


for title in allFiles do
    local found = {}
local filename = title.text
if filename:match("%.gif$") then
local file = mw.title.new('File:' .. filename)
if file then
local content = file:getContent()
if content and not content:match('%[%[Category:') then
table.insert(uncategorized, '* [[:File:' .. filename .. ']]')
end
end
end
end


if #uncategorized == 0 then
    if include_base then
return 'Все gif-файлы категоризированы.'
        local t = mw.title.new("Файл:" .. name .. "." .. ext)
end
        if t and t.exists then
            table.insert(found, "")
        end
    end


return table.concat(uncategorized, '\n')
    for i = 1, max do
        local t = mw.title.new("Файл:" .. 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 .. "|" .. attributes .. "]]"
 
    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
end


return p
return p