Module:RecursiveSelectiveList: Difference between revisions

From Ikwipedia
No edit summary
No edit summary
Line 3: Line 3:


function p.main(frame)
function p.main(frame)
    -- Retrieve parameters from the template invocation
     local categoryName = "Category:" .. frame.args.categoryName
    local args = frame.args
     local content = mw.title.new(categoryName):getContent()
     local categoryName = args.categoryName
     return content or "The category '" .. categoryName .. "' does not exist or has no content."
 
    -- 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
end


return p
return p

Revision as of 08:14, 22 December 2024

Documentation for this module may be created at Module:RecursiveSelectiveList/doc

local p = {}
local mw = require('mw')

function p.main(frame)
    local categoryName = "Category:" .. frame.args.categoryName
    local content = mw.title.new(categoryName):getContent()
    return content or "The category '" .. categoryName .. "' does not exist or has no content."
end

return p