Module:RecursiveSelectiveList: Difference between revisions
EnWikiAdmin (talk | contribs) No edit summary |
EnWikiAdmin (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
Line 15: | Line 4: | ||
return p.getCategoryMembers(frame) | return p.getCategoryMembers(frame) | ||
end | end | ||
function p.getCategoryMembers(frame) | function p.getCategoryMembers(frame) | ||
local categoryName = frame.args | local categoryName = frame.args[1] -- Pass the category name as an argument | ||
local category = mw.title.new("Category:" .. categoryName) | local category = mw.title.new("Category:" .. categoryName) | ||
Line 23: | Line 13: | ||
end | end | ||
local members = | local members = mw.site.categoryMembers("Category:" .. categoryName) | ||
local result = {} | local result = {} | ||
for | for _, member in ipairs(members) do | ||
table.insert(result, | table.insert(result, member.title) -- Collect page titles | ||
end | end | ||
Revision as of 08:22, 22 December 2024
Documentation for this module may be created at Module:RecursiveSelectiveList/doc
local p = {}
function p.main(frame)
return p.getCategoryMembers(frame)
end
function p.getCategoryMembers(frame)
local categoryName = frame.args[1] -- Pass the category name as an argument
local category = mw.title.new("Category:" .. categoryName)
if not category or not category.exists then
return "Category does not exist."
end
local members = mw.site.categoryMembers("Category:" .. categoryName)
local result = {}
for _, member in ipairs(members) do
table.insert(result, member.title) -- Collect page titles
end
return table.concat(result, ", ") -- Return a comma-separated list of page titles
end
return p