Module:MainPageSkinSwitch: Difference between revisions

From IxWiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
local p = {}
function p.detectSkin()
function p.detectSkin()
     local frame = mw.getCurrentFrame()
     local frame = mw.getCurrentFrame()
Line 20: Line 18:
     return skin
     return skin
end
end
function p.getMainPageContent(frame)
    local skin = p.detectSkin()
   
    mw.log('Detected skin: ' .. tostring(skin))
   
    local pageName
    -- Check for Citizen skin
    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)
   
    -- Preprocess the content to parse wiki markup
    return frame:preprocess(content)
end
function p.debugInfo()
    local skin = p.detectSkin()
    local info = "Detected skin: " .. tostring(skin) .. "\n"
    info = info .. "mw.site.stats.skin: " .. tostring(mw.site.stats.skin) .. "\n"
   
    local frame = mw.getCurrentFrame()
    local request = frame:getRequest()
    local cookieData = request:getHeader('Cookie')
    info = info .. "Cookie data: " .. tostring(cookieData) .. "\n"
   
    return info
end
return p

Revision as of 15:52, 1 August 2024

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

function p.detectSkin()
    local frame = mw.getCurrentFrame()
    local request = frame:getRequest()
    local cookieData = request:getHeader('Cookie')
    
    local skin = 'vector'  -- Default to vector
    if cookieData then
        for cookie in cookieData:gmatch('([^;]+)') do
            local name, value = cookie:match('(%s*)(.+)=(.+)')
            if name and name:match('userSkin') then
                skin = value
                break
            end
        end
    end
    
    mw.log('Detected skin from cookie: ' .. tostring(skin))
    return skin
end