Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
The main server is currently down. We are running on a backup server, so editing and search functionality are temporarily disabled. Please check back in a few hours.

Module:Infobox: Difference between revisions

From GameBrew
No edit summary
Tag: Reverted
No edit summary
Tag: Manual revert
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
-- Simple infobox module with enhanced flexibility and cleaner structure
--- Simple infobox module
local p = {}
local p = {}


--- Main function: generates an infobox table
--- Main function
function p.infobox(frame)
function p.infobox( frame )
    -- Retrieve arguments (from template or direct call)
local args
    local args = (frame.args and frame.args) or (frame:getParent() and frame:getParent().args) or {}
if frame == mw.getCurrentFrame() then
args = frame:getParent().args
else
args = frame
end
local infobox = mw.html.create('table'):addClass('infobox')
--top infobox ads
local div = mw.html.create('div')
div:attr('id', 'Ads-InfoboxTop')
infobox:node(div)


    -- Create the container table
-- Title
    local infobox = mw.html.create('table'):addClass('infobox')
local title = args.title
if not title or title == '' then title = mw.title.getCurrentTitle().text end
infobox:tag('tr'):tag('th'):addClass('infobox-title'):attr('scope','col'):attr('colspan',2):wikitext(title)
-- Image
local image = args.image
if image and image ~= '' then
if image:sub(1,2) ~= '[[' then
if not image:find(':') then
image = 'File:' .. image
end
image = '[[' .. image .. '|' .. ('300px') .. ']]'
end
local imgcell = infobox:tag('tr'):tag('td'):addClass('infobox-image')
:attr('colspan',2):wikitext(image)
local caption = args.imagecaption
if caption and caption ~= '' then
imgcell:wikitext("<br />''" .. caption .. "''")
end
end
-- Description
          local description = args.description
          if not description or description == '' then description = mw.title.getCurrentTitle().text end


    -- Top ad slot
-- Rows
    infobox:node(
for i = 1, 30 do
        mw.html.create('div')
local header = args['header' .. i]; if header == '' then header = nil end
            :attr('id', 'Ads-InfoboxTop')
local label = args['label' .. i]; if label == '' then label = nil end
    )
local data = args['data' .. i]; if data == '' then data = nil end
 
    -- Title row (defaults to page title)
if header then
    local title = args.title or mw.title.getCurrentTitle().text
infobox:tag('tr')
    infobox:tag('tr')
:tag('th'):addClass('infobox-header'):attr('scope','col'):attr('colspan',2):wikitext(header)
        :tag('th')
end
            :addClass('infobox-title')
if data then
            :attr{scope = 'col', colspan = '2'}
if label then
            :wikitext(title)
infobox:tag('tr')
 
:tag('th'):attr('scope','row'):addClass('infobox-label'):wikitext(label):done()
    -- Optional description row
:tag('td'):addClass('infobox-data'):wikitext(data)
    if args.description and args.description ~= '' then
else
        infobox:tag('tr')
infobox:tag('tr')
            :tag('td')
:tag('td'):addClass('infobox-data'):attr('colspan',2)
                :addClass('infobox-description')
:css('text-align','center'):wikitext(data)
                :attr('colspan', 2)
end
                :wikitext(args.description)
end
    end
end
 
    -- Image block (with optional width and caption)
-- Below
    if args.image and args.image ~= '' then
local below = args.below
        local img = args.image
if below and below ~= '' then
        -- Wrap in File: namespace if needed
infobox:tag('tr'):tag('td'):addClass('infobox-below'):attr('colspan',2):wikitext(below)
        if not img:match('%[%[') then
end
            if not img:find(':') then img = 'File:' .. img end
            local width = args.imagewidth or '300px'
return infobox
            img = string.format('[[%s|%s]]', img, width)
        end
        local imgCell = infobox:tag('tr')
            :tag('td')
                :addClass('infobox-image')
                :attr('colspan', 2)
                :wikitext(img)
        if args.imagecaption and args.imagecaption ~= '' then
            imgCell:tag('div')
                :addClass('infobox-caption')
                :wikitext(args.imagecaption)
        end
    end
 
    -- Data rows: uses args.rows to limit iterations or defaults to 30
    local maxRows = tonumber(args.rows or 30)
    for i = 1, maxRows do
        local header = args['header' .. i]
        if header and header ~= '' then
            infobox:tag('tr')
                :tag('th')
                    :addClass('infobox-header')
                    :attr{scope = 'col', colspan = '2'}
                    :wikitext(header)
        end
 
        local label = args['label' .. i]
        local data  = args['data'  .. i]
        if data and data ~= '' then
            if label and label ~= '' then
                local row = infobox:tag('tr')
                row:tag('th')
                    :addClass('infobox-label')
                    :attr('scope', 'row')
                    :wikitext(label)
                row:tag('td')
                    :addClass('infobox-data')
                    :wikitext(data)
            else
                infobox:tag('tr')
                    :tag('td')
                        :addClass('infobox-data')
                        :attr{colspan = '2', style = 'text-align:center;'}
                        :wikitext(data)
            end
        end
    end
 
    -- Optional footer row
    if args.below and args.below ~= '' then
        infobox:tag('tr')
            :tag('td')
                :addClass('infobox-below')
                :attr('colspan', 2)
                :wikitext(args.below)
    end
 
    -- Return HTML string
    return tostring(infobox)
end
end
 
return p
return p

Latest revision as of 02:33, 18 April 2025

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

--- Simple infobox module
local p = {}

--- Main function
function p.infobox( frame )
	local args
	if frame == mw.getCurrentFrame() then
		args = frame:getParent().args
	else
		args = frame
	end
 
	local infobox = mw.html.create('table'):addClass('infobox')
 
--top infobox ads
local div = mw.html.create('div')
div:attr('id', 'Ads-InfoboxTop')
infobox:node(div)

	-- Title
	local title = args.title
	if not title or title == '' then title = mw.title.getCurrentTitle().text end
	infobox:tag('tr'):tag('th'):addClass('infobox-title'):attr('scope','col'):attr('colspan',2):wikitext(title)
 
	-- Image
	local image = args.image
	if image and image ~= '' then
		if image:sub(1,2) ~= '[[' then
			if not image:find(':') then
				image = 'File:' .. image	
			end
			image = '[[' .. image .. '|' .. ('300px') .. ']]'
		end
		local imgcell = infobox:tag('tr'):tag('td'):addClass('infobox-image')
			:attr('colspan',2):wikitext(image)
		local caption = args.imagecaption
		if caption and caption ~= '' then
			imgcell:wikitext("<br />''" .. caption .. "''")
		end
	end
	-- Description
           local description = args.description
           if not description or description == '' then description = mw.title.getCurrentTitle().text end

	-- Rows
	for i = 1, 30 do
		local header = args['header' .. i]; if header == '' then header = nil end
		local label = args['label' .. i]; if label == '' then label = nil end
		local data = args['data' .. i]; if data == '' then data = nil end
 
		if header then
			infobox:tag('tr')
				:tag('th'):addClass('infobox-header'):attr('scope','col'):attr('colspan',2):wikitext(header)
		end
		if data then
			if label then
				infobox:tag('tr')
					:tag('th'):attr('scope','row'):addClass('infobox-label'):wikitext(label):done()
					:tag('td'):addClass('infobox-data'):wikitext(data)
			else
				infobox:tag('tr')
					:tag('td'):addClass('infobox-data'):attr('colspan',2)
						:css('text-align','center'):wikitext(data)
			end
		end
	end
 
	-- Below
	local below = args.below
	if below and below ~= '' then
		infobox:tag('tr'):tag('td'):addClass('infobox-below'):attr('colspan',2):wikitext(below)
	end
 
	return infobox
end
 
return p

Advertising: