Module:MainPageSkinSwitch: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function p.detectSkin( | function p.detectSkin() | ||
local skin = | local skin = mw.site.stats.skin or 'vector' | ||
-- Check for useskin parameter in the URL | |||
local frame = mw.getCurrentFrame() | |||
if frame then | |||
local parent = frame:getParent() | |||
if parent then | |||
local urlParam = parent.args['useskin'] | |||
if urlParam then | |||
skin = urlParam | |||
end | |||
end | |||
end | |||
mw.log('Detected skin: ' .. tostring(skin)) | mw.log('Detected skin: ' .. tostring(skin)) | ||
return skin | return skin | ||
Line 8: | Line 19: | ||
function p.getMainPageContent(frame) | function p.getMainPageContent(frame) | ||
local skin = p.detectSkin( | local skin = p.detectSkin() | ||
local pageName | local pageName | ||
Line 38: | Line 49: | ||
end | end | ||
function p.debugInfo( | function p.debugInfo() | ||
local skin = p.detectSkin( | local skin = p.detectSkin() | ||
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" |
Revision as of 16:13, 1 August 2024
Documentation for this module may be created at Module:MainPageSkinSwitch/doc
local p = {}
function p.detectSkin()
local skin = mw.site.stats.skin or 'vector'
-- Check for useskin parameter in the URL
local frame = mw.getCurrentFrame()
if frame then
local parent = frame:getParent()
if parent then
local urlParam = parent.args['useskin']
if urlParam then
skin = urlParam
end
end
end
mw.log('Detected skin: ' .. tostring(skin))
return skin
end
function p.getMainPageContent(frame)
local skin = p.detectSkin()
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"
return info
end
return p