Module:RecursiveSelectiveList: Difference between revisions

From Ikwipedia
No edit summary
No edit summary
Tag: Reverted
Line 5: Line 5:
     -- Retrieve parameters from the template invocation
     -- Retrieve parameters from the template invocation
     local args = frame.args
     local args = frame.args
     local pageName = args.pageName
     local categoryName = args.categoryName


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


     -- Fetch content for the specified page
     -- Fetch pages in the category
     local pageContent = mw.title.new(pageName):getContent()
     local category = mw.site.getCategory(categoryName)
    if not category then
        return "Error: Category '" .. categoryName .. "' does not exist."
    end


     -- Handle cases where the page doesn't exist or has no content
     -- Retrieve the list of pages
     if not pageContent then
    local pages = {}
         return "Error: The page '" .. pageName .. "' does not exist or has no content."
     for page in category:members() do
         table.insert(pages, "* [[" .. page.title .. "]]")
     end
     end


     return pageContent
    -- Return the list as a formatted string
     return table.concat(pages, "\n")
end
end


return p
return p

Revision as of 07:17, 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

    -- Fetch pages in the category
    local category = mw.site.getCategory(categoryName)
    if not category then
        return "Error: Category '" .. categoryName .. "' does not exist."
    end

    -- Retrieve the list of pages
    local pages = {}
    for page in category:members() do
        table.insert(pages, "* [[" .. page.title .. "]]")
    end

    -- Return the list as a formatted string
    return table.concat(pages, "\n")
end

return p