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)
    -- Get all arguments passed to the module
     local args = frame:getParent().args or {}
     local args = frame:getParent().args
   
    -- Normalize parameter name case (if there's a case mismatch)
    local pageName = args["pageName"] or args["PageName"] or args["pagename"]


     -- Debug: Display all arguments
     -- Check if pageName is missing or empty
     local debugInfo = "Arguments passed:\n"
     if not pageName or pageName == "" then
    for key, value in pairs(args) do
         return "Error: 'pageName' parameter is missing or empty."
         debugInfo = debugInfo .. key .. " = " .. (value or "nil") .. "\n"
     end
     end


     return debugInfo -- Return the debug information
     -- Fetch page content
    local pageContent = mw.title.new(pageName):getContent()
 
    if not pageContent then
        return "Error: The page '" .. pageName .. "' does not exist or has no content."
    end
 
    return pageContent
end
end


return p
return p

Revision as of 07:13, 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 args = frame:getParent().args or {}
    
    -- Normalize parameter name case (if there's a case mismatch)
    local pageName = args["pageName"] or args["PageName"] or args["pagename"]

    -- Check if pageName is missing or empty
    if not pageName or pageName == "" then
        return "Error: 'pageName' parameter is missing or empty."
    end

    -- Fetch page content
    local pageContent = mw.title.new(pageName):getContent()

    if not pageContent then
        return "Error: The page '" .. pageName .. "' does not exist or has no content."
    end

    return pageContent
end

return p