Module:RecursiveSelectiveList

Revision as of 06:55, 22 December 2024 by EnWikiAdmin (talk | contribs)

Documentation for this module may be created at Module:RecursiveSelectiveList/doc

local p = {}

function p.main(frame)
    local args = frame:getParent().args
    local categoryName = args['categoryName']
    local limit = tonumber(args['limit']) or 10

    if not categoryName then
        return "Error: Please provide a category name."
    end

    -- Fetch category members
    local category = mw.title.new("Category:" .. categoryName)
    if not category then
        return "Error: Invalid category name."
    end

    local members = {}
    for member in category:members() do
        if #members >= limit then
            break
        end
        table.insert(members, "* [[" .. member.fullText .. "]]")
    end

    if #members == 0 then
        return "No pages found in the category."
    end

    return table.concat(members, "\n")
end

return p