Ugrás a tartalomhoz

„Modul:Infobox” változatai közötti eltérés

Innen: TrashWiki
népesség csak az utolsó
a 1 változat importálva
Címke: Visszaállítva
1. sor: 1. sor:
require('strict')
local getArgs = require"Modul:Arguments".getArgs
local p = {}
local p = {}
local args = {}
local origArgs = {}
local root
local empty_row_categories = {}
local category_in_empty_row_pattern = '%[%[%s*[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]%s*:[^]]*]]'
local has_rows = false
local lists = {
plainlist_t = {
patterns = {
'^plainlist$',
'%splainlist$',
'^plainlist%s',
'%splainlist%s'
},
found = false,
styles = 'Plainlist/styles.css'
},
hlist_t = {
patterns = {
'^hlist$',
'%shlist$',
'^hlist%s',
'%shlist%s'
},
found = false,
styles = 'Hlist/styles.css'
}
}


p.row = function (args)
local function has_list_class(args_to_check)
args = getArgs(args)
for _, list in pairs(lists) do
local val, label, group, undertag
if not list.found then
val = args[1]
for _, arg in pairs(args_to_check) do
if not val then
for _, pattern in ipairs(list.patterns) do
return nil
if mw.ustring.find(arg or '', pattern) then
list.found = true
break
end
end
if list.found then break end
end
end
end
end
if args[3] then
end
label = '[[' .. args[3] .. '|' .. args[2] .. ']]'
 
local function fixChildBoxes(sval, tt)
local function notempty( s ) return s and s:match( '%S' ) end
if notempty(sval) then
local marker = '<span class=special_infobox_marker>'
local s = sval
-- start moving templatestyles and categories inside of table rows
local slast = ''
while slast ~= s do
slast = s
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>%s*)(%[%[%s*[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]%s*:[^]]*%]%])', '%2%1')
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>%s*)(\127[^\127]*UNIQ%-%-templatestyles%-%x+%-QINU[^\127]*\127)', '%2%1')
end
-- end moving templatestyles and categories inside of table rows
s = mw.ustring.gsub(s, '(<%s*[Tt][Rr])', marker .. '%1')
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>)', '%1' .. marker)
if s:match(marker) then
s = mw.ustring.gsub(s, marker .. '%s*' .. marker, '')
s = mw.ustring.gsub(s, '([\r\n]|-[^\r\n]*[\r\n])%s*' .. marker, '%1')
s = mw.ustring.gsub(s, marker .. '%s*([\r\n]|-)', '%1')
s = mw.ustring.gsub(s, '(</[Cc][Aa][Pp][Tt][Ii][Oo][Nn]%s*>%s*)' .. marker, '%1')
s = mw.ustring.gsub(s, '(<%s*[Tt][Aa][Bb][Ll][Ee][^<>]*>%s*)' .. marker, '%1')
s = mw.ustring.gsub(s, '^(%{|[^\r\n]*[\r\n]%s*)' .. marker, '%1')
s = mw.ustring.gsub(s, '([\r\n]%{|[^\r\n]*[\r\n]%s*)' .. marker, '%1')
s = mw.ustring.gsub(s, marker .. '(%s*</[Tt][Aa][Bb][Ll][Ee]%s*>)', '%1')
s = mw.ustring.gsub(s, marker .. '(%s*\n|%})', '%1')
end
if s:match(marker) then
local subcells = mw.text.split(s, marker)
s = ''
for k = 1, #subcells do
if k == 1 then
s = s .. subcells[k] .. '</' .. tt .. '></tr>'
elseif k == #subcells then
local rowstyle = ' style="display:none"'
if notempty(subcells[k]) then rowstyle = '' end
s = s .. '<tr' .. rowstyle ..'><' .. tt .. ' colspan=2>\n' ..
subcells[k]
elseif notempty(subcells[k]) then
if (k % 2) == 0 then
s = s .. subcells[k]
else
s = s .. '<tr><' .. tt .. ' colspan=2>\n' ..
subcells[k] .. '</' .. tt .. '></tr>'
end
end
end
end
-- the next two lines add a newline at the end of lists for the PHP parser
-- [[Special:Diff/849054481]]
-- remove when [[:phab:T191516]] is fixed or OBE
s = mw.ustring.gsub(s, '([\r\n][%*#;:][^\r\n]*)$', '%1\n')
s = mw.ustring.gsub(s, '^([%*#;:][^\r\n]*)$', '%1\n')
s = mw.ustring.gsub(s, '^([%*#;:])', '\n%1')
s = mw.ustring.gsub(s, '^(%{%|)', '\n%1')
return s
else
else
label = args[2]
return sval
end
end
group = args['csoportazonosító']
end
undertag = not (not args['címke alatt'])
 
local row = mw.html.create('tr')
-- Cleans empty tables
if group then
local function cleanInfobox()
row:addClass( 'csoport-' .. tostring(group) )
root = tostring(root)
if has_rows == false then
root = mw.ustring.gsub(root, '<table[^<>]*>%s*</table>', '')
end
end
local labeltag = row:tag('td')
labeltag:addClass(undertag and 'cimkealatt' or 'cimke')
if not undertag then
labeltag:css('font-weight', 'bolder')
end
labeltag:wikitext(label)
labeltag:done()
local valtag = row:tag('td')
valtag:wikitext(val)
valtag:done()
return tostring(row)
end
end


p['adat allapról'] = function (frame)
-- Returns the union of the values of two tables, as a sequence.
local args = getArgs(frame, { wrappers = 'Sablon:Infobox/Adat allapról' })
local function union(t1, t2)
if not args[1] or not args[2] then
 
return nil
local vals = {}
for k, v in pairs(t1) do
vals[v] = true
end
end
local value
for k, v in pairs(t2) do
if mw.language.getContentLanguage():lc(args[1]) == 'népesség' and args[2] == mw.title.getCurrentTitle().text then
vals[v] = true
value = require('Modul:Wikidata').formatStatements(nil, { property = 'P1082', format = 'default', sort = 'P585', sortDesc = '1', first = '1' })
end
end
if not value or value == '' then
local ret = {}
local title = mw.title.new('Sablon:' .. args[1] .. '/' .. args[2])
for k, v in pairs(vals) do
if title and title.exists then
table.insert(ret, k)
value = mw.getCurrentFrame():expandTemplate{ title = title.text .. (args[3] and ' (' .. args[3] .. ')' or '') }
else
value = mw.getCurrentFrame():expandTemplate{ title = args[1] .. '/ismeretlen', args = { args[2] } }
end
end
end
return string.format('<tr style="vertical-align:top;"><td style="font-weight:bold;">%s</td><td>%s</td></tr>', args[4] or '', value)
return ret
end
end


p["ország"] = function (frame)
-- Returns a table containing the numbers of the arguments that exist
local args = getArgs(frame, { wrappers = "Sablon:Infobox/Ország" })
-- for the specified prefix. For example, if the prefix was 'data', and
if args[1] == "-" then
-- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}.
return nil
local function getArgNums(prefix)
local nums = {}
for k, v in pairs(args) do
local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
if num then table.insert(nums, tonumber(num)) end
end
end
local cdata = require('Modul:Country data').main
table.sort(nums)
return p.row{
return nums
cdata{ [1] = args[1], ['size'] = args[4] },
'Ország'
}
end
end


p.image = function (filename, legend, property, entityId)
-- Adds a row to the infobox, with either a header cell
if filename == '-' then
-- or a label/data cell combination.
return nil, nil
local function addRow(rowArgs)
end
if (not filename) and property then
if rowArgs.header and rowArgs.header ~= '_BLANK_' then
local item = mw.wikibase.getEntity(entityId)
has_rows = true
if not item then
has_list_class({ rowArgs.rowclass, rowArgs.class, args.headerclass })
return nil, nil
root
:tag('tr')
:addClass(rowArgs.rowclass)
:cssText(rowArgs.rowstyle)
:tag('th')
:attr('colspan', '2')
:addClass('infobox-header')
:addClass(rowArgs.class)
:addClass(args.headerclass)
-- @deprecated next; target .infobox-<name> .infobox-header
:cssText(args.headerstyle)
:cssText(rowArgs.rowcellstyle)
:wikitext(fixChildBoxes(rowArgs.header, 'th'))
if rowArgs.data then
root:wikitext(
'[[Category:Pages using infobox templates with ignored data cells]]'
)
end
end
local image = item:getBestStatements(string.upper(property))[1]
elseif rowArgs.data and rowArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
if image and image.mainsnak.snaktype == 'value' then
has_rows = true
filename = image.mainsnak.datavalue.value
has_list_class({ rowArgs.rowclass, rowArgs.class })
legend = nil
if image.qualifiers and image.qualifiers.P2096 then
local row = root:tag('tr')
for _, snak in ipairs(image.qualifiers.P2096) do
row:addClass(rowArgs.rowclass)
if snak.snaktype == 'value' then
row:cssText(rowArgs.rowstyle)
if snak.datavalue.value.language == 'hu' then
if rowArgs.label then
legend = snak.datavalue.value.text
row
end
:tag('th')
end
:attr('scope', 'row')
end
:addClass('infobox-label')
end
-- @deprecated next; target .infobox-<name> .infobox-label
else
:cssText(args.labelstyle)
return nil, nil
:cssText(rowArgs.rowcellstyle)
:wikitext(rowArgs.label)
:done()
end
end
local dataCell = row:tag('td')
dataCell
:attr('colspan', not rowArgs.label and '2' or nil)
:addClass(not rowArgs.label and 'infobox-full-data' or 'infobox-data')
:addClass(rowArgs.class)
-- @deprecated next; target .infobox-<name> .infobox(-full)-data
:cssText(rowArgs.datastyle)
:cssText(rowArgs.rowcellstyle)
:wikitext(fixChildBoxes(rowArgs.data, 'td'))
else
table.insert(empty_row_categories, rowArgs.data or '')
end
end
return filename, legend
end
end


p["kép"] = function (frame)
local function renderTitle()
local args = getArgs(frame, {wrappers = "Sablon:Infobox/Kép"})
if not args.title then return end
local filename, legend = p.image(args[1], args[3], args["wd-property"], args["wd-entity"])
 
if not filename then
has_rows = true
return nil
has_list_class({args.titleclass})
root
:tag('caption')
:addClass('infobox-title')
:addClass(args.titleclass)
-- @deprecated next; target .infobox-<name> .infobox-title
:cssText(args.titlestyle)
:wikitext(args.title)
end
 
local function renderAboveRow()
if not args.above then return end
 
has_rows = true
has_list_class({ args.aboveclass })
root
:tag('tr')
:tag('th')
:attr('colspan', '2')
:addClass('infobox-above')
:addClass(args.aboveclass)
-- @deprecated next; target .infobox-<name> .infobox-above
:cssText(args.abovestyle)
:wikitext(fixChildBoxes(args.above,'th'))
end
 
local function renderBelowRow()
if not args.below then return end
 
has_rows = true
has_list_class({ args.belowclass })
root
:tag('tr')
:tag('td')
:attr('colspan', '2')
:addClass('infobox-below')
:addClass(args.belowclass)
-- @deprecated next; target .infobox-<name> .infobox-below
:cssText(args.belowstyle)
:wikitext(fixChildBoxes(args.below,'td'))
end
 
local function addSubheaderRow(subheaderArgs)
if subheaderArgs.data and
subheaderArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
has_rows = true
has_list_class({ subheaderArgs.rowclass, subheaderArgs.class })
local row = root:tag('tr')
row:addClass(subheaderArgs.rowclass)
 
local dataCell = row:tag('td')
dataCell
:attr('colspan', '2')
:addClass('infobox-subheader')
:addClass(subheaderArgs.class)
:cssText(subheaderArgs.datastyle)
:cssText(subheaderArgs.rowcellstyle)
:wikitext(fixChildBoxes(subheaderArgs.data, 'td'))
else
table.insert(empty_row_categories, subheaderArgs.data or '')
end
end
local filesize = args[2]
if not filesize then
local title = mw.title.new('Media:' .. filename)
if (
title and title.file.width and title.file.width < 250
and title.file.mimeType ~= 'image/svg' and title.file.mimeType ~= 'image/svg+xml'
) then
filesize = title.file.width
else
filesize = 250
end
filesize = tostring(filesize) .. 'px'
end
local link = "[[Fájl:" .. filename .. "|" .. filesize
if legend then
link = link .. "|" .. legend
end
link = link .. "]]"
local result = tostring(mw.html.create"tr"
:tag"td"
:attr("colspan", "2")
:css("text-align", "center")
:wikitext(link)
:allDone()
)
if legend then
result = result .. tostring(mw.html.create"tr"
:tag"td"
:attr("colspan", "2")
:css("text-align", "center")
:css("font-size", "92%")
:wikitext(legend)
:allDone()
)
end
return result
end
end


local function getWikidataCoord(entityId)
local function renderSubheaders()
local item = mw.wikibase.getEntity(entityId)
if args.subheader then
if not item then
args.subheader1 = args.subheader
return nil, nil
end
end
local P625 = item:getBestStatements('P625')
if args.subheaderrowclass then
for _, v in ipairs(P625) do
args.subheaderrowclass1 = args.subheaderrowclass
if v.mainsnak.snaktype == 'value' then
local lat = P625[1].mainsnak.datavalue.value.latitude
local long = P625[1].mainsnak.datavalue.value.longitude
return lat, long
end
end
end
local P159 = item:getBestStatements('P159')
local subheadernums = getArgNums('subheader')
for _, v in ipairs(P159) do
for k, num in ipairs(subheadernums) do
if v.qualifiers and v.qualifiers.P625 and v.qualifiers.P625[1].snaktype == 'value' then
addSubheaderRow({
local lat = v.qualifiers.P625[1].datavalue.value.latitude
data = args['subheader' .. tostring(num)],
local long = v.qualifiers.P625[1].datavalue.value.longitude
-- @deprecated next; target .infobox-<name> .infobox-subheader
return lat, long
datastyle = args.subheaderstyle,
end
rowcellstyle = args['subheaderstyle' .. tostring(num)],
class = args.subheaderclass,
rowclass = args['subheaderrowclass' .. tostring(num)]
})
end
end
return nil, nil
end
end


local function coordRow(coordinatesLink)
local function addImageRow(imageArgs)
return '<tr><td colspan="2" style="text-align:center">[[Fájl:OOjs UI icon mapPin-progressive.svg|16px|link=]] ' .. coordinatesLink .. '</td></tr>'
 
end
if imageArgs.data and
imageArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
 
has_rows = true
has_list_class({ imageArgs.rowclass, imageArgs.class })
local row = root:tag('tr')
row:addClass(imageArgs.rowclass)


--[[
local dataCell = row:tag('td')
Helyi értékű paramétereket átalakítja szám szerinti paraméterekké.
dataCell
Modul:Pozíciós térkép-ből is.
:attr('colspan', '2')
--]]
:addClass('infobox-image')
function p.coord(frame, args)
:addClass(imageArgs.class)
local coorArgs = {args[9], display = args.display, format = 'dms', with_pfunc = true}
:cssText(imageArgs.datastyle)
if args[1] and args[5] then
:wikitext(fixChildBoxes(imageArgs.data, 'td'))
local hemisphereMultipliers = {
longitude = { W = -1, w = -1, E = 1, e = 1, NY = -1, Ny = -1, ny = -1, K = 1, k = 1 },
latitude = { S = -1, s = -1, N = 1, n = 1, D = -1, d = -1, ['É'] = 1, ['é'] = 1 }
}
table.insert(coorArgs, 1, hemisphereMultipliers.latitude[args[4]] and args[4] or 'N')
table.insert(coorArgs, 2, hemisphereMultipliers.longitude[args[8]] and args[8] or 'E')
table.insert(coorArgs, 1, args[1])
table.insert(coorArgs, 3, args[5])
if args[2] and args[6] then
table.insert(coorArgs, 2, args[2])
table.insert(coorArgs, 5, args[6])
if args[3] and args[7] then
table.insert(coorArgs, 3, args[3])
table.insert(coorArgs, 7, args[7])
end
else
if not args[4] or not args[8] then
table.remove(coorArgs, 4)
table.remove(coorArgs, 2)
end
end
elseif args.lat and args.long then
table.insert(coorArgs, 1, args.lat)
table.insert(coorArgs, 2, args.long)
coorArgs.precision = 'wikidata'
else
else
return nil
table.insert(empty_row_categories, imageArgs.data or '')
end
end
return require( 'Modul:Coordinate' ).coord( nil, coorArgs )
end
end


p["pozíciós térkép"] = function (frame)
local function renderImages()
local args = getArgs(frame, {wrappers = "Sablon:Infobox/Pozíciós térkép"})
if args.image then
if args[4] == '-' or args[8] == '-' then
args.image1 = args.image
return nil
end
if args.caption then
args.caption1 = args.caption
end
end
local mapArgs = {
local imagenums = getArgNums('image')
args[1],
for k, num in ipairs(imagenums) do
['felirat'] = "'''" .. (args[2] ~= '{{{név}}}' and args[2] or require'Modul:String'.simpletitle{args = {}}) .. "'''",
local caption = args['caption' .. tostring(num)]
['keret'] = 'none',
local data = mw.html.create():wikitext(args['image' .. tostring(num)])
['felirat pozíciója'] = args[3],
if caption then
['jel'] = args.jel or 'Green pog.svg',
data
['felirat mérete'] = '100',
:tag('div')
['méret'] = '248',
:addClass('infobox-caption')
['igazítás'] = 'none',
-- @deprecated next; target .infobox-<name> .infobox-caption
['térképtípus'] = args['térképtípus'],
:cssText(args.captionstyle)
['meta'] = args.meta,
:wikitext(caption)
['jel mérete'] = args['jel mérete']
}
if args[4] and args[8] then
mapArgs['szélesség'] = args[7]
mapArgs['hosszúság'] = args[11]
mapArgs['szélességi fok'] = args[4]
mapArgs['hosszúsági fok'] = args[8]
if args[5] and args[9] then
mapArgs['szélességi ívperc'] = args[5]
mapArgs['hosszúsági ívperc'] = args[9]
if args[6] and args[10] then
mapArgs['szélességi ívmásodperc'] = args[6]
mapArgs['hosszúsági ívmásodperc'] = args[10]
end
end
else
mapArgs.lat, mapArgs.long = getWikidataCoord(args['wd-entity'])
if not mapArgs.lat or not mapArgs.long then
return nil
end
end
addImageRow({
data = tostring(data),
-- @deprecated next; target .infobox-<name> .infobox-image
datastyle = args.imagestyle,
class = args.imageclass,
rowclass = args['imagerowclass' .. tostring(num)]
})
end
end
local result = {}
end
local trackWikidata = false
 
if not args[1] then
-- When autoheaders are turned on, preprocesses the rows
if not args['koordinátakategória nélkül'] then
local function preprocessRows()
table.insert(result, '[[Kategória:Koordináták térkép nélkül]]')
if not args.autoheaders then return end
end
elseif args[1] ~= '-' then
local rownums = union(getArgNums('header'), getArgNums('data'))
local title = mw.title.new('Sablon:Pozíciós térkép ' .. args[1])
table.sort(rownums)
if title and mw.ustring.sub(args[1], -9) == ' vármegye' and not title.exists then
local lastheader
mapArgs[1] = mw.ustring.gsub(args[1], ' vármegye$', ' megye')
for k, num in ipairs(rownums) do
title = mw.title.new('Sablon:Pozíciós térkép ' .. mapArgs[1])
if args['header' .. tostring(num)] then
end
if lastheader then
if title and title.exists then
args['header' .. tostring(lastheader)] = nil
local success, map = pcall(require'Modul:Pozíciós térkép'.many, frame, mapArgs)
end
if not success then
lastheader = num
map = '<strong class="error">' .. map .. '</strong>[[Kategória:Hibásan használt pozícióstérkép-sablonok]]'
elseif args['data' .. tostring(num)] and
else
args['data' .. tostring(num)]:gsub(
trackWikidata = true
category_in_empty_row_pattern, ''
):match('^%S') then
local data = args['data' .. tostring(num)]
if data:gsub(category_in_empty_row_pattern, ''):match('%S') then
lastheader = nil
end
end
table.insert(result, '<tr><td colspan="2" align="center">' .. map .. '</td></tr>\n')
else
table.insert(result, '[[Kategória:Pozíciós térképet hiányoló lapok]]')
end
end
end
end
if lastheader then
args['header' .. tostring(lastheader)] = nil
end
end
-- Gets the union of the header and data argument numbers,
-- and renders them all in order
local function renderRows()


if args['koordináta a térkép alatt'] then
local rownums = union(getArgNums('header'), getArgNums('data'))
table.insert(result, coordRow(p.coord(frame, {args[4], args[5], args[6], args[7],  
table.sort(rownums)
args[8], args[9], args[10], args[11], args.meta, display = args['koordináta a cím alatt'] and 'inline,title',  
for k, num in ipairs(rownums) do
lat = mapArgs.lat, long = mapArgs.long})))
addRow({
trackWikidata = true
header = args['header' .. tostring(num)],
elseif args['koordináta a cím alatt'] then
label = args['label' .. tostring(num)],
table.insert(result, p.coord(frame, {args[4], args[5], args[6], args[7],  
data = args['data' .. tostring(num)],
args[8], args[9], args[10], args[11], args.meta, display = 'title',
datastyle = args.datastyle,
lat = mapArgs.lat, long = mapArgs.long}))
class = args['class' .. tostring(num)],
trackWikidata = true
rowclass = args['rowclass' .. tostring(num)],
-- @deprecated next; target .infobox-<name> rowclass
rowstyle = args['rowstyle' .. tostring(num)],
rowcellstyle = args['rowcellstyle' .. tostring(num)]
})
end
end
-- Nincs rá szükség
end
--if trackWikidata and mapArgs.lat then
 
-- table.insert(result, '[[Kategória:Wikidata-koordinátákat használó lapok]]')
local function renderNavBar()
--end
if not args.name then return end


return table.concat(result)
has_rows = true
root
:tag('tr')
:tag('td')
:attr('colspan', '2')
:addClass('infobox-navbar')
:wikitext(require('Module:Navbar')._navbar{
args.name,
mini = 1,
})
end
end


p["koordináta"] = function (frame)
local function renderItalicTitle()
local args = getArgs(frame, {wrappers = "Sablon:Infobox/Koordináta"})
local italicTitle = args['italic title'] and mw.ustring.lower(args['italic title'])
if args[1] == '-' or args[5] == '-' then
if italicTitle == '' or italicTitle == 'force' or italicTitle == 'yes' then
return nil
root:wikitext(require('Module:Italic title')._main({}))
end
end
if not args[1] or not args[5] then
end
args.lat, args.long = getWikidataCoord(args['wd-entity'])
 
if not args.lat or not args.long then
-- Categories in otherwise empty rows are collected in empty_row_categories.
return nil
-- This function adds them to the module output. It is not affected by
-- args.decat because this module should not prevent module-external categories
-- from rendering.
local function renderEmptyRowCategories()
for _, s in ipairs(empty_row_categories) do
root:wikitext(s)
end
end
 
-- Render tracking categories. args.decat == turns off tracking categories.
local function renderTrackingCategories()
if args.decat == 'yes' then return end
if args.child == 'yes' then
if args.title then
root:wikitext(
'[[Category:Pages using embedded infobox templates with the title parameter]]'
)
end
end
elseif #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then
root:wikitext('[[Category:Articles using infobox templates with no data rows]]')
end
end
return coordRow(p.coord(frame, args))
end
end


function p.terkep(frame)
--[=[
local args = getArgs(frame, { wrappers='Sablon:Infobox/Térkép' })
Loads the templatestyles for the infobox.
if args.mapframe == 'no' or args.map == '-' then
 
return nil
TODO: FINISH loading base templatestyles here rather than in
MediaWiki:Common.css. There are 4-5000 pages with 'raw' infobox tables.
See [[Mediawiki_talk:Common.css/to_do#Infobox]] and/or come help :).
When we do this we should clean up the inline CSS below too.
Will have to do some bizarre conversion category like with sidebar.
 
]=]
local function loadTemplateStyles()
local frame = mw.getCurrentFrame()
local hlist_templatestyles = ''
if lists.hlist_t.found then
hlist_templatestyles = frame:extensionTag{
name = 'templatestyles', args = { src = lists.hlist_t.styles }
}
end
end
local itemId = mw.wikibase.getEntityIdForCurrentPage() or args.entityId
local cst = itemId and mw.wikibase.getBestStatements(itemId, 'P625') or {}
local plainlist_templatestyles = ''
if not args.coord and not next(cst) then
if lists.plainlist_t.found then
return nil
plainlist_templatestyles = frame:extensionTag{
name = 'templatestyles', args = { src = lists.plainlist_t.styles }
}
end
-- See function description
local base_templatestyles = frame:extensionTag{
name = 'templatestyles', args = { src = 'Module:Infobox/styles.css' }
}
 
local templatestyles = ''
if args['templatestyles'] then
templatestyles = frame:extensionTag{
name = 'templatestyles', args = { src = args['templatestyles'] }
}
end
local child_templatestyles = ''
if args['child templatestyles'] then
child_templatestyles = frame:extensionTag{
name = 'templatestyles', args = { src = args['child templatestyles'] }
}
end
end
if next(cst) and cst[1].mainsnak.datavalue.value.latitude <= -60 then -- southern arctic
frame.args[1] = args.map
local grandchild_templatestyles = ''
return p['pozíciós térkép'](frame)
if args['grandchild templatestyles'] then
grandchild_templatestyles = frame:extensionTag{
name = 'templatestyles', args = { src = args['grandchild templatestyles'] }
}
end
end
return ('<tr><td colspan="2" style="text-align:center">%s</td></tr>')
:format(require('Modul:Pozíciós térkép').infoboxMapframe(frame))
return table.concat({
-- hlist -> plainlist -> base is best-effort to preserve old Common.css ordering.
-- this ordering is not a guarantee because the rows of interest invoking
-- each class may not be on a specific page
hlist_templatestyles,
plainlist_templatestyles,
base_templatestyles,
templatestyles,
child_templatestyles,
grandchild_templatestyles
})
end
 
-- common functions between the child and non child cases
local function structure_infobox_common()
renderSubheaders()
renderImages()
preprocessRows()
renderRows()
renderBelowRow()
renderNavBar()
renderItalicTitle()
renderEmptyRowCategories()
renderTrackingCategories()
cleanInfobox()
end
end


function p.tarsprojekt(frame)
-- Specify the overall layout of the infobox, with special settings if the
local args = getArgs(frame, { wrappers='Sablon:Infobox/Társprojekt' })
-- infobox is used as a 'child' inside another infobox.
if not args[1] then
local function _infobox()
return nil
if args.child ~= 'yes' then
root = mw.html.create('table')
 
root
:addClass(args.subbox == 'yes' and 'infobox-subbox' or 'infobox')
:addClass(args.bodyclass)
-- @deprecated next; target .infobox-<name>
:cssText(args.bodystyle)
has_list_class({ args.bodyclass })
 
renderTitle()
renderAboveRow()
else
root = mw.html.create()
 
root
:wikitext(args.title)
end
end
local title = args[2]
structure_infobox_common()
if title == '-' then
return nil
return loadTemplateStyles() .. root
end
 
-- If the argument exists and isn't blank, add it to the argument table.
-- Blank arguments are treated as nil to match the behaviour of ParserFunctions.
local function preprocessSingleArg(argName)
if origArgs[argName] and origArgs[argName] ~= '' then
args[argName] = origArgs[argName]
end
end
local siteGroup, prefix, lang, imageFile
end
if args[1]:match('^[Cc]ommons$') then
 
siteGroup = 'commonswiki'
-- Assign the parameters with the given prefixes to the args table, in order, in
prefix = 'c:'
-- batches of the step size specified. This is to prevent references etc. from
imageFile = 'Commons-logo.svg'
-- appearing in the wrong order. The prefixTable should be an array containing
elseif args[1]:match('^[Ww]ikiforrás$') then
-- tables, each of which has two possible fields, a "prefix" string and a
siteGroup = 'wikisource'
-- "depend" table. The function always parses parameters containing the "prefix"
prefix = 's:'
-- string, but only parses parameters in the "depend" table if the prefix
imageFile = 'Wikisource-logo.svg'
-- parameter is present and non-blank.
local function preprocessArgs(prefixTable, step)
if type(prefixTable) ~= 'table' then
error("Non-table value detected for the prefix table", 2)
end
end
if not siteGroup then
if type(step) ~= 'number' then
return nil
error("Invalid step value detected", 2)
end
end
if siteGroup:sub(1, 4) == 'wiki' then
 
lang = args[3] or 'hu'
-- Get arguments without a number suffix, and check for bad input.
end
for i,v in ipairs(prefixTable) do
if not title then
if type(v) ~= 'table' or type(v.prefix) ~= "string" or
local itemId = args[6] or mw.wikibase.getEntityIdForCurrentPage()
(v.depend and type(v.depend) ~= 'table') then
if not itemId then
error('Invalid input detected to preprocessArgs prefix table', 2)
return nil
end
end
title = mw.wikibase.getSitelink(itemId, (lang or '') .. siteGroup)
preprocessSingleArg(v.prefix)
if siteGroup == 'commonswiki' then
-- Only parse the depend parameter if the prefix parameter is present
if not title or title:sub(1, 9) ~= 'Category:' then
-- and not blank.
local st = mw.wikibase.getBestStatements(itemId, 'P373')
if args[v.prefix] and v.depend then
if next(st) and st[1].mainsnak.snaktype == 'value' then
for j, dependValue in ipairs(v.depend) do
title = 'Category:' .. st[1].mainsnak.datavalue.value
if type(dependValue) ~= 'string' then
error('Invalid "depend" parameter value detected in preprocessArgs')
end
end
preprocessSingleArg(dependValue)
end
end
end
end
if not title then
return nil
end
end
local text = '<strong class="error">Modul:Infobox: Nincs megadva szöveg</strong>'
if siteGroup == 'commonswiki' then
text = "A [[Wikimédia Commons]] tartalmaz ''[[%s]]'' témájú médiaállományokat."
elseif siteGroup == 'wikisource' then
text = (lang == 'hu' and 'A' or frame:preprocess(('{{NAGYKEZDŐBETŰ:{{a(z)|{{nyelv neve/%s}}}}}}'):format(lang))) ..
" [[Wikiforrás]]ban további forrásszövegek találhatók ''[[%s]]'' témában."
end
end
local label = args[4] or require('Modul:String').simpletitle()
text = text:format(('%s%s%s|%s'):format(prefix, lang and lang ~= 'hu' and lang .. ':' or '', title, label))
return ('<tr><td colspan="2" style="background-color:%s"><div style="display:flex"><div>[[Fájl:%s|20px|link=|alt=]]</div><div style="width:100%%; padding-left:1ch; text-align:center">%s</div></div></td></tr>')
:format(args[5] or '#e4ebf3', imageFile, text)
end


--[[
-- Get arguments with number suffixes.
Sablon:Repülőtér infobox futópálya P529
local a = 1 -- Counter variable.
  ]]
local moreArgumentsExist = true
function p.repuloter_futopalya(frame)
while moreArgumentsExist == true do
local args = getArgs(frame, { frameOnly = true })
moreArgumentsExist = false
if args[1] then
for i = a, a + step - 1 do
return nil
for j,v in ipairs(prefixTable) do
end
local prefixArgName = v.prefix .. tostring(i)
if args[2] == '-' then
if origArgs[prefixArgName] then
return nil
-- Do another loop if any arguments are found, even blank ones.
end
moreArgumentsExist = true
local itemId = mw.wikibase.getEntityIdForCurrentPage()
preprocessSingleArg(prefixArgName)
if not itemId then
end
return nil
-- Process the depend table if the prefix argument is present
end
-- and not blank, or we are processing "prefix1" and "prefix" is
local ret = {}
-- present and not blank, and if the depend table is present.
local f = require'Modul:Wikidata'.formatters
if v.depend and (args[prefixArgName] or (i == 1 and args[v.prefix])) then
local options = { link = 'nem', unit = 'm', showUnit = true, conjunction = ', ' }
for j,dependValue in ipairs(v.depend) do
for _, s in ipairs(mw.wikibase.getBestStatements(itemId, 'P529')) do
local dependArgName = dependValue .. tostring(i)
local material = {}
preprocessSingleArg(dependArgName)
for _, q in ipairs(s.qualifiers and s.qualifiers.P186 or {}) do
end
table.insert(material, mw.wikibase.renderSnak(q))
end
end
end
end
table.insert(ret, '<tr><td>' .. mw.wikibase.renderSnak(s.mainsnak) ..
a = a + step
'</td><td>' .. f.formatSnaks(s.qualifiers and s.qualifiers.P2043 or {}, options) ..
'</td><td>' .. table.concat(material, ', ') ..
'</td></tr>')
end
end
return table.concat(ret)
end
end


--[[
-- Parse the data parameters in the same order that the old {{infobox}} did, so
Sablon:Világörökségi helyszín infobox/veszélyeztetettség/P793
-- that references etc. will display in the expected places. Parameters that
  ]]
-- depend on another parameter are only processed if that parameter is present,
function p.vor_veszelyeztetettseg(frame)
-- to avoid phantom references appearing in article reference lists.
local args = getArgs(frame, { frameOnly = true })
local function parseDataParameters()
if args[1] == '-' then
 
return nil
preprocessSingleArg('autoheaders')
end
preprocessSingleArg('child')
if args[1] then
preprocessSingleArg('bodyclass')
return args[1]
preprocessSingleArg('subbox')
end
preprocessSingleArg('bodystyle')
local itemId = mw.wikibase.getEntityIdForCurrentPage()
preprocessSingleArg('title')
if not itemId then
preprocessSingleArg('titleclass')
return nil
preprocessSingleArg('titlestyle')
end
preprocessSingleArg('above')
local ret = {}
preprocessSingleArg('aboveclass')
for _, s in ipairs(mw.wikibase.getBestStatements(itemId, 'P793')) do
preprocessSingleArg('abovestyle')
local startTime, endTime
preprocessArgs({
if s.mainsnak.datavalue.value.id == 'Q222384' and s.qualifiers then
{prefix = 'subheader', depend = {'subheaderstyle', 'subheaderrowclass'}}
startTime = s.qualifiers.P580 and mw.wikibase.renderSnak(s.qualifiers.P580[1]) or nil
}, 10)
endTime = s.qualifiers.P582 and mw.wikibase.renderSnak(s.qualifiers.P582[1]) or nil
preprocessSingleArg('subheaderstyle')
end
preprocessSingleArg('subheaderclass')
if startTime or endTime then
preprocessArgs({
table.insert(ret, (startTime or '') .. '' .. (endTime or ''))
{prefix = 'image', depend = {'caption', 'imagerowclass'}}
end
}, 10)
end
preprocessSingleArg('captionstyle')
return table.concat(ret, '<br>')
preprocessSingleArg('imagestyle')
preprocessSingleArg('imageclass')
preprocessArgs({
{prefix = 'header'},
{prefix = 'data', depend = {'label'}},
{prefix = 'rowclass'},
{prefix = 'rowstyle'},
{prefix = 'rowcellstyle'},
{prefix = 'class'}
}, 50)
preprocessSingleArg('headerclass')
preprocessSingleArg('headerstyle')
preprocessSingleArg('labelstyle')
preprocessSingleArg('datastyle')
preprocessSingleArg('below')
preprocessSingleArg('belowclass')
preprocessSingleArg('belowstyle')
preprocessSingleArg('name')
-- different behaviour for italics if blank or absent
args['italic title'] = origArgs['italic title']
preprocessSingleArg('decat')
preprocessSingleArg('templatestyles')
preprocessSingleArg('child templatestyles')
preprocessSingleArg('grandchild templatestyles')
end
end


--[[
-- If called via #invoke, use the args passed into the invoking template.
Sablon:Stw
-- Otherwise, for testing purposes, assume args are being passed directly in.
--]]
function p.infobox(frame)
function p.newline_for_wikitext(frame)
if frame == mw.getCurrentFrame() then
local text = frame.args[1]
origArgs = frame:getParent().args
if not text or text:match('^%s*(.-)%s*$') == '' then
else
return nil
origArgs = frame
end
end
if mw.ustring.find('*#: ', mw.ustring.sub(text, 1, 1), 1, true) or mw.ustring.sub(text, 1, 2) == '{|' then
return '\n'
parseDataParameters()
end
return nil
return _infobox()
end
end


-- For calling via #invoke within a template
function p.infoboxTemplate(frame)
origArgs = {}
for k,v in pairs(frame.args) do origArgs[k] = mw.text.trim(v) end
parseDataParameters()
return _infobox()
end
return p
return p

A lap 2025. január 21., 07:36-kori változata

A modult a Modul:Infobox/doc lapon tudod dokumentálni

local p = {}
local args = {}
local origArgs = {}
local root
local empty_row_categories = {}
local category_in_empty_row_pattern = '%[%[%s*[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]%s*:[^]]*]]'
local has_rows = false
local lists = {
	plainlist_t = {
		patterns = {
			'^plainlist$',
			'%splainlist$',
			'^plainlist%s',
			'%splainlist%s'
		},
		found = false,
		styles = 'Plainlist/styles.css'
	},
	hlist_t = {
		patterns = {
			'^hlist$',
			'%shlist$',
			'^hlist%s',
			'%shlist%s'
		},
		found = false,
		styles = 'Hlist/styles.css'
	}
}

local function has_list_class(args_to_check)
	for _, list in pairs(lists) do
		if not list.found then
			for _, arg in pairs(args_to_check) do
				for _, pattern in ipairs(list.patterns) do
					if mw.ustring.find(arg or '', pattern) then
						list.found = true
						break
					end
				end
				if list.found then break end
			end
		end
	end
end

local function fixChildBoxes(sval, tt)
	local function notempty( s ) return s and s:match( '%S' ) end
	
	if notempty(sval) then
		local marker = '<span class=special_infobox_marker>'
		local s = sval
		-- start moving templatestyles and categories inside of table rows
		local slast = ''
		while slast ~= s do
			slast = s
			s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>%s*)(%[%[%s*[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]%s*:[^]]*%]%])', '%2%1')
			s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>%s*)(\127[^\127]*UNIQ%-%-templatestyles%-%x+%-QINU[^\127]*\127)', '%2%1')
		end
		-- end moving templatestyles and categories inside of table rows
		s = mw.ustring.gsub(s, '(<%s*[Tt][Rr])', marker .. '%1')
		s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>)', '%1' .. marker)
		if s:match(marker) then
			s = mw.ustring.gsub(s, marker .. '%s*' .. marker, '')
			s = mw.ustring.gsub(s, '([\r\n]|-[^\r\n]*[\r\n])%s*' .. marker, '%1')
			s = mw.ustring.gsub(s, marker .. '%s*([\r\n]|-)', '%1')
			s = mw.ustring.gsub(s, '(</[Cc][Aa][Pp][Tt][Ii][Oo][Nn]%s*>%s*)' .. marker, '%1')
			s = mw.ustring.gsub(s, '(<%s*[Tt][Aa][Bb][Ll][Ee][^<>]*>%s*)' .. marker, '%1')
			s = mw.ustring.gsub(s, '^(%{|[^\r\n]*[\r\n]%s*)' .. marker, '%1')
			s = mw.ustring.gsub(s, '([\r\n]%{|[^\r\n]*[\r\n]%s*)' .. marker, '%1')
			s = mw.ustring.gsub(s, marker .. '(%s*</[Tt][Aa][Bb][Ll][Ee]%s*>)', '%1')
			s = mw.ustring.gsub(s, marker .. '(%s*\n|%})', '%1')
		end
		if s:match(marker) then
			local subcells = mw.text.split(s, marker)
			s = ''
			for k = 1, #subcells do
				if k == 1 then
					s = s .. subcells[k] .. '</' .. tt .. '></tr>'
				elseif k == #subcells then
					local rowstyle = ' style="display:none"'
					if notempty(subcells[k]) then rowstyle = ''	end
					s = s .. '<tr' .. rowstyle ..'><' .. tt .. ' colspan=2>\n' ..
						subcells[k]
				elseif notempty(subcells[k]) then
					if (k % 2) == 0 then
						s = s .. subcells[k]
					else
						s = s .. '<tr><' .. tt .. ' colspan=2>\n' ..
							subcells[k] .. '</' .. tt .. '></tr>'
					end
				end
			end
		end
		-- the next two lines add a newline at the end of lists for the PHP parser
		-- [[Special:Diff/849054481]]
		-- remove when [[:phab:T191516]] is fixed or OBE
		s = mw.ustring.gsub(s, '([\r\n][%*#;:][^\r\n]*)$', '%1\n')
		s = mw.ustring.gsub(s, '^([%*#;:][^\r\n]*)$', '%1\n')
		s = mw.ustring.gsub(s, '^([%*#;:])', '\n%1')
		s = mw.ustring.gsub(s, '^(%{%|)', '\n%1')
		return s
	else
		return sval
	end
end

-- Cleans empty tables
local function cleanInfobox()
	root = tostring(root)
	if has_rows == false then
		root = mw.ustring.gsub(root, '<table[^<>]*>%s*</table>', '')
	end
end

-- Returns the union of the values of two tables, as a sequence.
local function union(t1, t2)

	local vals = {}
	for k, v in pairs(t1) do
		vals[v] = true
	end
	for k, v in pairs(t2) do
		vals[v] = true
	end
	local ret = {}
	for k, v in pairs(vals) do
		table.insert(ret, k)
	end
	return ret
end

-- Returns a table containing the numbers of the arguments that exist
-- for the specified prefix. For example, if the prefix was 'data', and
-- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}.
local function getArgNums(prefix)
	local nums = {}
	for k, v in pairs(args) do
		local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
		if num then table.insert(nums, tonumber(num)) end
	end
	table.sort(nums)
	return nums
end

-- Adds a row to the infobox, with either a header cell
-- or a label/data cell combination.
local function addRow(rowArgs)
	
	if rowArgs.header and rowArgs.header ~= '_BLANK_' then
		has_rows = true
		has_list_class({ rowArgs.rowclass, rowArgs.class, args.headerclass })
		
		root
			:tag('tr')
				:addClass(rowArgs.rowclass)
				:cssText(rowArgs.rowstyle)
				:tag('th')
					:attr('colspan', '2')
					:addClass('infobox-header')
					:addClass(rowArgs.class)
					:addClass(args.headerclass)
					-- @deprecated next; target .infobox-<name> .infobox-header
					:cssText(args.headerstyle)
					:cssText(rowArgs.rowcellstyle)
					:wikitext(fixChildBoxes(rowArgs.header, 'th'))
		if rowArgs.data then
			root:wikitext(
				'[[Category:Pages using infobox templates with ignored data cells]]'
			)
		end
	elseif rowArgs.data and rowArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
		has_rows = true
		has_list_class({ rowArgs.rowclass, rowArgs.class })
		
		local row = root:tag('tr')
		row:addClass(rowArgs.rowclass)
		row:cssText(rowArgs.rowstyle)
		if rowArgs.label then
			row
				:tag('th')
					:attr('scope', 'row')
					:addClass('infobox-label')
					-- @deprecated next; target .infobox-<name> .infobox-label
					:cssText(args.labelstyle)
					:cssText(rowArgs.rowcellstyle)
					:wikitext(rowArgs.label)
					:done()
		end

		local dataCell = row:tag('td')
		dataCell
			:attr('colspan', not rowArgs.label and '2' or nil)
			:addClass(not rowArgs.label and 'infobox-full-data' or 'infobox-data')
			:addClass(rowArgs.class)
			-- @deprecated next; target .infobox-<name> .infobox(-full)-data
			:cssText(rowArgs.datastyle)
			:cssText(rowArgs.rowcellstyle)
			:wikitext(fixChildBoxes(rowArgs.data, 'td'))
	else
		table.insert(empty_row_categories, rowArgs.data or '')
	end
end

local function renderTitle()
	if not args.title then return end

	has_rows = true
	has_list_class({args.titleclass})
	
	root
		:tag('caption')
			:addClass('infobox-title')
			:addClass(args.titleclass)
			-- @deprecated next; target .infobox-<name> .infobox-title
			:cssText(args.titlestyle)
			:wikitext(args.title)
	
end

local function renderAboveRow()
	if not args.above then return end

	has_rows = true
	has_list_class({ args.aboveclass })
	
	root
		:tag('tr')
			:tag('th')
				:attr('colspan', '2')
				:addClass('infobox-above')
				:addClass(args.aboveclass)
				-- @deprecated next; target .infobox-<name> .infobox-above
				:cssText(args.abovestyle)
				:wikitext(fixChildBoxes(args.above,'th'))
end

local function renderBelowRow()
	if not args.below then return end

	has_rows = true
	has_list_class({ args.belowclass })
	
	root
		:tag('tr')
			:tag('td')
				:attr('colspan', '2')
				:addClass('infobox-below')
				:addClass(args.belowclass)
				-- @deprecated next; target .infobox-<name> .infobox-below
				:cssText(args.belowstyle)
				:wikitext(fixChildBoxes(args.below,'td'))
end

local function addSubheaderRow(subheaderArgs)
	if subheaderArgs.data and
		subheaderArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
		has_rows = true
		has_list_class({ subheaderArgs.rowclass, subheaderArgs.class })
		
		local row = root:tag('tr')
		row:addClass(subheaderArgs.rowclass)

		local dataCell = row:tag('td')
		dataCell
			:attr('colspan', '2')
			:addClass('infobox-subheader')
			:addClass(subheaderArgs.class)
			:cssText(subheaderArgs.datastyle)
			:cssText(subheaderArgs.rowcellstyle)
			:wikitext(fixChildBoxes(subheaderArgs.data, 'td'))
	else
		table.insert(empty_row_categories, subheaderArgs.data or '')
	end
end

local function renderSubheaders()
	if args.subheader then
		args.subheader1 = args.subheader
	end
	if args.subheaderrowclass then
		args.subheaderrowclass1 = args.subheaderrowclass
	end
	local subheadernums = getArgNums('subheader')
	for k, num in ipairs(subheadernums) do
		addSubheaderRow({
			data = args['subheader' .. tostring(num)],
			-- @deprecated next; target .infobox-<name> .infobox-subheader
			datastyle = args.subheaderstyle,
			rowcellstyle = args['subheaderstyle' .. tostring(num)],
			class = args.subheaderclass,
			rowclass = args['subheaderrowclass' .. tostring(num)]
		})
	end
end

local function addImageRow(imageArgs)

	if imageArgs.data and
		imageArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then

		has_rows = true
		has_list_class({ imageArgs.rowclass, imageArgs.class })
		
		local row = root:tag('tr')
		row:addClass(imageArgs.rowclass)

		local dataCell = row:tag('td')
		dataCell
			:attr('colspan', '2')
			:addClass('infobox-image')
			:addClass(imageArgs.class)
			:cssText(imageArgs.datastyle)
			:wikitext(fixChildBoxes(imageArgs.data, 'td'))
	else
		table.insert(empty_row_categories, imageArgs.data or '')
	end
end

local function renderImages()
	if args.image then
		args.image1 = args.image
	end
	if args.caption then
		args.caption1 = args.caption
	end
	local imagenums = getArgNums('image')
	for k, num in ipairs(imagenums) do
		local caption = args['caption' .. tostring(num)]
		local data = mw.html.create():wikitext(args['image' .. tostring(num)])
		if caption then
			data
				:tag('div')
					:addClass('infobox-caption')
					-- @deprecated next; target .infobox-<name> .infobox-caption
					:cssText(args.captionstyle)
					:wikitext(caption)
		end
		addImageRow({
			data = tostring(data),
			-- @deprecated next; target .infobox-<name> .infobox-image
			datastyle = args.imagestyle,
			class = args.imageclass,
			rowclass = args['imagerowclass' .. tostring(num)]
		})
	end
end

-- When autoheaders are turned on, preprocesses the rows
local function preprocessRows()
	if not args.autoheaders then return end
	
	local rownums = union(getArgNums('header'), getArgNums('data'))
	table.sort(rownums)
	local lastheader
	for k, num in ipairs(rownums) do
		if args['header' .. tostring(num)] then
			if lastheader then
				args['header' .. tostring(lastheader)] = nil
			end
			lastheader = num
		elseif args['data' .. tostring(num)] and
			args['data' .. tostring(num)]:gsub(
				category_in_empty_row_pattern, ''
			):match('^%S') then
			local data = args['data' .. tostring(num)]
			if data:gsub(category_in_empty_row_pattern, ''):match('%S') then
				lastheader = nil
			end
		end
	end
	if lastheader then
		args['header' .. tostring(lastheader)] = nil
	end
end

-- Gets the union of the header and data argument numbers,
-- and renders them all in order
local function renderRows()

	local rownums = union(getArgNums('header'), getArgNums('data'))
	table.sort(rownums)
	for k, num in ipairs(rownums) do
		addRow({
			header = args['header' .. tostring(num)],
			label = args['label' .. tostring(num)],
			data = args['data' .. tostring(num)],
			datastyle = args.datastyle,
			class = args['class' .. tostring(num)],
			rowclass = args['rowclass' .. tostring(num)],
			-- @deprecated next; target .infobox-<name> rowclass
			rowstyle = args['rowstyle' .. tostring(num)],
			rowcellstyle = args['rowcellstyle' .. tostring(num)]
		})
	end
end

local function renderNavBar()
	if not args.name then return end

	has_rows = true
	root
		:tag('tr')
			:tag('td')
				:attr('colspan', '2')
				:addClass('infobox-navbar')
				:wikitext(require('Module:Navbar')._navbar{
					args.name,
					mini = 1,
				})
end

local function renderItalicTitle()
	local italicTitle = args['italic title'] and mw.ustring.lower(args['italic title'])
	if italicTitle == '' or italicTitle == 'force' or italicTitle == 'yes' then
		root:wikitext(require('Module:Italic title')._main({}))
	end
end

-- Categories in otherwise empty rows are collected in empty_row_categories.
-- This function adds them to the module output. It is not affected by
-- args.decat because this module should not prevent module-external categories
-- from rendering.
local function renderEmptyRowCategories()
	for _, s in ipairs(empty_row_categories) do
		root:wikitext(s)
	end
end

-- Render tracking categories. args.decat == turns off tracking categories.
local function renderTrackingCategories()
	if args.decat == 'yes' then return end
	if args.child == 'yes' then
		if args.title then
			root:wikitext(
				'[[Category:Pages using embedded infobox templates with the title parameter]]'
			)
		end
	elseif #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then
		root:wikitext('[[Category:Articles using infobox templates with no data rows]]')
	end
end

--[=[
Loads the templatestyles for the infobox.

TODO: FINISH loading base templatestyles here rather than in
MediaWiki:Common.css. There are 4-5000 pages with 'raw' infobox tables.
See [[Mediawiki_talk:Common.css/to_do#Infobox]] and/or come help :).
When we do this we should clean up the inline CSS below too.
Will have to do some bizarre conversion category like with sidebar.

]=]
local function loadTemplateStyles()
	local frame = mw.getCurrentFrame()
	
	local hlist_templatestyles = ''
	if lists.hlist_t.found then
		hlist_templatestyles = frame:extensionTag{
			name = 'templatestyles', args = { src = lists.hlist_t.styles }
		}
	end
	
	local plainlist_templatestyles = ''
	if lists.plainlist_t.found then
		plainlist_templatestyles = frame:extensionTag{
			name = 'templatestyles', args = { src = lists.plainlist_t.styles }
		}
	end
	
	-- See function description
	local base_templatestyles = frame:extensionTag{
		name = 'templatestyles', args = { src = 'Module:Infobox/styles.css' }
	}

	local templatestyles = ''
	if args['templatestyles'] then
		templatestyles = frame:extensionTag{
			name = 'templatestyles', args = { src = args['templatestyles'] }
		}
	end
	
	local child_templatestyles = ''
	if args['child templatestyles'] then
		child_templatestyles = frame:extensionTag{
			name = 'templatestyles', args = { src = args['child templatestyles'] }
		}
	end
	
	local grandchild_templatestyles = ''
	if args['grandchild templatestyles'] then
		grandchild_templatestyles = frame:extensionTag{
			name = 'templatestyles', args = { src = args['grandchild templatestyles'] }
		}
	end
	
	return table.concat({
		-- hlist -> plainlist -> base is best-effort to preserve old Common.css ordering.
		-- this ordering is not a guarantee because the rows of interest invoking
		-- each class may not be on a specific page
		hlist_templatestyles,
		plainlist_templatestyles,
		base_templatestyles,
		templatestyles,
		child_templatestyles,
		grandchild_templatestyles
	})
end

-- common functions between the child and non child cases
local function structure_infobox_common()
	renderSubheaders()
	renderImages()
	preprocessRows()
	renderRows()
	renderBelowRow()
	renderNavBar()
	renderItalicTitle()
	renderEmptyRowCategories()
	renderTrackingCategories()
	cleanInfobox()
end

-- Specify the overall layout of the infobox, with special settings if the
-- infobox is used as a 'child' inside another infobox.
local function _infobox()
	if args.child ~= 'yes' then
		root = mw.html.create('table')

		root
			:addClass(args.subbox == 'yes' and 'infobox-subbox' or 'infobox')
			:addClass(args.bodyclass)
			-- @deprecated next; target .infobox-<name>
			:cssText(args.bodystyle)
		
		has_list_class({ args.bodyclass })

		renderTitle()
		renderAboveRow()
	else
		root = mw.html.create()

		root
			:wikitext(args.title)
	end
	structure_infobox_common()
	
	return loadTemplateStyles() .. root
end

-- If the argument exists and isn't blank, add it to the argument table.
-- Blank arguments are treated as nil to match the behaviour of ParserFunctions.
local function preprocessSingleArg(argName)
	if origArgs[argName] and origArgs[argName] ~= '' then
		args[argName] = origArgs[argName]
	end
end

-- Assign the parameters with the given prefixes to the args table, in order, in
-- batches of the step size specified. This is to prevent references etc. from
-- appearing in the wrong order. The prefixTable should be an array containing
-- tables, each of which has two possible fields, a "prefix" string and a
-- "depend" table. The function always parses parameters containing the "prefix"
-- string, but only parses parameters in the "depend" table if the prefix
-- parameter is present and non-blank.
local function preprocessArgs(prefixTable, step)
	if type(prefixTable) ~= 'table' then
		error("Non-table value detected for the prefix table", 2)
	end
	if type(step) ~= 'number' then
		error("Invalid step value detected", 2)
	end

	-- Get arguments without a number suffix, and check for bad input.
	for i,v in ipairs(prefixTable) do
		if type(v) ~= 'table' or type(v.prefix) ~= "string" or
			(v.depend and type(v.depend) ~= 'table') then
			error('Invalid input detected to preprocessArgs prefix table', 2)
		end
		preprocessSingleArg(v.prefix)
		-- Only parse the depend parameter if the prefix parameter is present
		-- and not blank.
		if args[v.prefix] and v.depend then
			for j, dependValue in ipairs(v.depend) do
				if type(dependValue) ~= 'string' then
					error('Invalid "depend" parameter value detected in preprocessArgs')
				end
				preprocessSingleArg(dependValue)
			end
		end
	end

	-- Get arguments with number suffixes.
	local a = 1 -- Counter variable.
	local moreArgumentsExist = true
	while moreArgumentsExist == true do
		moreArgumentsExist = false
		for i = a, a + step - 1 do
			for j,v in ipairs(prefixTable) do
				local prefixArgName = v.prefix .. tostring(i)
				if origArgs[prefixArgName] then
					-- Do another loop if any arguments are found, even blank ones.
					moreArgumentsExist = true
					preprocessSingleArg(prefixArgName)
				end
				-- Process the depend table if the prefix argument is present
				-- and not blank, or we are processing "prefix1" and "prefix" is
				-- present and not blank, and if the depend table is present.
				if v.depend and (args[prefixArgName] or (i == 1 and args[v.prefix])) then
					for j,dependValue in ipairs(v.depend) do
						local dependArgName = dependValue .. tostring(i)
						preprocessSingleArg(dependArgName)
					end
				end
			end
		end
		a = a + step
	end
end

-- Parse the data parameters in the same order that the old {{infobox}} did, so
-- that references etc. will display in the expected places. Parameters that
-- depend on another parameter are only processed if that parameter is present,
-- to avoid phantom references appearing in article reference lists.
local function parseDataParameters()

	preprocessSingleArg('autoheaders')
	preprocessSingleArg('child')
	preprocessSingleArg('bodyclass')
	preprocessSingleArg('subbox')
	preprocessSingleArg('bodystyle')
	preprocessSingleArg('title')
	preprocessSingleArg('titleclass')
	preprocessSingleArg('titlestyle')
	preprocessSingleArg('above')
	preprocessSingleArg('aboveclass')
	preprocessSingleArg('abovestyle')
	preprocessArgs({
		{prefix = 'subheader', depend = {'subheaderstyle', 'subheaderrowclass'}}
	}, 10)
	preprocessSingleArg('subheaderstyle')
	preprocessSingleArg('subheaderclass')
	preprocessArgs({
		{prefix = 'image', depend = {'caption', 'imagerowclass'}}
	}, 10)
	preprocessSingleArg('captionstyle')
	preprocessSingleArg('imagestyle')
	preprocessSingleArg('imageclass')
	preprocessArgs({
		{prefix = 'header'},
		{prefix = 'data', depend = {'label'}},
		{prefix = 'rowclass'},
		{prefix = 'rowstyle'},
		{prefix = 'rowcellstyle'},
		{prefix = 'class'}
	}, 50)
	preprocessSingleArg('headerclass')
	preprocessSingleArg('headerstyle')
	preprocessSingleArg('labelstyle')
	preprocessSingleArg('datastyle')
	preprocessSingleArg('below')
	preprocessSingleArg('belowclass')
	preprocessSingleArg('belowstyle')
	preprocessSingleArg('name')
	-- different behaviour for italics if blank or absent
	args['italic title'] = origArgs['italic title']
	preprocessSingleArg('decat')
	preprocessSingleArg('templatestyles')
	preprocessSingleArg('child templatestyles')
	preprocessSingleArg('grandchild templatestyles')
end

-- If called via #invoke, use the args passed into the invoking template.
-- Otherwise, for testing purposes, assume args are being passed directly in.
function p.infobox(frame)
	if frame == mw.getCurrentFrame() then
		origArgs = frame:getParent().args
	else
		origArgs = frame
	end
	
	parseDataParameters()
	
	return _infobox()
end

-- For calling via #invoke within a template
function p.infoboxTemplate(frame)
	origArgs = {}
	for k,v in pairs(frame.args) do origArgs[k] = mw.text.trim(v) end
	
	parseDataParameters()
	
	return _infobox()
end
return p