Module:MainPageSkinSwitch

From IxWiki
Revision as of 17:31, 1 August 2024 by Heku (talk | contribs)
Jump to navigation Jump to search

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

local p = {}

function p.getMainPageContent(frame)
    local currentTitle = mw.title.getCurrentTitle()
    local skin = frame.args[1] or mw.site.stats.skin or 'vector'
    
    local debug = "Function: getMainPageContent\n"
    debug = debug .. "Current page: " .. currentTitle.text .. "\n"
    debug = debug .. "Provided skin: " .. tostring(skin) .. "\n"
    debug = debug .. "mw.site.stats.skin: " .. tostring(mw.site.stats.skin) .. "\n"
    
    if currentTitle.text ~= 'Main Page' then
        debug = debug .. "Not on Main Page, returning empty string\n"
        return debug
    end
    
    local pageName = 'Template:MainPage/' .. (skin == 'citizen' and 'Citizen' or 'Vector')
    debug = debug .. "Attempting to load: " .. pageName .. "\n"
    
    local page = mw.title.new(pageName)
    if not page then
        debug = debug .. "Error: Page '" .. pageName .. "' does not exist.\n"
        return debug
    end
    
    local content = page:getContent()
    if not content then
        debug = debug .. "Error: Unable to retrieve content from '" .. pageName .. "'.\n"
        return debug
    end
    
    debug = debug .. "Content retrieved successfully.\n"
    
    return frame:preprocess(content) .. "\n\n<!-- Debug Info:\n" .. debug .. "-->"
end

function p.debugInfo(frame)
    return p.getMainPageContent(frame)
end

return p