Module:MainPageSkinSwitch: Difference between revisions

From IxWiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(20 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
function p.detectSkin(frame)
    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


function p.getMainPageContent(frame)
function p.getMainPageContent(frame)
     local skin = p.detectSkin(frame)
     local skin = frame.args[1] or mw.site.stats.skin or 'vector'
   
    mw.log('Detected skin: ' .. tostring(skin))
      
      
     local pageName
     local pageName
    -- Check for Citizen skin
     if skin == 'citizen' then
     if skin == 'citizen' then
         pageName = 'Template:MainPage/Citizen'
         pageName = 'Template:MainPage/Citizen'
     else
     else
         pageName = 'Template:MainPage/Vector'
         pageName = 'Template:Home'
     end
     end
      
      
Line 49: Line 27:
     mw.log('Successfully retrieved content from: ' .. pageName)
     mw.log('Successfully retrieved content from: ' .. pageName)
      
      
    -- Preprocess the content to parse wiki markup
     return frame:preprocess(content)
     return frame:preprocess(content)
end
end


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


return p
return p

Latest revision as of 19:07, 3 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:Home'
    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