Bureaucrats, Moderators (CommentStreams), Interface administrators, Push subscription managers, Suppressors, Administrators
13,382
edits
m (4 revisions imported) |
(try fix) |
||
| Line 1: | Line 1: | ||
-- Module:Main_page | -- Module:Main_page | ||
-- IMProved Main Page framework for | -- IMProved Main Page framework – FIXED for direct use on Main Page | ||
-- | -- Works on wiki.gg, Fandom, and any MediaWiki | ||
local p = {} | local p = {} | ||
function p.main(frame) | function p.main(frame) | ||
local | local parent = frame:getParent() | ||
local args = parent and parent.args or frame.args | |||
local content = {} | local content = {} | ||
local header = args.header or '' | local header = args.header or '' | ||
| Line 14: | Line 14: | ||
local below = args.below or '' | local below = args.below or '' | ||
-- Collect | -- Collect content from numbered args (content1, content2, ...) | ||
for k, v in pairs(args) do | for k, v in pairs(args) do | ||
if type(k) == 'string' and k:match('^content%d+$') then | if type(k) == 'string' and k:match('^content%d+$') then | ||
| Line 21: | Line 21: | ||
end | end | ||
-- Fallback: use | -- Fallback: if no content args, use direct wikitext between {{Main_page}} and end | ||
if #content == 0 and parent then | |||
local fullText = mw.getCurrentFrame():getParent():getTitle() == 'Main Page' | |||
and mw.getCurrentFrame():preprocess('{{SUBPAGENAME}}') -- not used | |||
local raw = parent:getContent() | |||
if raw then | |||
table.insert(content, raw) | |||
end | |||
end | |||
-- If still empty, use frame expansion (safe fallback) | |||
if #content == 0 then | if #content == 0 then | ||
content = {frame:getParent(): | local expanded = frame:expandTemplate{ title = 'void' } -- dummy | ||
content = {frame:getParent() and frame:getParent():preprocess() or ''} | |||
end | end | ||
-- Build HTML | |||
local html = mw.html.create() | local html = mw.html.create() | ||
| Line 42: | Line 54: | ||
end | end | ||
-- Main | -- Main container | ||
local container = html:tag('div') | local container = html:tag('div') | ||
:addClass('mp-container') | :addClass('mp-container') | ||
:addClass(bodyclass) | :addClass(bodyclass) | ||
:css( | :css({ | ||
display = 'grid', | |||
gap = '1.5rem', | |||
['grid-template-columns'] = 'repeat(auto-fit, minmax(280px, 1fr))', | |||
margin = '1rem auto', | |||
['max-width'] = '1600px', | |||
padding = '0 1rem' | |||
}) | |||
-- Add each box | |||
for _, box in ipairs(content) do | for _, box in ipairs(content) do | ||
container:wikitext(box) | if box and box ~= '' then | ||
container:wikitext(box) | |||
end | |||
end | end | ||