local p = {}local args = {}local origArgs = {}local rootlocal empty_row_categories = {}local category_in_empty_row_pattern = '%[%[%s*[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]%s*:[^]]*]]'local has_rows = falselocal 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) doif not list.found thenfor _, arg in pairs(args_to_check) dofor _, pattern in ipairs(list.patterns) doif mw.ustring.find(arg or '', pattern) thenlist.found = truebreakendendif list.found then break endendendendendlocal function fixChildBoxes(sval, tt)local function notempty( s ) return s and s:match( '%S' ) endif notempty(sval) thenlocal marker = '<span class=special_infobox_marker>'local s = sval-- start moving templatestyles and categories inside of table rowslocal slast = ''while slast ~= s doslast = ss = 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 rowss = mw.ustring.gsub(s, '(<%s*[Tt][Rr])', marker .. '%1')s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>)', '%1' .. marker)if s:match(marker) thens = 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')endif s:match(marker) thenlocal subcells = mw.text.split(s, marker)s = ''for k = 1, #subcells doif k == 1 thens = s .. subcells[k] .. '</' .. tt .. '></tr>'elseif k == #subcells thenlocal rowstyle = ' style="display:none"'if notempty(subcells[k]) then rowstyle = ''ends = s .. '<tr' .. rowstyle ..'><' .. tt .. ' colspan=2>\n' ..subcells[k]elseif notempty(subcells[k]) thenif (k % 2) == 0 thens = s .. subcells[k]elses = s .. '<tr><' .. tt .. ' colspan=2>\n' ..subcells[k] .. '</' .. tt .. '></tr>'endendendend-- 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 OBEs = 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 selsereturn svalendend-- Cleans empty tableslocal function cleanInfobox()root = tostring(root)if has_rows == false thenroot = mw.ustring.gsub(root, '<table[^<>]*>%s*</table>', '')endend-- 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) dovals[v] = trueendfor k, v in pairs(t2) dovals[v] = trueendlocal ret = {}for k, v in pairs(vals) dotable.insert(ret, k)endreturn retend-- 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) dolocal num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')if num then table.insert(nums, tonumber(num)) endendtable.sort(nums)return numsend-- 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_' thenhas_rows = truehas_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 thenroot:wikitext('[[Category:Pages using infobox templates with ignored data cells]]')endelseif rowArgs.data and rowArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') thenhas_rows = truehas_list_class({ rowArgs.rowclass, rowArgs.class })local row = root:tag('tr')row:addClass(rowArgs.rowclass)row:cssText(rowArgs.rowstyle)if rowArgs.label thenrow: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()endlocal 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'))elsetable.insert(empty_row_categories, rowArgs.data or '')endendlocal function renderTitle()if not args.title then return endhas_rows = truehas_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)endlocal function renderAboveRow()if not args.above then return endhas_rows = truehas_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'))endlocal function renderBelowRow()if not args.below then return endhas_rows = truehas_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'))endlocal function addSubheaderRow(subheaderArgs)if subheaderArgs.data andsubheaderArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') thenhas_rows = truehas_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'))elsetable.insert(empty_row_categories, subheaderArgs.data or '')endendlocal function renderSubheaders()if args.subheader thenargs.subheader1 = args.subheaderendif args.subheaderrowclass thenargs.subheaderrowclass1 = args.subheaderrowclassendlocal subheadernums = getArgNums('subheader')for k, num in ipairs(subheadernums) doaddSubheaderRow({data = args['subheader' .. tostring(num)],-- @deprecated next; target .infobox-<name> .infobox-subheaderdatastyle = args.subheaderstyle,rowcellstyle = args['subheaderstyle' .. tostring(num)],class = args.subheaderclass,rowclass = args['subheaderrowclass' .. tostring(num)]})endendlocal function addImageRow(imageArgs)if imageArgs.data andimageArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') thenhas_rows = truehas_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'))elsetable.insert(empty_row_categories, imageArgs.data or '')endendlocal function renderImages()if args.image thenargs.image1 = args.imageendif args.caption thenargs.caption1 = args.captionendlocal imagenums = getArgNums('image')for k, num in ipairs(imagenums) dolocal caption = args['caption' .. tostring(num)]local data = mw.html.create():wikitext(args['image' .. tostring(num)])if caption thendata:tag('div'):addClass('infobox-caption')-- @deprecated next; target .infobox-<name> .infobox-caption:cssText(args.captionstyle):wikitext(caption)endaddImageRow({data = tostring(data),-- @deprecated next; target .infobox-<name> .infobox-imagedatastyle = args.imagestyle,class = args.imageclass,rowclass = args['imagerowclass' .. tostring(num)]})endend-- When autoheaders are turned on, preprocesses the rowslocal function preprocessRows()if not args.autoheaders then return endlocal rownums = union(getArgNums('header'), getArgNums('data'))table.sort(rownums)local lastheaderfor k, num in ipairs(rownums) doif args['header' .. tostring(num)] thenif lastheader thenargs['header' .. tostring(lastheader)] = nilendlastheader = numelseif args['data' .. tostring(num)] andargs['data' .. tostring(num)]:gsub(category_in_empty_row_pattern, ''):match('^%S') thenlocal data = args['data' .. tostring(num)]if data:gsub(category_in_empty_row_pattern, ''):match('%S') thenlastheader = nilendendendif lastheader thenargs['header' .. tostring(lastheader)] = nilendend-- Gets the union of the header and data argument numbers,-- and renders them all in orderlocal function renderRows()local rownums = union(getArgNums('header'), getArgNums('data'))table.sort(rownums)for k, num in ipairs(rownums) doaddRow({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> rowclassrowstyle = args['rowstyle' .. tostring(num)],rowcellstyle = args['rowcellstyle' .. tostring(num)]})endendlocal function renderNavBar()if not args.name then return endhas_rows = trueroot:tag('tr'):tag('td'):attr('colspan', '2'):addClass('infobox-navbar'):wikitext(require('Module:Navbar')._navbar{args.name,mini = 1,})endlocal function renderItalicTitle()local italicTitle = args['italic title'] and mw.ustring.lower(args['italic title'])if italicTitle == '' or italicTitle == 'force' or italicTitle == 'yes' thenroot:wikitext(require('Module:Italic title')._main({}))endend-- 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) doroot:wikitext(s)endend-- Render tracking categories. args.decat == turns off tracking categories.local function renderTrackingCategories()if args.decat == 'yes' then return endif args.child == 'yes' thenif args.title thenroot:wikitext('[[Category:Pages using embedded infobox templates with the title parameter]]')endelseif #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 thenroot:wikitext('[[Category:Articles using infobox templates with no data rows]]')endend--[=[Loads the templatestyles for the infobox.TODO: FINISH loading base templatestyles here rather than inMediaWiki: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 thenhlist_templatestyles = frame:extensionTag{name = 'templatestyles', args = { src = lists.hlist_t.styles }}endlocal plainlist_templatestyles = ''if lists.plainlist_t.found thenplainlist_templatestyles = frame:extensionTag{name = 'templatestyles', args = { src = lists.plainlist_t.styles }}end-- See function descriptionlocal base_templatestyles = frame:extensionTag{name = 'templatestyles', args = { src = 'Module:Infobox/styles.css' }}local templatestyles = ''if args['templatestyles'] thentemplatestyles = frame:extensionTag{name = 'templatestyles', args = { src = args['templatestyles'] }}endlocal child_templatestyles = ''if args['child templatestyles'] thenchild_templatestyles = frame:extensionTag{name = 'templatestyles', args = { src = args['child templatestyles'] }}endlocal grandchild_templatestyles = ''if args['grandchild templatestyles'] thengrandchild_templatestyles = frame:extensionTag{name = 'templatestyles', args = { src = args['grandchild templatestyles'] }}endreturn 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 pagehlist_templatestyles,plainlist_templatestyles,base_templatestyles,templatestyles,child_templatestyles,grandchild_templatestyles})end-- common functions between the child and non child caseslocal 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' thenroot = 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()elseroot = mw.html.create()root:wikitext(args.title)endstructure_infobox_common()return loadTemplateStyles() .. rootend-- 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] ~= '' thenargs[argName] = origArgs[argName]endend-- 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' thenerror("Non-table value detected for the prefix table", 2)endif type(step) ~= 'number' thenerror("Invalid step value detected", 2)end-- Get arguments without a number suffix, and check for bad input.for i,v in ipairs(prefixTable) doif type(v) ~= 'table' or type(v.prefix) ~= "string" or(v.depend and type(v.depend) ~= 'table') thenerror('Invalid input detected to preprocessArgs prefix table', 2)endpreprocessSingleArg(v.prefix)-- Only parse the depend parameter if the prefix parameter is present-- and not blank.if args[v.prefix] and v.depend thenfor j, dependValue in ipairs(v.depend) doif type(dependValue) ~= 'string' thenerror('Invalid "depend" parameter value detected in preprocessArgs')endpreprocessSingleArg(dependValue)endendend-- Get arguments with number suffixes.local a = 1 -- Counter variable.local moreArgumentsExist = truewhile moreArgumentsExist == true domoreArgumentsExist = falsefor i = a, a + step - 1 dofor j,v in ipairs(prefixTable) dolocal prefixArgName = v.prefix .. tostring(i)if origArgs[prefixArgName] then-- Do another loop if any arguments are found, even blank ones.moreArgumentsExist = truepreprocessSingleArg(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])) thenfor j,dependValue in ipairs(v.depend) dolocal dependArgName = dependValue .. tostring(i)preprocessSingleArg(dependArgName)endendendenda = a + stependend-- 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 absentargs['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() thenorigArgs = frame:getParent().argselseorigArgs = frameendparseDataParameters()return _infobox()end-- For calling via #invoke within a templatefunction p.infoboxTemplate(frame)origArgs = {}for k,v in pairs(frame.args) do origArgs[k] = mw.text.trim(v) endparseDataParameters()return _infobox()endreturn p
🔥 Top keywords: Main PageSpecial:SearchPage 3Wikipedia:Featured picturesHouse of the DragonUEFA Euro 2024Bryson DeChambeauJuneteenthInside Out 2Eid al-AdhaCleopatraDeaths in 2024Merrily We Roll Along (musical)Jonathan GroffJude Bellingham.xxx77th Tony AwardsBridgertonGary PlauchéKylian MbappéDaniel RadcliffeUEFA European Championship2024 ICC Men's T20 World CupUnit 731The Boys (TV series)Rory McIlroyN'Golo KantéUEFA Euro 2020YouTubeRomelu LukakuOpinion polling for the 2024 United Kingdom general electionThe Boys season 4Romania national football teamNicola CoughlanStereophonic (play)Gene WilderErin DarkeAntoine GriezmannProject 2025