Module:RecursiveSelectiveList: Difference between revisions
EnWikiAdmin (talk | contribs) No edit summary |
EnWikiAdmin (talk | contribs) No edit summary Tag: Reverted |
||
Line 5: | Line 5: | ||
-- Retrieve parameters from the template invocation | -- Retrieve parameters from the template invocation | ||
local args = frame.args | local args = frame.args | ||
local | local categoryName = args.categoryName | ||
-- Check if ' | -- Check if 'categoryName' is provided | ||
if not | if not categoryName or categoryName == "" then | ||
return "Error: ' | return "Error: 'categoryName' parameter is missing or empty." | ||
end | end | ||
-- Fetch | -- Fetch pages in the category | ||
local | local category = mw.site.getCategory(categoryName) | ||
if not category then | |||
return "Error: Category '" .. categoryName .. "' does not exist." | |||
end | |||
-- | -- Retrieve the list of pages | ||
local pages = {} | |||
for page in category:members() do | |||
table.insert(pages, "* [[" .. page.title .. "]]") | |||
end | end | ||
return | -- Return the list as a formatted string | ||
return table.concat(pages, "\n") | |||
end | end | ||
return p | return p |
Revision as of 07:17, 22 December 2024
Documentation for this module may be created at Module:RecursiveSelectiveList/doc
local p = {}
local mw = require('mw')
function p.main(frame)
-- Retrieve parameters from the template invocation
local args = frame.args
local categoryName = args.categoryName
-- Check if 'categoryName' is provided
if not categoryName or categoryName == "" then
return "Error: 'categoryName' parameter is missing or empty."
end
-- Fetch pages in the category
local category = mw.site.getCategory(categoryName)
if not category then
return "Error: Category '" .. categoryName .. "' does not exist."
end
-- Retrieve the list of pages
local pages = {}
for page in category:members() do
table.insert(pages, "* [[" .. page.title .. "]]")
end
-- Return the list as a formatted string
return table.concat(pages, "\n")
end
return p