Module:MainPageSkinSwitch: Difference between revisions

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


function p.getMainPageContent(frame)
function p.getMainPageContent(frame)
     local skin = frame.args[1] or mw.site.stats.skin or 'vector'
     local currentTitle = mw.title.getCurrentTitle()
      
      
     local pageName
     -- Check if we're on the main page
     if skin == 'citizen' then
     if currentTitle.isMainPage then
         pageName = 'Template:MainPage/Citizen'
        local vectorContent = p.getSkinContent(frame, 'vector')
        local citizenContent = p.getSkinContent(frame, 'citizen')
       
         return '<div id="vector-content" class="skin-content">' .. vectorContent .. '</div>' ..
              '<div id="citizen-content" class="skin-content" style="display:none;">' .. citizenContent .. '</div>'
     else
     else
         pageName = 'Template:MainPage/Vector'
         -- Return empty string or some default content for non-main pages
        return ''
     end
     end
   
end
    mw.log('Attempting to load page: ' .. pageName)
 
function p.getSkinContent(frame, skin)
    local pageName = 'Template:MainPage/' .. skin:gsub("^%l", string.upper)
      
      
     local page = mw.title.new(pageName)
     local page = mw.title.new(pageName)
     if not page then
     if not page then
        mw.log('Page does not exist: ' .. pageName)
         return "Error: Page '" .. pageName .. "' does not exist."
         return "Error: Page '" .. pageName .. "' does not exist."
     end
     end
Line 21: Line 27:
     local content = page:getContent()
     local content = page:getContent()
     if not content then
     if not content then
        mw.log('Unable to retrieve content from: ' .. pageName)
         return "Error: Unable to retrieve content from '" .. pageName .. "'."
         return "Error: Unable to retrieve content from '" .. pageName .. "'."
     end
     end
   
    mw.log('Successfully retrieved content from: ' .. pageName)
      
      
     return frame:preprocess(content)
     return frame:preprocess(content)
Line 31: Line 34:


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 = "Detected skin: " .. tostring(skin) .. "\n"
      
     info = info .. "mw.site.stats.skin: " .. tostring(mw.site.stats.skin) .. "\n"
    if currentTitle.isMainPage then
     return info
        return "Current skin: " .. skin .. " (Main Page)"
     else
        return "Not on Main Page"
     end
end
end


return p
return p

Revision as of 16:46, 1 August 2024

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

local p = {}

function p.getMainPageContent(frame)
    local currentTitle = mw.title.getCurrentTitle()
    
    -- Check if we're on the main page
    if currentTitle.isMainPage then
        local vectorContent = p.getSkinContent(frame, 'vector')
        local citizenContent = p.getSkinContent(frame, 'citizen')
        
        return '<div id="vector-content" class="skin-content">' .. vectorContent .. '</div>' ..
               '<div id="citizen-content" class="skin-content" style="display:none;">' .. citizenContent .. '</div>'
    else
        -- Return empty string or some default content for non-main pages
        return ''
    end
end

function p.getSkinContent(frame, skin)
    local pageName = 'Template:MainPage/' .. skin:gsub("^%l", string.upper)
    
    local page = mw.title.new(pageName)
    if not page then
        return "Error: Page '" .. pageName .. "' does not exist."
    end
    
    local content = page:getContent()
    if not content then
        return "Error: Unable to retrieve content from '" .. pageName .. "'."
    end
    
    return frame:preprocess(content)
end

function p.debugInfo(frame)
    local currentTitle = mw.title.getCurrentTitle()
    local skin = frame.args[1] or mw.site.stats.skin or 'vector'
    
    if currentTitle.isMainPage then
        return "Current skin: " .. skin .. " (Main Page)"
    else
        return "Not on Main Page"
    end
end

return p