Module:RecursiveSelectiveList: Difference between revisions

From Ikwipedia
No edit summary
No edit summary
Line 9: Line 9:
     end
     end


     -- Fetch the category
     -- Fetch category members using mw.site
     local category = mw.title.new("Category:" .. categoryName)
    local categoryTitle = "Category:" .. categoryName
     local category = mw.site.getCategoryMembers(categoryTitle, "all", 500) -- Fetch up to 500 members
     if not category then
     if not category then
         return "Error: Invalid category name."
         return "Error: Unable to fetch category members. Is the category name correct?"
     end
     end


     -- Get category members
     -- Generate a bulleted list of members
    local members = category:linkedPages()
     local output = {}
     local output = {}
 
     for _, member in ipairs(category) do
     for _, member in ipairs(members) do
         table.insert(output, "* [[" .. member.title .. "]]")
         table.insert(output, "* [[" .. member.fullText .. "]]")
     end
     end



Revision as of 06:50, 22 December 2024

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']

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

    -- Fetch category members using mw.site
    local categoryTitle = "Category:" .. categoryName
    local category = mw.site.getCategoryMembers(categoryTitle, "all", 500) -- Fetch up to 500 members
    if not category then
        return "Error: Unable to fetch category members. Is the category name correct?"
    end

    -- Generate a bulleted list of members
    local output = {}
    for _, member in ipairs(category) do
        table.insert(output, "* [[" .. member.title .. "]]")
    end

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

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

return p