Module:MainPageSkinSwitch: Difference between revisions

From IxWiki
Jump to navigation Jump to search
mNo edit summary
Tag: Reverted
mNo edit summary
Tag: Reverted
Line 3: Line 3:
function p.getMainPageContent(frame)
function p.getMainPageContent(frame)
     local currentTitle = mw.title.getCurrentTitle()
     local currentTitle = mw.title.getCurrentTitle()
    local skin = frame.args[1] or mw.site.stats.skin or 'vector'
      
      
     -- Debug output
     -- Simple check for Main_Page
     mw.log('Current page: ' .. currentTitle.fullText)
     if currentTitle.text ~= 'Main_Page' then
    mw.log('Is main page: ' .. tostring(currentTitle.isMainPage))
        return '' -- Return empty string if not on Main_Page
 
     end
    -- Always proceed, removing the main page check for now
     local skin = frame.args[1] or mw.site.stats.skin or 'vector'
      
      
     local pageName
     local pageName
Line 17: Line 16:
         pageName = 'Template:MainPage/Vector'
         pageName = 'Template:MainPage/Vector'
     end
     end
   
    mw.log('Attempting to load page: ' .. pageName)
      
      
     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 28: Line 24:
     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 40: Line 33:
     local currentTitle = mw.title.getCurrentTitle()
     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 = "Current page: " .. currentTitle.text .. "\n"
     info = info .. "Is main page: " .. tostring(currentTitle.isMainPage) .. "\n"
     info = info .. "Is Main_Page: " .. tostring(currentTitle.text == 'Main_Page') .. "\n"
     info = info .. "Detected skin: " .. tostring(skin) .. "\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"

Revision as of 17:25, 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()
    local skin = frame.args[1] or mw.site.stats.skin or 'vector'
    
    -- Simple check for Main_Page
    if currentTitle.text ~= 'Main_Page' then
        return '' -- Return empty string if not on Main_Page
    end
    
    local pageName
    if skin == 'citizen' then
        pageName = 'Template:MainPage/Citizen'
    else
        pageName = 'Template:MainPage/Vector'
    end
    
    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'
    local info = "Current page: " .. currentTitle.text .. "\n"
    info = info .. "Is Main_Page: " .. tostring(currentTitle.text == 'Main_Page') .. "\n"
    info = info .. "Detected skin: " .. tostring(skin) .. "\n"
    info = info .. "mw.site.stats.skin: " .. tostring(mw.site.stats.skin) .. "\n"
    return info
end

return p