Module:RecursiveSelectiveList: Difference between revisions
EnWikiAdmin (talk | contribs) No edit summary |
EnWikiAdmin (talk | contribs) No edit summary |
||
Line 2: | Line 2: | ||
function p.main(frame) | function p.main(frame) | ||
local categoryName = frame.args.categoryName or "Category: | local categoryName = frame.args.categoryName or "Category:Example" -- Default category | ||
local limit = tonumber(frame.args.limit) or 10 -- Default limit | local limit = tonumber(frame.args.limit) or 10 -- Default limit | ||
local category = mw.title.new(categoryName) | local category = mw.title.new(categoryName) | ||
if not category or not category.exists then | if not category or not category.exists then | ||
return "Error: | return "Error: The specified category does not exist." | ||
end | end | ||
local members = category:members() | |||
local | local result = {} | ||
local | |||
local count = 0 | local count = 0 | ||
for page in | for page in members do | ||
table.insert( | table.insert(result, "* [[" .. page.title .. "]]") | ||
count = count + 1 | count = count + 1 | ||
if count >= limit then | if count >= limit then | ||
Line 24: | Line 22: | ||
end | end | ||
return table.concat(result, "\n") | |||
return table.concat( | |||
end | end | ||
return p | return p |
Revision as of 07:25, 22 December 2024
Documentation for this module may be created at Module:RecursiveSelectiveList/doc
local p = {}
function p.main(frame)
local categoryName = frame.args.categoryName or "Category:Example" -- Default category
local limit = tonumber(frame.args.limit) or 10 -- Default limit
local category = mw.title.new(categoryName)
if not category or not category.exists then
return "Error: The specified category does not exist."
end
local members = category:members()
local result = {}
local count = 0
for page in members do
table.insert(result, "* [[" .. page.title .. "]]")
count = count + 1
if count >= limit then
break
end
end
return table.concat(result, "\n")
end
return p