Module:RecursiveSelectiveList: Difference between revisions

From Ikwipedia
No edit summary
No edit summary
Line 1: Line 1:
local categoryName = frame.args.categoryName or "Category:Example"
local p = {}
return "Debug: Attempting to fetch members for " .. categoryName
local mw = require('mw')
 
function p.debug(frame)
    local html = mw.html.create("div"):addClass("debug-output")
 
    -- Retrieve parameters from the template invocation
    local args = frame.args
    html:tag("h3"):wikitext("Debugging Information")
 
    -- Add each parameter as a key-value pair
    html:tag("h4"):wikitext("Template Arguments:")
    local argsList = html:tag("ul")
    for key, value in pairs(args) do
        argsList:tag("li"):wikitext(key .. " = " .. (value or "nil"))
    end
 
    -- Example of debugging mw.title.new
    local pageName = args.pageName or "No pageName provided"
    html:tag("h4"):wikitext("Page Name Provided:")
    html:tag("p"):wikitext(pageName)
 
    if pageName ~= "No pageName provided" then
        local titleObject = mw.title.new(pageName)
        if titleObject then
            html:tag("h4"):wikitext("Title Object Debugging:")
            local titleList = html:tag("ul")
            titleList:tag("li"):wikitext("Full Text: " .. (titleObject.fullText or "nil"))
            titleList:tag("li"):wikitext("Namespace: " .. (titleObject.namespace or "nil"))
            titleList:tag("li"):wikitext("ID: " .. (titleObject.id or "nil"))
 
            -- Try to get content
            local pageContent = titleObject:getContent()
            if pageContent then
                html:tag("h4"):wikitext("Page Content:")
                html:tag("pre"):wikitext(pageContent)
            else
                html:tag("h4"):wikitext("Page Content:"):tag("p"):wikitext("No content found or page does not exist.")
            end
        else
            html:tag("h4"):wikitext("Title Object:"):tag("p"):wikitext("Failed to create title object for page name.")
        end
    end
 
    return tostring(html)
end
 
return p

Revision as of 07:30, 22 December 2024

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

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

function p.debug(frame)
    local html = mw.html.create("div"):addClass("debug-output")

    -- Retrieve parameters from the template invocation
    local args = frame.args
    html:tag("h3"):wikitext("Debugging Information")

    -- Add each parameter as a key-value pair
    html:tag("h4"):wikitext("Template Arguments:")
    local argsList = html:tag("ul")
    for key, value in pairs(args) do
        argsList:tag("li"):wikitext(key .. " = " .. (value or "nil"))
    end

    -- Example of debugging mw.title.new
    local pageName = args.pageName or "No pageName provided"
    html:tag("h4"):wikitext("Page Name Provided:")
    html:tag("p"):wikitext(pageName)

    if pageName ~= "No pageName provided" then
        local titleObject = mw.title.new(pageName)
        if titleObject then
            html:tag("h4"):wikitext("Title Object Debugging:")
            local titleList = html:tag("ul")
            titleList:tag("li"):wikitext("Full Text: " .. (titleObject.fullText or "nil"))
            titleList:tag("li"):wikitext("Namespace: " .. (titleObject.namespace or "nil"))
            titleList:tag("li"):wikitext("ID: " .. (titleObject.id or "nil"))

            -- Try to get content
            local pageContent = titleObject:getContent()
            if pageContent then
                html:tag("h4"):wikitext("Page Content:")
                html:tag("pre"):wikitext(pageContent)
            else
                html:tag("h4"):wikitext("Page Content:"):tag("p"):wikitext("No content found or page does not exist.")
            end
        else
            html:tag("h4"):wikitext("Title Object:"):tag("p"):wikitext("Failed to create title object for page name.")
        end
    end

    return tostring(html)
end

return p