Module:MainPageSkinSwitch: Difference between revisions

From IxWiki
Jump to navigation Jump to search
mNo edit summary
Tag: Reverted
mNo edit summary
Tag: Manual revert
Line 2: Line 2:


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


function p.debugInfo(frame)
function p.debugInfo(frame)
     return p.getMainPageContent(frame)
     local skin = frame.args[1] or mw.site.stats.skin or 'vector'
    local info = "Detected skin: " .. tostring(skin) .. "\n"
    info = info .. "mw.site.stats.skin: " .. tostring(mw.site.stats.skin) .. "\n"
    return info
end
end


return p
return p

Revision as of 17:35, 1 August 2024

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

local p = {}

function p.getMainPageContent(frame)
    local skin = frame.args[1] or mw.site.stats.skin or 'vector'
    
    local pageName
    if skin == 'citizen' then
        pageName = 'Template:MainPage/Citizen'
    else
        pageName = 'Template:MainPage/Vector'
    end
    
    mw.log('Attempting to load page: ' .. pageName)
    
    local page = mw.title.new(pageName)
    if not page then
        mw.log('Page does not exist: ' .. pageName)
        return "Error: Page '" .. pageName .. "' does not exist."
    end
    
    local content = page:getContent()
    if not content then
        mw.log('Unable to retrieve content from: ' .. pageName)
        return "Error: Unable to retrieve content from '" .. pageName .. "'."
    end
    
    mw.log('Successfully retrieved content from: ' .. pageName)
    
    return frame:preprocess(content)
end

function p.debugInfo(frame)
    local skin = frame.args[1] or mw.site.stats.skin or 'vector'
    local info = "Detected skin: " .. tostring(skin) .. "\n"
    info = info .. "mw.site.stats.skin: " .. tostring(mw.site.stats.skin) .. "\n"
    return info
end

return p