Module:MainPageSkinSwitch: Difference between revisions

From IxWiki
Jump to navigation Jump to search
mNo edit summary
Tag: Reverted
mNo edit summary
 
(8 intermediate revisions by the same user not shown)
Line 2: Line 2:


function p.getMainPageContent(frame)
function p.getMainPageContent(frame)
    local currentTitle = mw.title.getCurrentTitle()
   
    -- Debug output
    mw.log('Current page: ' .. currentTitle.fullText)
    mw.log('Is main page: ' .. tostring(currentTitle.isMainPage))
    -- Always proceed, removing the main page check for now
     local skin = frame.args[1] or mw.site.stats.skin or 'vector'
     local skin = frame.args[1] or mw.site.stats.skin or 'vector'
      
      
Line 15: Line 8:
         pageName = 'Template:MainPage/Citizen'
         pageName = 'Template:MainPage/Citizen'
     else
     else
         pageName = 'Template:MainPage/Vector'
         pageName = 'Template:Home'
     end
     end
      
      
Line 38: Line 31:


function p.debugInfo(frame)
function p.debugInfo(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 info = "Current page: " .. currentTitle.fullText .. "\n"
     local info = "Detected skin: " .. tostring(skin) .. "\n"
    info = info .. "Is main page: " .. tostring(currentTitle.isMainPage) .. "\n"
    info = 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"
     return info
     return info

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