Module:RecursiveSelectiveList: Difference between revisions

From Ikwipedia
No edit summary
No edit summary
Line 2: Line 2:
local mw = require('mw')
local mw = require('mw')


-- Function to fetch content from a specified page
function p.main(frame)
function p.getPageContent(pageTitle)
     -- Retrieve parameters from the template invocation
     -- Check if a page title is provided
     local args = frame:getParent().args
     if not pageTitle or pageTitle == "" then
    local pageName = args.pageName or "Main Page" -- Default to "Main Page" if no pageName is provided
        return "Error: No page title provided."
    end


     -- Use the MediaWiki API to fetch the page content
     -- Use the MediaWiki API to fetch the content of the page
     local status, content = pcall(function()
     local pageContent = mw.title.new(pageName):getContent()
        return mw.title.new(pageTitle):getContent()
    end)


     -- Handle errors or return content
     -- Handle cases where the page might not exist
     if not status or not content then
     if not pageContent then
         return "Error: Unable to fetch content for page '" .. pageTitle .. "'."
         return "Error: The page '" .. pageName .. "' does not exist or has no content."
     end
     end


     return content or "Error: Page content is empty."
    -- Optionally process the content, here simply returning it
     return pageContent
end
end


-- Function to be invoked from templa
return p

Revision as of 07:06, 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:getParent().args
    local pageName = args.pageName or "Main Page" -- Default to "Main Page" if no pageName is provided

    -- Use the MediaWiki API to fetch the content of the page
    local pageContent = mw.title.new(pageName):getContent()

    -- Handle cases where the page might not exist
    if not pageContent then
        return "Error: The page '" .. pageName .. "' does not exist or has no content."
    end

    -- Optionally process the content, here simply returning it
    return pageContent
end

return p