This documentation is transcluded from Module:InfoboxNew/doc. Changes can be proposed in the talk page.
| Module:InfoboxNew loads styles from Module:InfoboxNew/styles.css. |
| Function list |
|---|
| L 23 — restoreUnderscore L 29 — formatNumber L 47 — getDetailsHTML L 64 — methodtable.tableToCommaList L 77 — methodtable.formatRange L 105 — methodtable.addUnitIfExists L 117 — methodtable.renderMessage L 137 — methodtable.renderImage L 184 — methodtable.renderIndicator L 231 — methodtable.renderHeader L 278 — methodtable.renderSection L 327 — methodtable.renderLinkButton L 364 — methodtable.renderFooter L 371 — isNonEmpty L 427 — methodtable.renderFooterButton L 440 — renderItemIconElement L 452 — renderItemLinkElements L 471 — renderItemTextElements L 489 — methodtable.renderItem L 560 — methodtable.renderInfobox L 570 — renderContent L 577 — renderSnippet L 618 — methodtable.showDescIfDiff L 627 — InfoboxNew.showDescIfDiff L 635 — InfoboxNew.new L 669 — InfoboxNew.fromArgs |
| Parts of this Module have been copied from Module:InfoboxNeue of the Star Citizen wiki. |
This module is used by Lua modules to build infobox.
Components
Image
infobox:renderImage( 'Marathon_2026_Infobox_Crop.png' )
Indicator
| Parameter | Description | Type | Status |
|---|---|---|---|
data |
Data of the indicator | string | required |
desc |
Description of the indicator | string | optional |
class |
HTML classes to be added to the indicator | string | optional |
infobox:renderIndicator( {
data = 'Indicator'
} )
Header
| Parameter | Description | Type | Status |
|---|---|---|---|
title |
Title of the infobox | string | required |
subtitle |
Subtitle of the infobox | string | optional |
infobox:renderHeader( {
title = 'Title',
subtitle = 'Subtitle'
} )
Message
This is a shortcut way to create a message wrapped in a section.
| Parameter | Description | Type | Status |
|---|---|---|---|
title |
Title of the message | string | required |
desc |
Description of the message | string | optional |
infobox:renderMessage( {
title = 'Message title',
desc = 'Message description'
} )
Item
| Parameter | Description | Type | Status |
|---|---|---|---|
data |
Data of the item | string | required |
label |
Label of the item | string | optional |
desc |
Description of the item | string | optional |
row |
Whether to display the item in a row | boolean | optional |
spacebetween |
Whether to put space between elements in the item | boolean | optional |
colspan |
Number of columns that the item spans | int | optional |
infobox:renderItem( {
label = 'Item label',
data = 'Item data'
} )
Section
This is used to wrap items into a section.
| Parameter | Description | Type | Status |
|---|---|---|---|
content |
Content of the section | string | required |
title |
Title of the section | string | optional |
subtitle |
Subtitle of the section | string | optional |
col |
Number of columns in the section | int | optional |
class |
HTML classes to be added to the section | string | optional |
contentClass |
HTML classes to be added to the sectionContent | string | optional |
infobox:renderSection( {
title = 'Section title',
content = table.concat( sectionTable ),
col = 3
} )
Layout
Row
Row layout
This is an example of the row layout.
Bacon
Good
Pancetta
Great
Prosciutto
Wonderful
-- Create items
sectionTable = {
infobox:renderItem( {
label = 'Bacon',
data = 'Good',
row = true,
spacebetween = true
} ),
infobox:renderItem( {
label = 'Pancetta',
data = 'Great',
row = true,
spacebetween = true
} ),
infobox:renderItem( {
label = 'Prosciutto',
data = 'Wonderful',
row = true,
spacebetween = true
} )
}
-- Create section with items
infobox:renderSection( {
title = 'Row layout',
subtitle = 'This is an example of the row layout.',
content = table.concat( sectionTable )
} )
List
List layout
This is an example of the list layout.
Bacon is good
Bacon ipsum dolor amet burgdoggen boudin spare ribs pork pork chop drumstick beef. Jowl turkey pork, kevin shankle shank shoulder.
Pancetta is great
Kevin pig fatback, alcatra pancetta sirloin venison tri-tip shankle kielbasa meatloaf spare ribs beef. Corned beef salami kielbasa tenderloin swine spare ribs andouille.
Prosciutto is wonderful
Venison chicken meatloaf, ground round swine short ribs shankle short loin tenderloin jerky capicola. Prosciutto venison sirloin beef brisket pancetta.
-- Create items
sectionTable = {
infobox:renderItem( {
data = 'Bacon is good',
desc = 'Bacon ipsum dolor amet burgdoggen boudin spare ribs pork pork chop drumstick beef. Jowl turkey pork, kevin shankle shank shoulder. ',
} ),
infobox:renderItem( {
data = 'Pancetta is great',
desc = 'Kevin pig fatback, alcatra pancetta sirloin venison tri-tip shankle kielbasa meatloaf spare ribs beef. Corned beef salami kielbasa tenderloin swine spare ribs andouille.',
} ),
infobox:renderItem( {
data = 'Prosciutto is wonderful',
desc = 'Venison chicken meatloaf, ground round swine short ribs shankle short loin tenderloin jerky capicola. Prosciutto venison sirloin beef brisket pancetta.',
} )
}
-- Create section with items
infobox:renderSection( {
title = 'List layout',
subtitle = 'This is an example of the list layout.',
content = table.concat( sectionTable )
} )
Grid
2 col grid layout
This is an example of the two column grid layout.
Bacon
Good
Pancetta
Great
Prosciutto
Wonderful
Capicola
Delightful
3 col grid layout
This is an example of the three column grid layout.
Bacon
Good
Pancetta
Great
Prosciutto
Wonderful
Capicola
Delightful
4 col grid layout
This is an example of the four column grid layout.
Bacon
Good
Pancetta
Great
Prosciutto
Wonderful
Capicola
Delightful
-- Create items
sectionTable = {
infobox:renderItem( {
label = 'Bacon',
data = 'Good'
} ),
infobox:renderItem( {
label = 'Pancetta',
data = 'Great'
} ),
infobox:renderItem( {
label = 'Prosciutto',
data = 'Wonderful'
} ),
infobox:renderItem( {
label = 'Capicola',
data = 'Delightful'
} )
}
-- Create section with items
infobox:renderSection( {
title = '2 col grid layout',
subtitle = 'This is an example of the two column grid layout.',
content = table.concat( sectionTable ),
col = 2
} )
infobox:renderSection( {
title = '3 col grid layout',
subtitle = 'This is an example of the three column grid layout.',
content = table.concat( sectionTable ),
col = 3
} )
infobox:renderSection( {
title = '4 col grid layout',
subtitle = 'This is an example of the four column grid layout.',
content = table.concat( sectionTable ),
col = 4
} )
require( 'strict' )
local InfoboxNew = {}
local metatable = {}
local methodtable = {}
local libraryUtil = require( 'libraryUtil' )
local checkType = libraryUtil.checkType
local checkTypeMulti = libraryUtil.checkTypeMulti
metatable.__index = methodtable
metatable.__tostring = function ( self )
return tostring( self:renderInfobox() )
end
--- Helper function to restore underscore from space
--- so that it does not screw up the external link wikitext syntax
--- For some reason SMW property converts underscore into space
--- mw.uri.encode can't be used on full URL
local function restoreUnderscore( s )
return s:gsub( ' ', '%%5F' )
end
--- Helper function to format string to number with separators
--- It is usually use to re-format raw number from SMW into more readable format
local function formatNumber( s )
local lang = mw.getContentLanguage()
if s == nil then
return
end
if type( s ) ~= 'number' then
s = tonumber( s )
end
if type( s ) == 'number' then
return lang:formatNum( s )
end
return s
end
-- TODO: Perhaps we should turn this into another module
local function getDetailsHTML( data, frame )
local details = frame:extensionTag {
name = 'div',
content = data.details.content,
args = {
class = data.details.class,
open = true
}
}
return details
end
--- Put table values into a comma-separated list
---
--- @param data table
--- @return string
function methodtable.tableToCommaList( data )
if type( data ) == 'table' then
return table.concat( data, ', ' )
else
return data
end
end
--- Show range if value1 and value2 are different
---
--- @param s1 string|nil
--- @param s2 string|nil
--- @return string|nil
function methodtable.formatRange( s1, s2, formatNum )
if s1 == nil and s2 == nil then
return
end
formatNum = formatNum or false
if formatNum then
if s1 then
s1 = formatNumber( s1 )
end
if s2 then
s2 = formatNumber( s2 )
end
end
if s1 and s2 and s1 ~= s2 then
return s1 .. ' – ' .. s2
end
return s1 or s2
end
--- Append unit to the value if exists
---
--- @param s string
--- @param unit string
--- @return string|nil
function methodtable.addUnitIfExists( s, unit )
if s == nil then
return
end
return s .. ' ' .. unit
end
--- Shortcut to return the HTML of the infobox message component as string
---
--- @param data table {title, desc)
--- @return string html
function methodtable.renderMessage( self, data, noInsert )
checkType( 'Module:InfoboxNew.renderMessage', 1, self, 'table' )
checkType( 'Module:InfoboxNew.renderMessage', 2, data, 'table' )
checkType( 'Module:InfoboxNew.renderMessage', 3, noInsert, 'boolean', true )
noInsert = noInsert or false
local item = self:renderSection( { content = self:renderItem( { data = data.title, desc = data.desc } ) }, noInsert )
if not noInsert then
table.insert( self.entries, item )
end
return item
end
--- Return the HTML of the infobox image component as string
---
--- @param filename string
--- @return string html
function methodtable.renderImage( self, filename )
checkType( 'Module:InfoboxNew.renderImage', 1, self, 'table' )
local hasPlaceholderImage = false
if type( filename ) ~= 'string' and self.config.displayPlaceholder == true then
hasPlaceholderImage = true
filename = self.config.placeholderImage
-- Add tracking category for infoboxes using placeholder image
--table.insert( self.categories,
-- string.format( '[[Category:%s]]', '' )
--)
end
if type( filename ) ~= 'string' then
return ''
end
local parts = mw.text.split( filename, ':', true )
if #parts > 1 then
table.remove( parts, 1 )
filename = table.concat( parts, ':' )
end
local html = mw.html.create( 'div' )
:addClass( 'infoboxNew__image' )
:wikitext( string.format( '[[File:%s|400px]]', filename ) )
if hasPlaceholderImage == true then
local icon = mw.html.create( 'span' ):addClass( 'mw-ui-icon-wikimedia-upload' )
-- TODO: Point the Upload link to a specific file name
html:tag( 'div' ):addClass( 'infoboxNew__image-upload' )
:wikitext( string.format( '[[%s|%s]]', 'Special:Upload',
tostring( icon ) .. 'Upload Image' ) )
end
local item = tostring( html )
table.insert( self.entries, item )
return item
end
--- Return the HTML of the infobox indicator component as string
---
--- @param data table {data, class, color, nopadding)
--- @return string html
function methodtable.renderIndicator( self, data )
checkType( 'Module:InfoboxNew.renderIndicator', 1, self, 'table' )
checkType( 'Module:InfoboxNew.renderIndicator', 2, data, 'table' )
if data == nil or data['data'] == nil or data['data'] == '' then return '' end