Module:Infobox : Différence entre versions

De Lagny-sur-Marne Wiki
Aller à : navigation, rechercher
m (typo)
(build(frame))
Ligne 1 : Ligne 1 :
 +
--
 +
-- This module implements {{Infobox}}
 +
--
 +
 
local p = {}
 
local p = {}
local lang = 'fr'
 
-- variables globales alimentées par les paramètres utilisés
 
item = nil -- l'élément Wikidata lié
 
moduledata = nil -- la sous-page de module:Infobox demandéep
 
localdata = {}-- données concernant les paramètres passés au modèle
 
page = { -- données concernant la page où est affichée l'infobox
 
name = mw.title.getCurrentTitle().prefixedText,
 
namespace =  mw.title.getCurrentTitle().namespace
 
}
 
local maincolor, secondcolor, thirdcolor = '#E1E1E1', '#E1E1E1', '#000000'
 
  
-- l'objet principal à retournerp
+
local navbar = require('Module:Navbar')._navbar
local infobox = mw.html.create('div')
 
  
-- objes secondaires à retourner
+
local args = {}
local maintenance = '' -- chaîne retournfoée avec le module : cats de maintenance
+
local origArgs
local externaltext = '' -- par exemple coordonnées en titre
+
local root
-- modules importés
 
local wikidata = require('Module:Interface Wikidata').fromLua
 
local wd = require 'Module:Wikidata'
 
local defaultstyle = require "Module:Infobox/Style"
 
local mapmod = require "Module:Carte"
 
  
local i18n = {
+
local function union(t1, t2)
['see doc'] = 'Documentation du modèle',
+
    -- Returns the union of the values of two tables, as a sequence.
['edit'] = 'modifier',
+
    local vals = {}
['edit code'] = 'modifier le code',
+
    for k, v in pairs(t1) do
['edit item'] = 'modifier Wikidata',
+
        vals[v] = true
['tracking cat'] = "Page utilisant des données de Wikidata",
+
    end
['invalid block type'] = "Bloc de données invalide dans le module d'infobox",
+
    for k, v in pairs(t2) do
['default cat'] = "Maintenance des infobox",
+
        vals[v] = true
}
+
    end
 
+
    local ret = {}
local function addwikidatacat(prop)
+
    for k, v in pairs(vals) do
maintenance = maintenance .. wikidata.addtrackingcat(prop)
+
        table.insert(ret, k)
 +
    end
 +
    return ret
 
end
 
end
  
local function expandquery(query)
+
local function getArgNums(prefix)
local value, number -- valeur à retourner, nombre de valeurs pour accorder le libellé
+
    -- Returns a table containing the numbers of the arguments that exist
if not query.entity then
+
    -- for the specified prefix. For example, if the prefix was 'data', and
query.entity = item
+
    -- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}.
end
+
    local nums = {}
if not query.conjtype then
+
    for k, v in pairs(args) do
query.conjtype = 'comma'
+
        local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
end
+
        if num then table.insert(nums, tonumber(num)) end
local claims = wikidata.getClaims(query)
+
    end
if (not claims) then
+
    table.sort(nums)
return nil
+
    return nums
end
 
return wikidata.formatAndCat(query), #claims -- pour l'accord au pluriel
 
 
end
 
end
  
local function getWikidataValue(params, wikidataparam)
+
local function addRow(rowArgs)
-- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le praramètre "property"
+
    -- Adds a row to the infobox, with either a header cell
if not item then
+
    -- or a label/data cell combination.
return nil
+
    if rowArgs.header then
end
+
        root
local value, number
+
            :tag('tr')
+
                :addClass(rowArgs.rowclass)
if not wikidataparam then -- par défaut la valeur wikidata est dans le paramètre "wikidata" mais dans les structures composées comme "title", il y a plusieurs paramètres wikidata
+
                :cssText(rowArgs.rowstyle)
wikidataparam = 'wikidata'
+
                :attr('id', rowArgs.rowid)
end
+
                :tag('th')
 
+
                    :attr('colspan', 2)
if params[wikidataparam] then
+
                    :attr('id', rowArgs.headerid)
if type(params[wikidataparam]) == 'function' then
+
                    :addClass(rowArgs.class)
return params[wikidataparam](item)
+
                    :addClass(args.headerclass)
elseif type(params[wikidataparam]) == 'table' then
+
                    :css('text-align', 'center')
return expandquery(params[wikidataparam])
+
                    :cssText(args.headerstyle)
else
+
                    :wikitext(rowArgs.header)
return params[wikidataparam]
+
    elseif rowArgs.data then
end
+
        local row = root:tag('tr')
end
+
        row:addClass(rowArgs.rowclass)
 +
        row:cssText(rowArgs.rowstyle)
 +
        row:attr('id', rowArgs.rowid)
 +
        if rowArgs.label then
 +
            row
 +
                :tag('th')
 +
                    :attr('scope', 'row')
 +
                    :attr('id', rowArgs.labelid)
 +
                    :cssText(args.labelstyle)
 +
                    :wikitext(rowArgs.label)
 +
                    :done()
 +
        end
 +
       
 +
        local dataCell = row:tag('td')
 +
        if not rowArgs.label then  
 +
            dataCell
 +
                :attr('colspan', 2)
 +
                :css('text-align', 'center')  
 +
        end
 +
        dataCell
 +
            :attr('id', rowArgs.dataid)
 +
            :addClass(rowArgs.class)
 +
            :cssText(rowArgs.datastyle)
 +
            :newline()
 +
            :wikitext(rowArgs.data)
 +
    end
 
end
 
end
  
local function getvalue(val, params)
+
local function renderTitle()
if type(val) == 'string' then
+
    if not args.title then return end
return localdata[val]
 
elseif type(val) == 'function' then
 
return val(localdata, item, params)
 
elseif type(val) == 'table' then
 
for i, j in pairs(val) do -- si plusieurs paramètres possibles (legacy de vieux code), prendre le preimeir non bide
 
if localdata[j] then
 
return localdata[j]
 
end
 
end
 
end
 
end
 
  
local function addmaintenancecat(cat, sortkey)
+
    root
if page.namespace ~= 0 then
+
        :tag('caption')
return ''
+
            :addClass(args.titleclass)
end
+
            :cssText(args.titlestyle)
if cat then
+
            :wikitext(args.title)
maintenance = maintenance .. '[[Category:' .. cat .. '|' .. (sortkey or page.name) .. ']]'
 
end
 
 
end
 
end
  
function p.separator(params)
+
local function renderAboveRow()
local style = params['separator style'] or {}
+
    if not args.above then return end
style.height = style.height or '2px'
+
   
style['background-color'] = style['background-color'] or maincolor
+
    root
+
        :tag('tr')
return mw.html.create('hr'):css( style )
+
            :tag('th')
 +
                :attr('colspan', 2)
 +
                :addClass(args.aboveclass)
 +
                :css('text-align', 'center')
 +
                :css('font-size', '125%')
 +
                :css('font-weight', 'bold')
 +
                :cssText(args.abovestyle)
 +
                :wikitext(args.above)
 
end
 
end
  
function p.buildtitle(params)
+
local function renderBelowRow()
local text = getvalue(params.value, params) or params.textdefaultvalue or  getWikidataValue(params) or mw.title.getCurrentTitle().text
+
    if not args.below then return end
local subtext = getvalue(params.subtitle) or  getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue
+
   
if subtext and (subtext ~= text) then
+
    root
text = text .. '<br /><small>' .. subtext .. '</small>'
+
        :tag('tr')
end
+
            :tag('td')
local icon = params.icon or ''
+
                :attr('colspan', '2')
if icon ~= '' and not params.large then
+
                :addClass(args.belowclass)
icon = 'icon ' .. icon
+
                :css('text-align', 'center')
end
+
                :cssText(args.belowstyle)
local class = 'entete ' .. icon
+
                :newline()
+
                :wikitext(args.below)
-- overwrites with those provided in the module
 
local style = {}
 
style['background-color'] = maincolor
 
style['color'] = thirdcolor
 
if params.style then
 
for i, j in pairs(params.style) do
 
style[i] = j
 
end
 
end
 
local title = mw.html.create('div')
 
:addClass(class)
 
:css(style)
 
:tag('div')
 
:wikitext(text)
 
:allDone()
 
return title
 
 
end
 
end
  
function p.buildnavbox(params)
+
local function renderSubheaders()
+
    if args.subheader then
-- définition du style
+
        args.subheader1 = args.subheader
local class = "overflow nav " .. (params.class or '')
+
    end
local style = params.style or {}
+
    if args.subheaderrowclass then
 
+
        args.subheaderrowclass1 = args.subheaderrowclass
if params.separated then -- options pour ajouter une ligne de séparation au dessus
+
    end
style['border-top'] = '1px solid' .. maincolor
+
    local subheadernums = getArgNums('subheader')
end
+
    for k, num in ipairs(subheadernums) do
 
+
        addRow({
-- ajustement des paramètres de données
+
            data = args['subheader' .. tostring(num)],
params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète
+
            datastyle = args.subheaderstyle or args['subheaderstyle' .. tostring(num)],
params.nextval = params.nextval or params.nextparameter
+
            class = args.subheaderclass,
+
            rowclass = args['subheaderrowclass' .. tostring(num)]
if params.previousproperty then
+
        })
params.previouswikidata = {property = params.previousproperty}
+
    end
end
 
if params.nextproperty then
 
params.nextwikidata = {property = params.nextproperty}
 
end
 
 
 
 
local previousval = getvalue(params.previousval, params) or getWikidataValue(params, 'previouswikidata')
 
local nextval = getvalue(params.nextval, params) or getWikidataValue(params, 'nextwikidata')
 
 
local navbox
 
if params.inner then -- pour celles qui sont à l'intérieur d'une table
 
navbox = mw.html.create('tr'):tag('th'):attr('colspan', 2)
 
style['font-weight'] = style['font-weight'] or 'normal'
 
else
 
navbox = mw.html.create('div')
 
end
 
 
navbox
 
:addClass(class)
 
:css(style)
 
:tag('div')
 
:addClass('prev_bloc')
 
:wikitext(previousval)
 
:done()
 
:tag('div')
 
:addClass('next_bloc')
 
:wikitext(nextval)
 
:done()
 
:allDone()
 
return navbox
 
 
end
 
end
  
function p.buildimages(params)
+
local function renderImages()
local images = {}
+
    if args.image then
local upright, link, caption, size -- size is deprecated
+
        args.image1 = args.image
if type(params.imageparameters) == 'string' then
+
    end
params.imageparameters = {params.imageparameters}
+
    if args.caption then
end
+
        args.caption1 = args.caption
if not params.imageparameters then -- s'il n'y a pa de paramètre image, continuer, peut-être y-a-t-il une image par défaut définie dans le module d'infobox
+
    end
params.imageparameters = {}
+
    local imagenums = getArgNums('image')
end
+
    for k, num in ipairs(imagenums) do
for j, k in ipairs(params.imageparameters) do
+
        local caption = args['caption' .. tostring(num)]
table.insert(images, localdata[k])
+
        local data = mw.html.create():wikitext(args['image' .. tostring(num)])
end
+
        if caption then
+
            data
-- Images de Wikidata
+
                :tag('div')
if #images == 0 and item then
+
                    :cssText(args.captionstyle)
if params.property then
+
                    :wikitext(caption)
images = wikidata.getClaims{entity = item, property = params.property} or {}
+
        end
if #images > 0 then
+
        addRow({
addwikidatacat(params.property)
+
            data = tostring(data),
end
+
            datastyle = args.imagestyle,
end
+
            class = args.imageclass,
if params.wikidata then
+
            rowclass = args['imagerowclass' .. tostring(num)]
images = params.wikidata()
+
        })
if type(images) == 'string' then
+
    end
return images
 
end -- c'est probablement une erreur dans la requête => afficher le message
 
end
 
end
 
if type(images[1]) == 'table' then
 
for i, j in pairs(images) do
 
if j.mainsnak.snaktype ~= 'value' then
 
return
 
end
 
local wdcaptions, wdcaption
 
local q = images[i].qualifiers
 
if q then
 
wdcaptions = q['P2096']
 
end
 
if wdcaptions then
 
for k, l in pairs(wdcaptions) do
 
if l.datavalue.value and l.datavalue.value.language == lang then
 
wdcaption = wd.formatSnak(l)
 
end
 
end
 
end
 
if wdcaption and caption then -- si deux légendes, désactivées pour éviter les conflits
 
caption = nil
 
elseif wdcaption then
 
caption = wdcaption
 
end
 
if i > (params.numval) then
 
images[i] = nil
 
else
 
images[i] = j.mainsnak.datavalue.value
 
end
 
end
 
end
 
 
 
-- Images par défaut
 
local isdefault = false
 
if #images == 0 then
 
if params.maintenancecat then
 
local maintenancecat = getvalue(params.maintenancecat, params)
 
if maintenancecat and maintenancecat ~= '-' then
 
addmaintenancecat(maintenancecat, params.sortkey)
 
end
 
end
 
if params.defaultimages then
 
images = params.defaultimages
 
if type(images) == 'string' then
 
images = {images}
 
end
 
end
 
upright, caption, link = params.defaultimageupright, params.defaultimagecaption, params.defaultimagelink
 
end
 
if #images == 0 then
 
return nil
 
end
 
 
upright = size or getvalue(params.uprightparameter) or params.defaultupright or "1.2"
 
link = link or getvalue(params.linkparameter) or params.defaultlink
 
caption = caption or getvalue(params.captionparameter) or params.defaultcaption or ''
 
 
 
if type(size) == 'function' then
 
size = size(localdata)
 
end
 
if type(link) == 'function' then
 
link = link()
 
end
 
if type(caption) == 'function' then
 
caption = caption(localdata)
 
end
 
 
 
-- taille avec "size" (obsolète)
 
size = size or getvalue(params.sizeparameter) or params.defaultsize -- deprecated
 
if size then
 
local numsize = size:gsub('px', '')
 
numsize = mw.ustring.gsub(numsize, 'x.*', '')
 
numsize = tonumber(numsize)
 
if type(numsize) ~= 'number' or numsize > 280 then
 
addmaintenancecat("taille d'image invalide")
 
end
 
if tonumber(size) then
 
size = size .. 'px'
 
end
 
size = '|' .. size
 
else
 
size = ''
 
end
 
 
if link then
 
link = '|link=' .. link
 
else
 
link = ''
 
end
 
local style = params.style or {padding ='2px 0',}
 
 
 
-- Partie image
 
 
 
local imagesString = ''
 
for i,image in pairs(images) do
 
if image == '-' then
 
return
 
end
 
imagesString = imagesString ..  '[[Fichier:' .. image .. link .. '|frameless' .. size
 
if #images == 1 then
 
imagesString = imagesString .. '|center'
 
end
 
if upright then
 
imagesString = imagesString .. '|upright=' .. upright
 
else
 
imagesString = imagesString .. '|upright=' .. ( 1 / #images )
 
end
 
imagesString = imagesString .. ']]'
 
end
 
 
 
local image = mw.html.create('div')
 
:addClass("images")
 
:css(style)
 
:wikitext(imagesString)
 
 
 
-- Partie légende
 
local captionobj = mw.html.create('p')
 
if caption then
 
captionobj
 
:wikitext(caption)
 
:css(params.style or {})
 
:addClass("legend")
 
:done()
 
end
 
 
-- séparateur
 
local separator
 
if params.separator then
 
separator = separator(params)
 
end
 
return mw.html.create('div'):node(image):node(captionobj):node(separator):done()
 
 
end
 
end
  
function p.buildtext(params)
+
local function renderRows()
local class = params.class or ''
+
    -- Gets the union of the header and data argument numbers,
local style = defaultstyle['boldline']
+
    -- and renders them all in order using addRow.
if params.style then
+
    local rownums = union(getArgNums('header'), getArgNums('data'))
for i, j in pairs(params.style) do
+
    table.sort(rownums)
style[i] = j
+
    for k, num in ipairs(rownums) do
end
+
        addRow({
end
+
            header = args['header' .. tostring(num)],
local text = getvalue(params.value, params) or getWikidataValue(params) or params.defaultvalue
+
            label = args['label' .. tostring(num)],
if text == '-' then
+
            data = args['data' .. tostring(num)],
return
+
            datastyle = args.datastyle,
end
+
            class = args['class' .. tostring(num)],
if not text then
+
            rowclass = args['rowclass' .. tostring(num)],
addmaintenancecat(params.maintenancecat, params.sortkey)
+
            rowstyle = args['rowstyle' .. tostring(num)],
return nil
+
            dataid = args['dataid' .. tostring(num)],
end
+
            labelid = args['labelid' .. tostring(num)],
local formattedtext = mw.html.create('p')
+
            headerid = args['headerid' .. tostring(num)],
:addClass(class)
+
            rowid = args['rowid' .. tostring(num)]
:css(style)
+
        })
:wikitext(text)
+
    end
:done()
 
return formattedtext
 
 
end
 
end
  
function p.buildrow(params)
+
local function renderNavBar()
local class = params.class or ''
+
    if not args.name then return end
local style = params.style or {}
+
   
local value, number =  getvalue(params.value, params)
+
    root
if not value then
+
        :tag('tr')
value, number =  getWikidataValue(params, 'wikidata')
+
            :tag('td')
end
+
                :attr('colspan', '2')
if (not value) and (params.property) then
+
                :css('text-align', 'right')
value, number = expandquery({property = params.property})  -- the property key takes a string value,  that would not work well using the wikidata key
+
                :wikitext(navbar{
end
+
                    args.name,
if not value then
+
                    mini = 1,
value = params.defaultvalue
+
                })
end
 
if value == '-' then
 
return nil
 
end
 
if not number then
 
number = 0 -- == indéfini
 
end
 
if not value then
 
if params.maintenancecat then
 
local maintenancecat = getvalue(params.maintenancecat, params)
 
addmaintenancecat(maintenancecat, params.sortkey)
 
end
 
return nil
 
end
 
 
 
local label = params.label
 
if number > 1 and (params.plurallabel) then
 
label = params.plurallabel
 
elseif number == 1 and (params.singularlabel) then
 
label = params.singularlabel
 
end
 
if type(label) == 'function' then
 
label = label(localdata, item)
 
end
 
 
 
-- format
 
local formattedvalue = mw.html.create('div')
 
:wikitext('\n' .. value) -- Le '\n' est requis lorsque value est une liste commençant par '*' ou '#'
 
 
if (params.hidden == true)then
 
formattedvalue
 
:attr({class="NavContent", style="display: none; text-align: left;"})
 
formattedvalue = mw.html.create('div')
 
:attr({class="NavFrame", title="[Afficher]/[Masquer]", style="border: none; padding: 0;"})
 
:node(formattedvalue)
 
end
 
formattedvalue =  mw.html.create('td')
 
:node(formattedvalue)
 
:allDone()
 
 
local formattedlabel
 
if label then
 
formattedlabel = mw.html.create('th')
 
:attr('scope', 'row')
 
:wikitext(label)
 
:done()
 
end
 
local row = mw.html.create('tr')
 
:addClass(class)
 
:css(style)
 
:node(formattedlabel)
 
:node(formattedvalue)
 
:done()
 
 
return row
 
 
end
 
end
  
function p.buildsuccession(params)
+
local function renderItalicTitle()
if not params.value then
+
    local italicTitle = args['italic title'] and mw.ustring.lower(args['italic title'])
return nil
+
    if italicTitle == '' or italicTitle == 'force' or italicTitle == 'yes' then
end
+
        root:wikitext(mw.getCurrentFrame():expandTemplate({title = 'italic title'}))
+
    end
--local style = params.style or {}
 
--style['text-align'] = style['text-align'] or 'center'
 
--style['color'] = style['color'] or '#000000'
 
--style['background-color'] = style['background-color'] or '#F9F9F9'
 
 
local rowI = mw.html.create('tr')
 
 
local colspan = '2'
 
cellI = mw.html.create('td')
 
:attr({colspan = colspan})
 
:attr({align = 'center'})
 
 
local styleT = {}
 
styleT['background-color'] = 'transparent'
 
styleT['width'] = '100%'
 
tabC = mw.html.create('table')
 
:attr({cellspacing = '0'})
 
:css(styleT)
 
 
local row = mw.html.create('tr')
 
 
 
local color = params.color
 
 
 
local style = {}
 
local arrowLeft
 
local arrowRight
 
 
if color == 'default' then
 
style['background-color'] = '#E6E6E6'
 
arrowLeft = '[[Fichier:Fleche-defaut-gauche.png|13px|alt=Précédent|link=]]'
 
arrowRight = '[[Fichier:Fleche-defaut-droite.png|13px|alt=Précédent|link=]]'
 
else
 
style['background-color'] = color
 
arrowLeft = '[[Fichier:Fleche-defaut-gauche-gris-32.png|13px|alt=Suivant|link=]]'
 
arrowRight = '[[Fichier:Fleche-defaut-droite-gris-32.png|13px|alt=Suivant|link=]]'
 
end
 
 
local styleTrans = {}
 
styleTrans['background-color'] = '#F9F9F9'
 
 
local values = params.value
 
local before = values['before']
 
local center = values['center']
 
local after = values['after']
 
 
local widthCell = '44%'
 
if center then
 
widthCenter = '28%'
 
widthCell = '29%'
 
end
 
 
local formattedbefore
 
if before then
 
formattedbefore = mw.html.create('td')
 
:attr({valign = 'middle'})
 
:attr({align = 'left'})
 
:attr({width = '5%'})
 
:css(style)
 
:wikitext(arrowLeft)
 
:done()
 
row:node(formattedbefore)
 
formattedbefore = mw.html.create('td')
 
:attr({width = '1%'})
 
:css(style)
 
:wikitext('')
 
:done()
 
row:node(formattedbefore)
 
formattedbefore = mw.html.create('td')
 
:attr({align = 'left'})
 
:attr({valign = 'middle'})
 
:attr({width = widthCell})
 
:css(style)
 
:wikitext(before)
 
:done()
 
row:node(formattedbefore)
 
else
 
formattedbefore = mw.html.create('td')
 
:attr({valign = 'middle'})
 
:attr({align = 'left'})
 
:attr({width = '5%'})
 
:css(styleTrans)
 
:wikitext('')
 
:done()
 
row:node(formattedbefore)
 
formattedbefore = mw.html.create('td')
 
:attr({width = '1%'})
 
:css(styleTrans)
 
:wikitext('')
 
:done()
 
row:node(formattedbefore)
 
formattedbefore = mw.html.create('td')
 
:attr({align = 'left'})
 
:attr({valign = 'middle'})
 
:attr({width = widthCell})
 
:css(styleTrans)
 
:wikitext('')
 
:done()
 
row:node(formattedbefore)
 
end
 
 
local formattedcenter
 
formattedcenter = mw.html.create('td')
 
:attr({width = '1%'})
 
:css(styleTrans)
 
:wikitext('')
 
:done()
 
row:node(formattedcenter)
 
 
if center then
 
formattedcenter = mw.html.create('td')
 
:attr({align = 'center'})
 
:attr({valign = 'middle'})
 
:attr({width = widthCenter})
 
:css(style)
 
:wikitext(center)
 
:done()
 
row:node(formattedcenter)
 
formattedcenter = mw.html.create('td')
 
:attr({width = '1%'})
 
:css(styleTrans)
 
:wikitext('')
 
:done()
 
row:node(formattedcenter)
 
end
 
 
local formattedafter
 
if after then
 
formattedafter = mw.html.create('td')
 
:attr({align = 'right'})
 
:attr({valign = 'middle'})
 
:attr({width = widthCell})
 
:css(style)
 
:wikitext(after)
 
:done()
 
row:node(formattedafter)
 
formattedbefore = mw.html.create('td')
 
:attr({width = '1%'})
 
:css(style)
 
:wikitext('')
 
:done()
 
row:node(formattedbefore)
 
formattedafter = mw.html.create('td')
 
:attr({align = 'right'})
 
:attr({valign = 'middle'})
 
:attr({width = '5%'})
 
:css(style)
 
:wikitext(arrowRight)
 
:done()
 
row:node(formattedafter)
 
else
 
formattedafter = mw.html.create('td')
 
:attr({align = 'right'})
 
:attr({valign = 'middle'})
 
:attr({width = widthCell})
 
:css(styleTrans)
 
:wikitext('')
 
:done()
 
row:node(formattedafter)
 
formattedbefore = mw.html.create('td')
 
:attr({width = '1%'})
 
:css(styleTrans)
 
:wikitext('')
 
:done()
 
row:node(formattedbefore)
 
formattedafter = mw.html.create('td')
 
:attr({align = 'right'})
 
:attr({valign = 'middle'})
 
:attr({width = '5%'})
 
:css(styleTrans)
 
:wikitext('')
 
:done()
 
row:node(formattedafter)
 
end
 
 
row:done()
 
tabC:node(row)
 
tabC:done()
 
cellI:node(tabC)
 
cellI:done()
 
rowI:node(cellI)
 
rowI:allDone()
 
 
return rowI
 
 
end
 
end
  
function p.buildrow1col(params)
+
local function renderTrackingCategories()
+
    if args.decat ~= 'yes' then
if not params.value then
+
        if #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then
return nil
+
            root:wikitext('[[Category:Articles which use infobox templates with no data rows]]')
end
+
        end
+
        if args.child == 'yes' and args.title then
--local style = params.style or {}
+
            root:wikitext('[[Category:Pages which use embedded infobox templates with the title parameter]]')
--style['text-align'] = style['text-align'] or 'center'
+
        end
--style['color'] = style['color'] or '#000000'
+
    end
--style['background-color'] = style['background-color'] or '#F9F9F9'
 
 
local rowcolor
 
if params.color == 'secondcolor' then
 
rowcolor = secondcolor
 
else
 
rowcolor = params.color
 
end
 
 
local style = {}
 
style['padding'] = '4px'
 
style['text-align'] = 'center'
 
style['background-color'] = rowcolor or '#F9F9F9'
 
style['color'] = '#000000'
 
 
local text = params.value
 
 
 
local colspan ='2'
 
 
 
local formattedlabel
 
formattedlabel = mw.html.create('th')
 
:attr({colspan = colspan})
 
:css(style)
 
:wikitext(text)
 
:done()
 
 
 
local row = mw.html.create('tr')
 
:addClass(class)
 
:css(style)
 
:node(formattedlabel)
 
:done()
 
 
return row
 
 
end
 
end
  
function p.buildtable(params)
+
local function _infobox()
local tab = mw.html.create('table'):css(params.style or {})
+
    -- Specify the overall layout of the infobox, with special settings
 +
    -- if the infobox is used as a 'child' inside another infobox.
 +
    if args.child ~= 'yes' then
 +
        root = mw.html.create('table')
 +
       
 +
        root
 +
            :addClass('infobox')
 +
            :addClass(args.bodyclass)
 +
           
 +
            if args.subbox == 'yes' then
 +
                root
 +
                    :css('padding', '0')
 +
                    :css('border', 'none')
 +
                    :css('margin', '-3px')
 +
                    :css('width', 'auto')
 +
                    :css('min-width', '100%')
 +
                    :css('font-size', '100%')
 +
                    :css('clear', 'none')
 +
                    :css('float', 'none')
 +
                    :css('background-color', 'transparent')
 +
            else
 +
                root
 +
                    :css('width', '22em')
 +
            end
 +
        root
 +
            :cssText(args.bodystyle)
 +
   
 +
        renderTitle()
 +
        renderAboveRow()
 +
    else
 +
        root = mw.html.create()
 +
       
 +
        root
 +
            :wikitext(args.title)
 +
    end
  
-- CREATE ROWS
+
    renderSubheaders()
local rows = {}
+
    renderImages()  
for k, l in pairs(params.rows) do
+
    renderRows()  
if type(l) == 'table' and l.type == 'multi' then -- when a single function is used for return several rows
+
    renderBelowRow()
table.remove(params.rows, k)
+
    renderNavBar()
local count = 0
+
    renderItalicTitle()
for m, n in pairs(l.rows) do
+
    renderTrackingCategories()
table.insert(params.rows, k + count, n)
+
   
count = count + 1
+
    return tostring(root)
end
 
l = params.rows[k]
 
end
 
 
 
if type(l) == 'function' then --accepte les fonctions qui retournent des tables
 
l = l(localdata, item)
 
end
 
if type(l) == 'nil' then
 
--ne rien faire (quand la valeur est originellemenet une fonctin elle peut retourner nil)
 
elseif type(l) ~= 'table' then
 
return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l))
 
else
 
local row = p.buildblock(l)
 
table.insert(rows, row)
 
end
 
end
 
if #rows == 0 then
 
return nil
 
end
 
 
 
-- ADD TITLE
 
local title
 
if params.title or params.singulartitle or params.pluraltitle then
 
local text
 
if #rows > 1 and params.pluraltitle then
 
text = pluraltitle
 
elseif #rows == 1 and params.singulartitle then
 
text = pluraltitle
 
else
 
text = params.title
 
end
 
 
 
local style = params.titlestyle or {}
 
style['text-align'] = style['text-align'] or 'center'
 
style['color'] = style['color'] or thirdcolor
 
style['background-color'] = style['background-color'] or maincolor
 
 
 
local colspan ='2'
 
title = mw.html.create('caption')
 
:attr({colspan = colspan})
 
:css(style)
 
:wikitext(text)
 
:done()
 
end
 
 
if title then
 
tab:node(title)
 
end
 
 
for i, j in pairs (rows) do
 
tab:node(j)
 
end
 
 
if params.separator then
 
local separator = p.separator(params)
 
tab:node(separator)
 
end
 
tab:allDone()
 
return tab
 
end
 
 
 
function p.buildinvalidblock(args)
 
addmaintenancecat(defaultcat)
 
local text = ''
 
if type(args) ~= 'table' then
 
text = "Les blocs d'infobox doivent être des tables"
 
else
 
text = i18n["invalid block type"] .. ' : ' .. (args.type or '??')
 
end
 
return text
 
 
end
 
end
  
function p.buildmap(params)-- TODO  : gestion de plusieurs points
+
local function preprocessSingleArg(argName)
 
+
    -- If the argument exists and isn't blank, add it to the argument table.
-- paramètre d'affichage
+
    -- Blank arguments are treated as nil to match the behaviour of ParserFunctions.
local maplist = getvalue(params.maps)
+
    if origArgs[argName] and origArgs[argName] ~= '' then
local pointtype = params.pointtype
+
        args[argName] = origArgs[argName]
local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.)
+
    end
if type(maplist) == 'function' then
 
maplist = maplist(localdata, item)
 
end
 
local width = tonumber(params.width) or 280
 
if width > 280 then
 
addmaintenancecat("Erreur d'Infobox/Image trop grande")
 
return 'image trop grande, la largeur doit être inférieure ou égale à 280px'
 
end
 
 
 
-- récupération des données locales
 
local latitude, longitude, globe = params.latitude, params.longitude, params.globe
 
if type(params.latitude) == 'function' then
 
latitude, longitude = params.latitude(localdata, item), params.longitude(localdata, item)
 
else
 
latitude, longitude = localdata[params.latitude], localdata[params.longitude]
 
end
 
 
-- récupération des données wikidata
 
if (not latitude or not longitude) and params.wikidata then
 
local query = params.wikidata
 
if type(query) == 'function' then
 
query = query()
 
end
 
if not query then
 
return nil
 
end
 
query.excludespecial = true
 
query.entity = query.entity or item
 
local claims = wikidata.getClaims(query)
 
if not claims then
 
return nil
 
end
 
local val = claims[1].mainsnak.datavalue.value
 
latitude, longitude, globe = val.latitude, val.longitude, val.globe
 
end
 
 
if not latitude or not longitude then
 
return nil
 
end
 
local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = item, latitude = latitude, longitude = longitude, globe = globe}
 
if params.params and type(params.params) == 'table' then -- paramètres additionnels
 
for i, j in pairs(params.params) do
 
newparams[i] = j
 
end
 
end
 
return mapmod.multimap(newparams)
 
 
end
 
end
  
function p.buildfooter(params)
+
local function preprocessArgs(prefixTable, step)
if not params then
+
    -- Assign the parameters with the given prefixes to the args table, in order, in batches
params = {}
+
    -- of the step size specified. This is to prevent references etc. from appearing in the
end
+
    -- 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
local class = 'navbar noprint ' .. (params.class or '')
+
    -- parameters containing the "prefix" string, but only parses parameters in the "depend"
local style = params.style or {}
+
    -- table if the prefix parameter is present and non-blank.
style['border-top'] = style['border-top'] or '1px solid ' .. maincolor
+
    if type(prefixTable) ~= 'table' then
+
        error("Non-table value detected for the prefix table", 2)
local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.name, '&veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']'
+
    end
.. ' - [' .. tostring( mw.uri.fullUrl( page.name, '&action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'
+
    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
  
local itemlinkstr
+
    -- Get arguments with number suffixes.
if item then
+
    local a = 1 -- Counter variable.
itemlinkstr = '[[d:' .. item.id .. '|' .. i18n['edit item'] .. ']]'
+
    local moreArgumentsExist = true
end
+
    while moreArgumentsExist == true do
local editstr = backlinkstr
+
        moreArgumentsExist = false
if itemlinkstr then
+
        for i = a, a + step - 1 do
editstr = editstr .. ' - ' .. itemlinkstr
+
            for j,v in ipairs(prefixTable) do
end
+
                local prefixArgName = v.prefix .. tostring(i)
local editlinkspan = mw.html.create('span')
+
                if origArgs[prefixArgName] then
:css({['text-align'] = "left"})
+
                    moreArgumentsExist = true -- Do another loop if any arguments are found, even blank ones.
:addClass('plainlinks')
+
                    preprocessSingleArg(prefixArgName)
:wikitext(editstr)
+
                end
:done()
+
                -- Process the depend table if the prefix argument is present and not blank, or
local doclinkstr = '[[Image:Info Simple.svg|12px|link=' .. localdata.templatename .. '|' .. i18n['see doc'] .. ']]'
+
                -- we are processing "prefix1" and "prefix" is present and not blank, and
-- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame
+
                -- if the depend table is present.
local doclinkspan = mw.html.create('span')
+
                if v.depend and (args[prefixArgName] or (i == 1 and args[v.prefix])) then
:css({['text-align'] = "right"})
+
                    for j,dependValue in ipairs(v.depend) do
:wikitext(doclinkstr)
+
                        local dependArgName = dependValue .. tostring(i)
:done()
+
                        preprocessSingleArg(dependArgName)
+
                    end
local footer = mw.html.create('p')
+
                end
:addClass(class)
+
            end
:css(style)
+
        end
:node(editlinkspan)
+
        a = a + step
:node(doclinkspan)
+
    end
return footer
 
 
end
 
end
 
+
function p.buildblock(block)
+
function p.infobox(frame)
if type(block) == 'function' then
+
    -- If called via #invoke, use the args passed into the invoking template.
block = block()
+
    -- Otherwise, for testing purposes, assume args are being passed directly in.
end
+
    if frame == mw.getCurrentFrame() then
 
+
        origArgs = frame:getParent().args
local blocktypes = { -- list of functions for block buildings
+
    else
['invalid'] = p.buildinvalidblock,
+
        origArgs = frame
['external text'] = p.buildexternaltext,
+
    end
['footer'] = p.buildfooter,
+
   
['images'] = p.buildimages,
+
    -- Parse the data parameters in the same order that the old {{infobox}} did, so that
['map']= p.buildmap,
+
    -- references etc. will display in the expected places. Parameters that depend on
['mixed'] = p.buildrow,
+
    -- another parameter are only processed if that parameter is present, to avoid
['navbox'] = p.buildnavbox,
+
    -- phantom references appearing in article reference lists.
['table'] = p.buildtable,
+
    preprocessSingleArg('child')
['row'] = p.buildrow,
+
    preprocessSingleArg('bodyclass')
['row1col'] = p.buildrow1col,
+
    preprocessSingleArg('subbox')
['succession'] = p.buildnavbox,
+
    preprocessSingleArg('bodystyle')
['text'] = p.buildtext,
+
    preprocessSingleArg('title')
['title'] = p.buildtitle,
+
    preprocessSingleArg('titleclass')
}
+
    preprocessSingleArg('titlestyle')
if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then
+
    preprocessSingleArg('above')
return blocktypes['invalid'](block)
+
    preprocessSingleArg('aboveclass')
end
+
    preprocessSingleArg('abovestyle')
return blocktypes[block.type](block)  
+
    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 = 'class'},
 +
        {prefix = 'dataid'},
 +
        {prefix = 'labelid'},
 +
        {prefix = 'headerid'},
 +
        {prefix = 'rowid'}
 +
    }, 50)
 +
    preprocessSingleArg('headerclass')
 +
    preprocessSingleArg('headerstyle')
 +
    preprocessSingleArg('labelstyle')
 +
    preprocessSingleArg('datastyle')
 +
    preprocessSingleArg('below')
 +
    preprocessSingleArg('belowclass')
 +
    preprocessSingleArg('belowstyle')
 +
    preprocessSingleArg('name')
 +
    args['italic title'] = origArgs['italic title'] -- different behaviour if blank or absent
 +
    preprocessSingleArg('decat')
 +
 +
    return _infobox()
 
end
 
end
 
+
   
function p._build(modulename, params, templatename)
 
 
 
-- fill-up global variable localdata using params
 
for i, j in pairs(params) do
 
if j and mw.text.trim(j) ~= '' then -- empty parameters are ignored
 
localdata[i] = j
 
end
 
end
 
localdata.templatename = templatename or modulename
 
 
 
-- load wikidata item as a global variable:
 
if localdata.wikidata == '-' then
 
item = nil
 
else
 
item = wikidata.getEntity(localdata.wikidata)
 
end
 
 
-- assign rank to the infobox, "secondary" means special formatting like no displaytitle for coordinates
 
local infoboxrank = 'main' -- main infobox of the page, with coordinates displayed in title etc.
 
if page.namespace ~= 0 then
 
infoboxrank = 'secondary'
 
end
 
-- if infobox is linked to another item: rank = secondary
 
if item then
 
local itemlink = mw.wikibase.sitelink(item.id)
 
local pagetitle = mw.title.getCurrentTitle().text
 
if (itemlink or '') ~= pagetitle then
 
infoboxrank = 'secondary'
 
end
 
end
 
localdata.infoboxrank = infoboxrank
 
 
 
-- load infobox module page
 
moduledata = require('Module:Infobox/' .. modulename)
 
moduledata.name = modulename
 
-- defines main color
 
maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or moduledata.maincolor or maincolor
 
secondcolor = moduledata.secondcolor or secondcolor
 
thirdcolor =  moduledata.thirdcolor or thirdcolor
 
if maincolor:match( '^%x%x%x%x%x%x$' ) or maincolor:match( '^%x%x%x$' ) then
 
maincolor = '#' .. maincolor
 
end
 
 
-- class
 
local class = 'infobox_v3'
 
if moduledata.class then
 
class = class .. ' ' .. moduledata.class
 
end
 
 
-- style
 
local style = moduledata.style or {}
 
if not style['max-width'] then
 
style['max-width'] = '300px'
 
end
 
 
-- build infobox
 
infobox :addClass(class)
 
:css(style)
 
for i, j in pairs( moduledata.parts ) do
 
infobox:node( p.buildblock(j) )
 
end
 
infobox :node(p.buildfooter(moduledata.footer))
 
:done()
 
 
 
return tostring(infobox) .. externaltext, maintenance
 
end
 
 
 
function p.build(frame)
 
local name =  frame.args.nom
 
local parent = frame:getParent()
 
local templatename = parent:getTitle() -- au cas où il soit différent du nom du module
 
local params = parent.args
 
return p._build(name, params, templatename)
 
end
 
 
 
 
return p
 
return p

Version du 12 mars 2016 à 11:02

La documentation pour ce module peut être créée à Module:Infobox/doc

--
-- This module implements {{Infobox}}
--
 
local p = {}

local navbar = require('Module:Navbar')._navbar

local args = {}
local origArgs
local root

local function union(t1, t2)
    -- Returns the union of the values of two tables, as a sequence.
    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

local function getArgNums(prefix)
    -- 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 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

local function addRow(rowArgs)
    -- Adds a row to the infobox, with either a header cell
    -- or a label/data cell combination.
    if rowArgs.header then
        root
            :tag('tr')
                :addClass(rowArgs.rowclass)
                :cssText(rowArgs.rowstyle)
                :attr('id', rowArgs.rowid)
                :tag('th')
                    :attr('colspan', 2)
                    :attr('id', rowArgs.headerid)
                    :addClass(rowArgs.class)
                    :addClass(args.headerclass)
                    :css('text-align', 'center')
                    :cssText(args.headerstyle)
                    :wikitext(rowArgs.header)
    elseif rowArgs.data then
        local row = root:tag('tr')
        row:addClass(rowArgs.rowclass)
        row:cssText(rowArgs.rowstyle)
        row:attr('id', rowArgs.rowid)
        if rowArgs.label then
            row
                :tag('th')
                    :attr('scope', 'row')
                    :attr('id', rowArgs.labelid)
                    :cssText(args.labelstyle)
                    :wikitext(rowArgs.label)
                    :done()
        end
        
        local dataCell = row:tag('td')
        if not rowArgs.label then 
            dataCell
                :attr('colspan', 2)
                :css('text-align', 'center') 
        end
        dataCell
            :attr('id', rowArgs.dataid)
            :addClass(rowArgs.class)
            :cssText(rowArgs.datastyle)
            :newline()
            :wikitext(rowArgs.data)
    end
end

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

    root
        :tag('caption')
            :addClass(args.titleclass)
            :cssText(args.titlestyle)
            :wikitext(args.title)
end

local function renderAboveRow()
    if not args.above then return end
    
    root
        :tag('tr')
            :tag('th')
                :attr('colspan', 2)
                :addClass(args.aboveclass)
                :css('text-align', 'center')
                :css('font-size', '125%')
                :css('font-weight', 'bold')
                :cssText(args.abovestyle)
                :wikitext(args.above)
end

local function renderBelowRow()
    if not args.below then return end
    
    root
        :tag('tr')
            :tag('td')
                :attr('colspan', '2')
                :addClass(args.belowclass)
                :css('text-align', 'center')
                :cssText(args.belowstyle)
                :newline()
                :wikitext(args.below)
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
        addRow({
            data = args['subheader' .. tostring(num)],
            datastyle = args.subheaderstyle or args['subheaderstyle' .. tostring(num)],
            class = args.subheaderclass,
            rowclass = args['subheaderrowclass' .. tostring(num)]
        })
    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')
                    :cssText(args.captionstyle)
                    :wikitext(caption)
        end
        addRow({
            data = tostring(data),
            datastyle = args.imagestyle,
            class = args.imageclass,
            rowclass = args['imagerowclass' .. tostring(num)]
        })
    end
end

local function renderRows()
    -- Gets the union of the header and data argument numbers,
    -- and renders them all in order using addRow.
    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)],
            rowstyle = args['rowstyle' .. tostring(num)],
            dataid = args['dataid' .. tostring(num)],
            labelid = args['labelid' .. tostring(num)],
            headerid = args['headerid' .. tostring(num)],
            rowid = args['rowid' .. tostring(num)]
        })
    end
end

local function renderNavBar()
    if not args.name then return end
    
    root
        :tag('tr')
            :tag('td')
                :attr('colspan', '2')
                :css('text-align', 'right')
                :wikitext(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(mw.getCurrentFrame():expandTemplate({title = 'italic title'}))
    end
end

local function renderTrackingCategories()
    if args.decat ~= 'yes' then
        if #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then
            root:wikitext('[[Category:Articles which use infobox templates with no data rows]]')
        end
        if args.child == 'yes' and args.title then
            root:wikitext('[[Category:Pages which use embedded infobox templates with the title parameter]]')
        end
    end
end

local function _infobox()
    -- Specify the overall layout of the infobox, with special settings
    -- if the infobox is used as a 'child' inside another infobox.
    if args.child ~= 'yes' then
        root = mw.html.create('table')
        
        root
            :addClass('infobox')
            :addClass(args.bodyclass)
            
            if args.subbox == 'yes' then
                root
                    :css('padding', '0')
                    :css('border', 'none')
                    :css('margin', '-3px')
                    :css('width', 'auto')
                    :css('min-width', '100%')
                    :css('font-size', '100%')
                    :css('clear', 'none')
                    :css('float', 'none')
                    :css('background-color', 'transparent')
            else
                root
                    :css('width', '22em')
            end
        root
            :cssText(args.bodystyle)
    
        renderTitle()
        renderAboveRow()
    else
        root = mw.html.create()
        
        root
            :wikitext(args.title)
    end

    renderSubheaders()
    renderImages() 
    renderRows() 
    renderBelowRow()  
    renderNavBar()
    renderItalicTitle()
    renderTrackingCategories()
    
    return tostring(root)
end

local function preprocessSingleArg(argName)
    -- 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.
    if origArgs[argName] and origArgs[argName] ~= '' then
        args[argName] = origArgs[argName]
    end
end

local function preprocessArgs(prefixTable, step)
    -- 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.
    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
                    moreArgumentsExist = true -- Do another loop if any arguments are found, even blank ones.
                    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
 
function p.infobox(frame)
    -- If called via #invoke, use the args passed into the invoking template.
    -- Otherwise, for testing purposes, assume args are being passed directly in.
    if frame == mw.getCurrentFrame() then
        origArgs = frame:getParent().args
    else
        origArgs = frame
    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.
    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 = 'class'},
        {prefix = 'dataid'},
        {prefix = 'labelid'},
        {prefix = 'headerid'},
        {prefix = 'rowid'}
    }, 50)
    preprocessSingleArg('headerclass')
    preprocessSingleArg('headerstyle')
    preprocessSingleArg('labelstyle')
    preprocessSingleArg('datastyle')
    preprocessSingleArg('below')
    preprocessSingleArg('belowclass')
    preprocessSingleArg('belowstyle')
    preprocessSingleArg('name')
    args['italic title'] = origArgs['italic title'] -- different behaviour if blank or absent
    preprocessSingleArg('decat')
 
    return _infobox()
end
 
return p