Module:RecursiveSelectiveList: Difference between revisions
EnWikiAdmin (talk | contribs) No edit summary |
EnWikiAdmin (talk | contribs) No edit summary |
||
Line 2: | Line 2: | ||
local mw = require('mw') | local mw = require('mw') | ||
function p.main(frame) | function p.main(frame) | ||
-- Retrieve the template | -- Retrieve parameters from the template invocation | ||
local args = frame.args | local args = frame.args | ||
local categoryName = args.categoryName | local categoryName = args.categoryName | ||
Line 20: | Line 17: | ||
end | end | ||
-- | -- Fetch the category page content | ||
local | local categoryPage = mw.title.new(categoryName) | ||
if not categoryPage then | |||
return "Error: Invalid category name '" .. categoryName .. "'." | |||
if not | |||
return | |||
end | end | ||
local content = categoryPage:getContent() | |||
-- Handle cases where the page has no content | |||
if not content then | |||
-- | return "The category '" .. categoryName .. "' does not exist or has no content." | ||
end | end | ||
-- | -- Return the raw content of the category page | ||
return "Raw content of category '" .. categoryName .. "':\n\n" .. content | |||
end | end | ||
return p | return p |
Revision as of 07:59, 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
-- Ensure the category name starts with "Category:"
if not categoryName:match("^Category:") then
categoryName = "Category:" .. categoryName
end
-- Fetch the category page content
local categoryPage = mw.title.new(categoryName)
if not categoryPage then
return "Error: Invalid category name '" .. categoryName .. "'."
end
local content = categoryPage:getContent()
-- Handle cases where the page has no content
if not content then
return "The category '" .. categoryName .. "' does not exist or has no content."
end
-- Return the raw content of the category page
return "Raw content of category '" .. categoryName .. "':\n\n" .. content
end
return p