Module:RecursiveSelectiveList: Difference between revisions
EnWikiAdmin (talk | contribs) No edit summary |
EnWikiAdmin (talk | contribs) No edit summary |
||
Line 9: | Line 9: | ||
return p]]-- | return p]]-- | ||
local p = {} | |||
local p = {} | local p = {} | ||
function p.main(frame) | function p.main(frame) | ||
return p. | return p.getCategoryStats(frame) | ||
end | end | ||
function p. | function p.getCategoryStats(frame) | ||
local categoryName = frame.args | local categoryName = frame.args[1] -- Pass the category name as an argument | ||
if not | if not categoryName or categoryName == "" then | ||
return " | return "Error: No category name provided." | ||
end | end | ||
local | 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 = {} | 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") | |||
return table.concat(result, " | |||
end | end | ||
return p | return p |
Revision as of 08:25, 22 December 2024
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