Module:RecursiveSelectiveList

From Ikwipedia
Revision as of 08:25, 22 December 2024 by EnWikiAdmin (talk | contribs)

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

--[[local p = {}
local mw = require('mw')

function p.main(frame)
    local categoryName = "Category:" .. frame.args.categoryName
    local content = mw.title.new(categoryName):getContent()
    return content or "The category '" .. categoryName .. "' does not exist or has no content."
end

return p]]--
local p = {}

local p = {}

function p.main(frame)
    return p.getCategoryStats(frame)
end

function p.getCategoryStats(frame)
    local categoryName = frame.args[1] -- Pass the category name as an argument

    if not categoryName or categoryName == "" then
        return "Error: No category name provided."
    end

    local stats = mw.site.stats.pagesInCategory(categoryName, "*")
    if not stats then
        return "Error: Unable to retrieve statistics for the category."
    end

    -- Format the results
    local result = {}
    table.insert(result, "Category: " .. categoryName)
    table.insert(result, "Total items: " .. stats.all)
    table.insert(result, "Subcategories: " .. stats.subcats)
    table.insert(result, "Files: " .. stats.files)
    table.insert(result, "Pages: " .. stats.pages)

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

return p