Module:RecursiveSelectiveList: Difference between revisions
EnWikiAdmin (talk | contribs) No edit summary |
EnWikiAdmin (talk | contribs) No edit summary |
||
Line 9: | Line 9: | ||
end | end | ||
-- Fetch category members | -- Fetch category members | ||
local categoryTitle = "Category:" .. categoryName | local categoryTitle = "Category:" .. categoryName | ||
local | local categoryPage = mw.title.new(categoryTitle) | ||
if not | if not categoryPage or not categoryPage.exists then | ||
return "Error: Unable to fetch category members. | return "Error: Category does not exist." | ||
end | |||
local members = categoryPage:members() | |||
if not members then | |||
return "Error: Unable to fetch category members." | |||
end | end | ||
-- Generate a bulleted list of members | -- Generate a bulleted list of members | ||
local output = {} | local output = {} | ||
for _, member in ipairs( | for _, member in ipairs(members) do | ||
table.insert(output, "* [[" .. member. | table.insert(output, "* [[" .. member.prefixedText .. "]]") | ||
end | end | ||
Revision as of 06:51, 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
local categoryTitle = "Category:" .. categoryName
local categoryPage = mw.title.new(categoryTitle)
if not categoryPage or not categoryPage.exists then
return "Error: Category does not exist."
end
local members = categoryPage:members()
if not members then
return "Error: Unable to fetch category members."
end
-- Generate a bulleted list of members
local output = {}
for _, member in ipairs(members) do
table.insert(output, "* [[" .. member.prefixedText .. "]]")
end
if #output == 0 then
return "No pages found in the category."
end
return table.concat(output, "\n")
end
return p