Aller au contenu

Modèle:Infobox/doc

De Wikisica

{{#ifeq:doc |doc

    | 

{{#ifeq:show |show

|

        }}{{#if: |
         |   {{#ifexist:Modèle:Infobox
                  | [[Category:{{#switch:Modèle |Template=Template |Module=Module |User=User |#default=Wikipedia}} documentation pages]]
                  | 
                 }}
        }}
    | 
   }}

{{#ifeq:doc|sandbox||

}}

local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p

Template:Infobox is intended as a meta template: a template used for constructing other templates. Note: In general, it is not meant for use directly in an article, but can be used on a one-off basis if required. Help:Infobox contains an introduction about the recommended content and design of infoboxes; Wikipedia:Manual of Style/Infoboxes contains additional style guidelines. See WP:List of infoboxes and Category:Infobox templates for lists of prepared topic-specific infoboxes.

Usage

{{Infobox}} is a meta-template: used to organise an actual {{Infobox sometopic}} template (like {{Infobox building}}).

For [[Template:Infobox sometopic]], template code then looks like this, simplified: <syntaxhighlight lang="wikitext"> local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p </syntaxhighlight>

Optional control parameters

name
If this parameter is present, "view, talk and edit" links will be added to the bottom of the infobox pointing to the named page, prefixed by Template: if no namespace is specified. You may use the value {{subst:PAGENAME}}; however, this is rarely what you want because it will send users clicking these links in an infobox to the template code rather than the data in the infobox they probably want to change.
child
See the Embedding section for details. If this is set to "yes", this child infobox should be titled but have no name parameter. This parameter is empty by default, set it to "yes" to activate it.
subbox
See the Subboxes section for details. If this is set to "yes", this subbox should be titled but have no name parameter. This parameter is empty by default, set to "yes" to activate it. It has no effect if the |{{SAFESUBST:#if:child|child=}} parameter is also set to "yes".
decat
If this is set to "yes", the current page will not be autocategorized in a maintenance category when the generated infobox has some problems or no visible data section. Leave empty by default or set to "yes" to activate it.
autoheaders
If this is set to any non-blank value, headers which are not followed by data fields are suppressed. See the "hiding headers when all its data fields are empty" section for more details.

Content parameters

Title

There are two different ways to put a title on an infobox. One contains the title inside the infobox's border in the uppermost cell of the table, the other puts it as a caption on top of the table. You can use them both together, or just one or the other, or neither (though this is not recommended):

title
Text to put in the caption over the top of the table (or as section header before the whole content of this table, if this is a child infobox). For accessibility reasons, this is the most recommended alternative.
above
Text to put within the uppermost cell of the table.
subheader(n)
additional title fields which fit below |{{SAFESUBST:#if:title|title=}}} and |{{SAFESUBST:#if:above|above=}}}, but before images.

Examples:

local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p <syntaxhighlight lang="wikitext" style="overflow: auto;"> local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p </syntaxhighlight>

local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p <syntaxhighlight lang="wikitext" style="overflow: auto;"> local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p </syntaxhighlight>

Illustration images

image(n)
images to display at the top of the template. Use full image syntax, for example [[File:example.png|200px|alt=Example alt text]]. Image is centered by default. See WP:ALT for more on alt text.
caption(n)
Text to put underneath the images.

Main data

header(n)
Text to use as a header in row n.
label(n)
Text to use as a label in row n.
data(n)
Text to display as data in row n.

Note: for any given value for (n), not all combinations of parameters are permitted. The presence of a |{{SAFESUBST:#if:header(n)|header(n)=}} will cause the corresponding |{{SAFESUBST:#if:data(n)|data(n)=}} (and |{{SAFESUBST:#if:rowclass(n)|rowclass(n)=}} |{{SAFESUBST:#if:label(n)|label(n)=}}, see below) to be ignored; the absence of a |{{SAFESUBST:#if:data(n)|data(n)=}} will cause the corresponding |{{SAFESUBST:#if:label(n)|label(n)=}} to be ignored. Valid combinations for any single row are:

  • |{{SAFESUBST:#if:class(n)|class(n)=}} |{{SAFESUBST:#if:header(n)|header(n)=}}
  • |{{SAFESUBST:#if:rowclass(n)|rowclass(n)=}} |{{SAFESUBST:#if:class(n)|class(n)=}} |{{SAFESUBST:#if:data(n)|data(n)=}}
  • |{{SAFESUBST:#if:rowclass(n)|rowclass(n)=}} |{{SAFESUBST:#if:label(n)|label(n)=}} |{{SAFESUBST:#if:class(n)|class(n)=}} |{{SAFESUBST:#if:data(n)|data(n)=}}

See the rendering of header4, label4, and data4 in the Examples section below.

Number ranges

To allow flexibility when the layout of an infobox is changed, it may be helpful when developing an infobox to use non-contiguous numbers for header and label/data rows. Parameters for new rows can then be inserted in future without having to renumber existing parameters. For example:

<syntaxhighlight lang="wikitext" style="overflow: auto;">

| header3  = Section 1
|  label5  = Label A
|   data5  = Data A
|  label7  = Label C
|   data7  = Data C
| header10 = Section 2
|  label12 = Label D
|   data12 = Data D

</syntaxhighlight>

It is also possible to automatically renumber parameter names by using User:Frietjes/infoboxgap.js or Module:IncrementParams.

There is no upper limit on numbers but there must be at most 50 between each used number.

Making data fields optional

A row with a label but no data is not displayed. This allows for the easy creation of optional infobox content rows. To make a row optional use a parameter that defaults to an empty string, like so:

<syntaxhighlight lang="wikitext" style="overflow: auto;">

| label5 = Population
|  data5 = 

</syntaxhighlight>

This way if an article doesn't define the population parameter in its infobox the row won't be displayed.

For more complex fields with pre-formatted contents that would still be present even if the parameter wasn't set, you can wrap it all in an "#if" statement to make the whole thing vanish when the parameter is not used. For instance, the "#if" statement in the following example reads "#if:the parameter mass has been supplied |then display it, followed by 'kg'":

<syntaxhighlight lang="wikitext" style="overflow: auto;">

| label6 = Mass
|  data6 = {{ #if:  | {{{mass}}} kg }}

</syntaxhighlight>

For more on #if, see here.

Hiding headers when all its data fields are empty

You can also make headers automatically hide when their section is empty (has no data-row showing).

Consider this situation: local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p <syntaxhighlight lang="wikitext" style="overflow: auto;"> local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p </syntaxhighlight>

If you want hide the header when no |{{SAFESUBST:#if:dataN|dataN=}} values are present, use |{{SAFESUBST:#if:autoheaders|autoheaders=}}y:

local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p

<syntaxhighlight lang="wikitext" style="overflow: auto;"> local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p </syntaxhighlight>

So, header1 will be shown if any of item1, item2, or item3 is defined. If none of the three parameters are defined the header won't be shown and no empty row appears before the next visible content.

Note: if the data has empty css elements, like |{{SAFESUBST:#if:data|data=}}<span style="background:yellow;"></span>, this will be treated as non-empty (having data).

If |{{SAFESUBST:#if:autoheaders|autoheaders=}}y but there are items that you do not want to trigger a header, place |{{SAFESUBST:#if:headerX|headerX=}}_BLANK_. This will serve as an empty header and separate it from the subsequent items.

local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p

<syntaxhighlight lang="wikitext" style="overflow: auto;"> local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p </syntaxhighlight>

Footer

below
Text to put in the bottom cell. The bottom cell is intended for footnotes, see-also, and other such information.

Presentation parameters

Italic titles

Titles of articles with infoboxes may be made italic, in line with WP:ITALICTITLE, by passing the italic title parameter.

  • Turn on italic titles by passing |{{SAFESUBST:#if:italic title|italic title=}}{{{italic title|}}} from the infobox.
  • Turn off by default (notably because only Latin script may be safely rendered in this style and italic may be needed to distinguish foreign language from local English language only in that script, but would be difficult to read for other scripts) but allow some instances to be made italic by passing |{{SAFESUBST:#if:italic title|italic title=}}{{{italic title|no}}}
  • Do not make any titles italic by not passing the parameter at all.

CSS styling

{{#if:|{{{content}}}

}}{{#ifeq:|yes|}}

bodystyle
Applies to the infobox table as a whole
titlestyle
Applies only to the title caption. Adding a background color is usually inadvisable since the text is rendered "outside" the infobox.
abovestyle
Applies only to the "above" cell at the top. The default style has font-size:125%; since this cell is usually used for a title, if you want to use the above cell for regular-sized text include "font-size:100%;" in the abovestyle.
imagestyle
Applies to the cell the image is in. This includes the text of the image caption, but you should set text properties with captionstyle instead of imagestyle in case the caption is moved out of this cell in the future.
captionstyle
Applies to the text of the image caption.
rowstyle(n)
This parameter is inserted into the style attribute for the specified row.
headerstyle
Applies to all header cells
subheaderstyle
Applies to all subheader cells
labelstyle
Applies to all label cells
datastyle
Applies to all data cells
belowstyle
Applies only to the below cell

HTML classes and microformats

{{#if:|{{{content}}}

}}{{#ifeq:|yes|}}

bodyclass
This parameter is inserted into the class attribute for the infobox as a whole.
titleclass
This parameter is inserted into the class attribute for the infobox's title caption.
aboveclass
This parameter is inserted into the class attribute for the infobox's above cell.
subheaderrowclass(n)
This parameter is inserted into the class attribute for the complete table row the subheader is on.
subheaderclass(n)
This parameter is inserted into the class attribute for the infobox's subheader.
imagerowclass(n)
These parameters are inserted into the class attribute for the complete table row their respective image is on.
imageclass
This parameter is inserted into the class attribute for the image.
rowclass(n)
This parameter is inserted into the class attribute for the specified row including the label and data cells.
class(n)
This parameter is inserted into the class attribute for the data cell of the specified row. If there's no data cell it has no effect.
belowclass
This parameter is inserted into the class attribute for the infobox's below cell.

This template supports the addition of microformat information. This is done by adding "class" attributes to various data cells, indicating what kind of information is contained within. Multiple class names may be specified, separated by spaces, some of them being used as selectors for custom styling according to a project policy or to the skin selected in user preferences, others being used for microformats.

To flag an infobox as containing hCard information, for example, add the following parameter:

<syntaxhighlight lang="wikitext" style="overflow: auto;">

| bodyclass = vcard

</syntaxhighlight>

And for each row containing a data cell that's part of the vcard, add a corresponding class parameter:

<syntaxhighlight lang="wikitext" style="overflow: auto;">

| class1 = fn
| class2 = org
| class3 = tel

</syntaxhighlight>

...and so forth. "above" and "title" can also be given classes, since these are usually used to display the name of the subject of the infobox.

See Wikipedia:WikiProject Microformats for more information on adding microformat information to Wikipedia, and microformat for more information on microformats in general.

Examples

Notice how the row doesn't appear in the displayed infobox when a label is defined without an accompanying data cell, and how all of them are displayed when a header is defined on the same row as a data cell. Also notice that subheaders are not bold by default like the headers used to split the main data section, because this role is meant to be for the above cell :

local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p

<syntaxhighlight lang="wikitext"> local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p </syntaxhighlight> For this example, the |{{SAFESUBST:#if:bodystyle|bodystyle=}} and |{{SAFESUBST:#if:labelstyle|labelstyle=}} parameters are used to adjust the infobox width and define a default width for the column of labels:

local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p <syntaxhighlight lang="wikitext"> local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p

</syntaxhighlight>

Embedding

One infobox template can be embedded into another using the |{{SAFESUBST:#if:child|child=}} parameter. This feature can be used to create a modular infobox, or to create better-defined logical sections. Long ago, it was necessary to use embedding in order to create infoboxes with more than 99 rows; but nowadays there's no limit to the number of rows that can be defined in a single instance of {{infobox}}.

local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p <syntaxhighlight lang="wikitext" style="overflow: auto;"> local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p </syntaxhighlight>

Note, in the examples above, the child infobox is placed in a data field, not a header field. Notice that the section subheadings are not in bold font if bolding is not explicitly specified. To obtain bold section headings, place the child infobox in a header field (but not in a label field because it would not be displayed!), either using

local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p <syntaxhighlight lang="wikitext" style="overflow: auto;"> local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p </syntaxhighlight>

or,

local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p <syntaxhighlight lang="wikitext" style="overflow: auto;"> local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p </syntaxhighlight>

Note that omitting the |{{SAFESUBST:#if:title|title=}} parameter, and not including any text preceding the embedded infobox, may result in spurious blank table rows, creating gaps in the visual presentation. The garbage output can be suppressed using |{{SAFESUBST:#if:rowstyleN|rowstyleN=}}display: none, replacing N with the data/header number.

Wikipedia:WikiProject Infoboxes/embed includes some links to Wikipedia articles which include infoboxes embedded within other infoboxes.

Subboxes

An alternative method for embedding is to use |{{SAFESUBST:#if:subbox|subbox=}}yes, which removes the outer border from the infobox, but preserves the interior structure. One feature of this approach is that the parent and child boxes need not have the same structure, and the label and data fields are not aligned between the parent and child boxes because they are not in the same parent table.

local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p <syntaxhighlight lang="wikitext" style="overflow: auto;"> local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p </syntaxhighlight>

Similar embedding techniques may be used within content parameters of some other templates generating tables (such as Sidebar):

<syntaxhighlight lang="wikitext" style="overflow: auto;">

</syntaxhighlight>

Note that the default padding of the parent data cell containing each subbox is still visible, so the subboxes are slightly narrower than the parent box and there's a higher vertical spacing between standard cells of the parent box than between cells of distinct subboxes.

Controlling line-breaking in embedded bulletless lists

Template {{nbsp}} may be used with {{wbr}} and {{nowrap}} to control line-breaking in bulletless lists embedded in infoboxes (e.g. cast list in {{Infobox film}}), to prevent wrapped long entries from being confused with multiple entries. See Template:Wbr/doc#Controlling line-breaking in infoboxes for details.

Full blank syntax

(Note: there is no limit to the number of possible rows; only 20 are given below since infoboxes larger than that will be relatively rare. Just extend the numbering as needed. The microformat "class" parameters are also omitted as they are not commonly used.)

<syntaxhighlight lang="wikitext" style="overflow: auto;"> local p = {} local wikiLang = 'fr'

local localdata = {}-- données concernant les paramètres passés au modèle

-- données concernant la page où est affichée l'infobox local page = mw.title.getCurrentTitle()

local maincolor, secondcolor, thirdcolor -- l'objet principal à retourner local infobox = mw.html.create('div')

-- objets secondaires à retourner local maintenance = -- chaîne retournée avec le module : cats de maintenance local externaltext = -- par exemple coordonnées en titre -- modules importés local wd = require 'Module:Wikidata' local yesno = require 'Module:Yesno' local valueexpl = wd.translate("activate-query")

-- maintenance des images dupliquées local usedImages = {}

local i18n = { ['see doc'] = 'Documentation du modèle', ['edit'] = 'modifier', ['edit code'] = 'modifier le code', ['edit item'] = 'modifier Wikidata', ['tracking cat'] = "Page utilisant des données de Wikidata", ['invalid block type'] = "Bloc de données invalide dans le module d'infobox", ['default cat'] = "Maintenance des infobox", }

local function expandQuery(query) if not query.entity then query.entity = localdata.item end if not query.conjtype then query.conjtype = 'comma' end local claims = wd.getClaims(query) if (not claims) then return nil end

return wd.formatAndCat(query), wd.getgendernum(claims) -- valeur et code indiquant le genre/nombre pour accorder le libellé end

local function getWikidataValue(params, wikidataparam) -- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le paramètre "property" if not localdata.item then return nil end

if params.blockers then -- blockers are local parameters that disable the wikidata query local blockers = params.blockers if (type(blockers) == 'string') then blockers = {blockers} end for i, blocker in ipairs(blockers) do if localdata[blocker] then return nil end end end

local v, valgendernum -- la valeur à retourner, et le genre/nombre de de valeurs (pour l'accord grammatical)

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 wikidataparam = 'wikidata' end

if params.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} end

if params[wikidataparam] then if type(params[wikidataparam]) == 'function' then v, valgendernum = params[wikidataparam](localdata.item) elseif type(params[wikidataparam]) == 'table' then v, valgendernum = expandQuery(params[wikidataparam]) else v, valgendernum = params[wikidataparam] end end if not v then return nil end

if(type(valgendernum) == 'number') then if(valgendernum > 1) then valgendernum = 'p' else valgendernum = 's' end end

return v, valgendernum end

local function getValue(val, params) if type(val) == 'string' then return localdata[val] elseif type(val) == 'function' then return val(localdata, 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 premier non vide if localdata[j] then return localdata[j] end end end end

local function addMaintenanceCat(cat, sortkey) if page.namespace ~= 0 then return end if cat then local sortkeycode if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = end maintenance = maintenance .. end end

function p.separator(params) local classes = params['separator classes'] local style = params['separator style'] or {} style['background-color'] = style['background-color'] or maincolor if style['background-color'] then style.color = 'var( --color-base )' end

return mw.html.create('hr'):addClass( classes ):css( style ) end

--[=[ Construit le code du bloc de titre de l'infobox

Paramètres (liste partielle) : - value : Moyen d'obtenir le titre via getValue (nom de paramètre de modèle ou fonction). - textdefaultvalue : Valeur par défaut du titre. - icon : Pictogramme d'infobox (voir Projet:Infobox/Pictogramme). - italic : Indique si le titre doit être affiché en italique.

 Si italic=true, le paramètre "titre en italique" de l'infobox peut forcer la désactivation.

- setdisplaytitle : Indique si le titre de l'article doit être mis en forme comme celui de l'infobox.

 Si setdisplaytitle=true, le paramètre "titre article en italique" de l'infobox peut forcer la désactivation.

]=] function p.buildtitle(params) local text = getValue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or page.prefixedText local lang = localdata['langue du titre'] or if lang ~= then local langueFunction = require( 'Module:Langue' ).langue text = langueFunction( { lang, text } ) end local subtext = getValue(params.subtitle) or getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue if subtext and (subtext ~= text) then text = text .. '
' .. subtext .. '' end local icon = params.icon or if icon ~= and icon ~= 'defaut' then text = text .. mw.getCurrentFrame():extensionTag('templatestyles', , {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'}) if not params.large then icon = 'icon ' .. icon end end local classes = 'entete ' .. icon

local italic = params.italic and yesno(localdata['titre en italique'] or , true, true) if italic then classes = classes .. ' italique' end if params.setdisplaytitle and yesno(localdata['titre article en italique'] or , true, true) then local formatTitleModule = require( 'Module:Formatage du titre' ) text = text .. formatTitleModule.setDisplayTitle{ args = { lang = lang, italic = italic, options = 'noreplace', } } end

-- 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(classes) :css(style) :tag('div') :wikitext(text) :allDone() return title end p.buildTitle = p.buildtitle

function p.buildnavigator(params)

-- définition du style local classes = "overflow infobox-navigateur " .. (params.class or ) local style = params.style or {}

if params.separated then -- options pour ajouter une ligne de séparation au dessus classes = classes .. ' bordered' if maincolor then style['border-top'] = '1px solid' .. maincolor end end

-- ajustement des paramètres de données params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète params.nextval = params.nextval or params.nextparameter

if params.previousproperty then params.previouswikidata = {property = params.previousproperty} 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')

   if previousval  == '-' then previousval  = nil end
   if nextval  == '-' then nextval  = nil end

local navigator if params.inner then -- pour celles qui sont à l'intérieur d'une table navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2) style['font-weight'] = style['font-weight'] or 'normal' else navigator = mw.html.create('div') end

if previousval or nextval then navigator :addClass(classes) :css(style) :tag('div') :addClass('prev_bloc') :wikitext(previousval) :done() :tag('div') :addClass('next_bloc') :wikitext(nextval) :done() :allDone() return navigator end return nil end p.buildNavigator = p.buildnavigator

function p.buildimages(params) local images = {} local upright, link, caption, classe, alt, size -- size is deprecated if type(params.imageparameters) == 'string' then params.imageparameters = {params.imageparameters} end if not params.imageparameters then -- s'il n'y a pas de paramètre image, continuer, peut-être y a-t-il une image par défaut définie dans le module d'infobox params.imageparameters = {} end for j, k in ipairs(params.imageparameters) do table.insert(images, localdata[k]) end -- Images de Wikidata local iswikidataimage, iswikidatacaption = false if #images == 0 and localdata.item then if params.property then params.wikidata = {entity = localdata.item, property = params.property} end if params.wikidata then local wdq = params.wikidata wdq.excludespecial = true if type(wdq) == 'table' then wdq.entity = wdq.entity or localdata.item wdq.numval = wdq.numval or params.numval or 1 images = wd.getClaims(wdq) end if type(wdq) == 'function' then images = params.wikidata() if type(images) == 'string' then return images end --c'est probablement une erreur dans la requête => afficher le message end if (not images) then images = {} end if (#images > 0) and (params.wikidata.property) then maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property) end

if type(images[1]) == 'table' then for i, image in pairs(images) do if image.mainsnak.snaktype ~= 'value' then return end if #images == 1 then -- si une seule image, on utilise la légende (si deux plusieurs images, comment mettre en forme ?) caption = wd.getFormattedQualifiers(images[i], {'P2096'}, {isinlang = wikiLang}) caption = caption or wd.getFormattedQualifiers(images[i], {'P805'}) --"affirmation détaillée dans" if params.datecaption and not caption then --légende construite à partir de la date de l'image et d'une table de paramètres spécifiques local dcparams = params.datecaption if type(dcparams) ~= 'table' then dcparams = {} end local numdate = wd.compare.get_claim_date(images[i]) local endclaims = wd.getClaims({entity = wdq.entity, property = dcparams.endproperty, numval = 1}) local endnumdate = ( endclaims and wd.compare.get_claim_date(endclaims[1]) ) or math.huge if numdate <= endnumdate then caption = wd.getFormattedDate(images[i], {precision = dcparams.precision or 'year', linktopic = dcparams.linktopic or '-', withpreposition = true}) if caption then if dcparams.prefix then caption = dcparams.prefix .. ' ' .. caption end caption = require('Module:Linguistique').ucfirst(caption) .. '.' addMaintenanceCat("Infobox avec une légende automatique à partir de la date de l'image") end end end iswikidatacaption = caption ~= nil end images[i] = image.mainsnak.datavalue.value iswikidataimage = true end end end end

if #images == 0 and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale sans image") end -- Images par défaut if #images == 0 then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end if params.defaultimages then images = params.defaultimages if type(images) == 'string' then images = {images} end upright = params.defaultimageupright caption = params.defaultimagecaption link = params.defaultimagelink classe = params.defaultimageclass if not classe and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then classe = 'skin-invert-image' end alt = params.defaultimagealt if not alt and ( images[1] == 'Defaut.svg' or images[1] == 'Defaut 2.svg' ) then alt = 'une illustration sous licence libre serait bienvenue' end end end if #images == 0 then return nil end

upright = upright 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 classe = classe or getValue( params.classparameter) or params.defaultclass alt = alt or getValue( params.altparameter) or params.defaultalt

if iswikidataimage and not iswikidatacaption and getValue(params.captionparameter) ~= nil then addMaintenanceCat("Infobox avec une légende locale et une image sur Wikidata") end

-- taille avec "size" (obsolète) size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated if size then local sizevalue = size:gsub('px$', )

local widthonly = mw.ustring.gsub(sizevalue, 'x.*', ) widthonly = tonumber(widthonly) if type(widthonly) ~= 'number' or widthonly > 280 then addMaintenanceCat("Infobox avec une image trop grande") end

if tonumber(sizevalue) then size = tostring( tonumber(sizevalue) ) .. 'px' end end

if tonumber(upright) then upright = tostring( tonumber(upright) ) 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 .. 'lang=' .. wikiLang end imagesString = imagesString .. ''

if usedImages[image] then addMaintenanceCat('Infobox avec plusieurs images identiques') end usedImages[image] = true end

local image = mw.html.create('div') :addClass("images") :css(style) :wikitext(imagesString)

-- Partie légende local captionobj if caption then captionobj = mw.html.create('div') :wikitext(caption) :css(params.legendstyle or {}) :addClass("legend") :done() end

-- séparateur local separator if params.separator then separator = p.separator(params) end return mw.html.create('div') :node(image) :node(captionobj) :node(separator) :done() end p.buildImages = p.buildimages

function p.buildtext(params) local classes = params.class or local style = { ['text-align'] = 'center', ['font-weight'] = 'bold' } if params.style then for i, j in pairs(params.style) do style[i] = j end end local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue if text == '-' then return end if not text then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end -- séparateur local separator if params.separator then separator = p.separator(params) end local formattedtext = mw.html.create('p') :addClass(classes) :css(style) :wikitext(text) :node(separator) :done() return formattedtext end p.buildText = p.buildtext

function p.buildrow(params) local classes = params.class or local style = params.style or {} local valueClass = params.valueClass or local valueStyle = params.valueStyle or {} local value, gendernum = getValue(params.value, params) if(type(gendernum) == 'number') then if(gendernum > 1) then gendernum = 'p' else gendernum = 's' end end

if type(params.wikidata) == 'table' then params.wikidata.wikidatalang = localdata.wikidatalang if (value == valueexpl) then value = nil params.wikidata.expl = false end end if (not value) then value, gendernum = getWikidataValue(params, 'wikidata') end

if not value then value = params.defaultvalue end if value == '-' then return nil end if not gendernum then gendernum = 's' --singulier indéfini end

if not value then if params.maintenancecat then addMaintenanceCat(params.maintenancecat, params.sortkey) end return nil end

local label = params.label if type(label) == 'string' then label = {default = label} end

if type(label) == 'table' then -- Accord en genre et en nombre local onlynum = {default = 'default', s = 's', ms = 's', fs = 's', p = 'p', mp = 'p', fp = 'p', mixtep = 'p'} -- Accord seulement en nombre par défaut

label['s'] = label['s'] or params.singularlabel or label['default'] or label['ms'] label['p'] = label['p'] or params.plurallabel or label['mp']

label = label[gendernum] or label[onlynum[gendernum]] or label.default end

if type(label) == 'function' then label = label(localdata, 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) :addClass(valueClass) :css(valueStyle) :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(classes) :css(style) :node(formattedlabel) :node(formattedvalue) :done()

return row end p.buildRow = p.buildrow

function p.buildsuccession(params) if not params.value then return nil 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 styleI = {} local colspan = '2' styleI['padding'] = '1px' local cellI = mw.html.create('td') :attr({colspan = colspan}) :attr({align = 'center'}) :css(styleI)

local styleT = { margin = '0', ['background-color'] = 'transparent', color = 'inherit', width = '100%' } local tabC = mw.html.create('table') :attr({cellspacing = '0'}) :addClass('navigation-not-searchable') :css(styleT)

local row = mw.html.create('tr')

local color = params.color

local style = {} local arrowLeft = 'Précédent' local arrowRight = 'Suivant'

if color ~= 'default' then style['background-color'] = color end

local styleTrans = {}

local values = params.value local before = values['before'] local center = values['center'] local after = values['after']

local widthCenter 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 p.buildSuccession = p.buildsuccession

function p.buildrow1col(params)

if not params.value then return nil 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 classes = 'row1col ' .. (params.class or ) local style = {} if params.color == 'secondcolor' then style['background-color'] = secondcolor else style['background-color'] = params.color end

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(classes) :css(style) :node(formattedlabel) :done()

return row end p.buildRow1Col = p.buildrow1col

function p.buildtable(params) local tab = mw.html.create('table'):addClass(params.classes):css(params.style or {})

local rows = params.rows

-- expand parameters so that we have a list of tables local i = 1

while (i <= #rows) do local l = rows[i] if type(l) == 'function' then l = l(localdata, localdata.item) end if (type(l) == 'table') and (l.type == 'multi') then table.remove(rows, i) for j, row in ipairs(l.rows) do table.insert(rows, i + j - 1, row) end elseif type(l) == 'nil' then table.remove(rows, i) elseif type(l) ~= 'table' then return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l)) else i = i + 1 end end

-- CREATE ROW local expandedrows = {} for k, row in ipairs(rows) do local v = p.buildblock(row) if v then table.insert(expandedrows, v) end end if (#expandedrows == 0) then return nil end rows = expandedrows

-- ADD TITLE local title if params.title or params.singulartitle or params.pluraltitle then local text if #rows > 1 and params.pluraltitle then text = params.pluraltitle elseif #rows == 1 and params.singulartitle then text = params.singulartitle 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 p.buildTable = p.buildtable


-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)


function p.buildSubheader2col(params)

   local row = mw.html.create('tr')
   local col1 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col1)
       :done()
   local col2 = mw.html.create('th')
       :attr('scope', 'col')
       :wikitext(params.col2)
       :done()
   row:node(col1)
   row:node(col2)
   row:done()
   return row

end

function p.buildinvalidblock(args) addMaintenanceCat(i18n['default cat']) 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 p.buildInvalidBlock = p.buildinvalidblock

function p.buildmap(params)

-- paramètre d'affichage local maplist = getValue(params.maps) local pointtype = params.pointtype local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.) if type(maplist) == 'function' then maplist = maplist(localdata, localdata.item) end local width = tonumber(params.width) or 280 if width > 280 then addMaintenanceCat("Infobox avec une 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 pointtable = {} local globe = params.globe if params.latitude then local lat, long if type(params.latitude) == 'function' then lat, long = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item) else lat, long = localdata[params.latitude], localdata[params.longitude] end if lat then table.insert(pointtable, {latitude = lat, longitude = long}) end end

-- récupération des données wikidata local function processWDval(claim, displayformat) if not claim then return nil end local val = wd.formatSnak( claim.mainsnak ) return {latitude = val.latitude, longitude = val.longitude, globe = val.globe, marker = displayformat.marker} end

local function getWDvals(query) query.excludespecial = true query.numval = query.numval or 1 query.entity = query.entity or localdata.item local claims = wd.getClaims(query) if (not claims) then return end for i, claim in ipairs(claims) do claim = processWDval(claim, query) table.insert(pointtable, claim) end end

if (#pointtable == 0) and localdata.item and params.wikidata and (params.wikidata ~= '-') then for i, query in ipairs(params.wikidata) do if type(query) == 'function' then query = query() end if query then getWDvals(query) end end end

if (not pointtable) or (#pointtable == 0) then return nil end

local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, pointtable = pointtable, globe = globe, marker=params.marker, default_zoom=params.default_zoom, ids = params.ids, markercolor = params.markercolor, shapecolor = params.shapecolor } 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 require('Module:Carte').multimap(newparams) end p.buildMap = p.buildmap

function p.buildexternaltext(params) local value = getValue(params.value) if value and (type(value) == 'string') then externaltext = externaltext .. value end end p.buildExternalText = p.buildexternaltext

function p.buildfooter(params) if not params then params = {} end

local classes = 'navbar noprint bordered navigation-not-searchable ' .. (params.class or ) local style = params.style or {} if not style['border-top'] and maincolor then style['border-top'] = '1px solid' .. maincolor end

local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.prefixedText, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']' .. ' - [' .. tostring( mw.uri.fullUrl( page.prefixedText, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

local itemlinkstr if localdata.item and localdata.item ~= '-' then itemlinkstr = '' .. i18n['edit item'] .. '' end local editstr = backlinkstr if itemlinkstr then editstr = editstr .. ' - ' .. itemlinkstr end local editlinkspan = mw.html.create('span') :css({['text-align'] = "left"}) :addClass('plainlinks') :wikitext(editstr) :done() local doclinkstr = '' .. i18n['see doc'] .. '' -- si ce lien ne marche pas toujours, il faut ajouter un variable pour le nom de l'infobox récupéré par le frame local doclinkspan = mw.html.create('span') :css({['text-align'] = "right"}) :wikitext(doclinkstr) :done()

local footer = mw.html.create('p') :addClass(classes) :css(style) :node(editlinkspan) :node(doclinkspan) return footer end p.buildFooter = p.buildfooter

function p.buildblock(block) if type(block) == 'function' then block = block( localdata ) end

local blocktypes = { -- list of functions for block buildings ['invalid'] = p.buildinvalidblock, ['external text'] = p.buildexternaltext, ['footer'] = p.buildfooter, ['images'] = p.buildimages, ['map']= p.buildmap, ['mixed'] = p.buildrow, ['navigator'] = p.buildnavigator, ['table'] = p.buildtable, ['row'] = p.buildrow, ['row1col'] = p.buildrow1col, ['succession'] = p.buildsuccession, ['text'] = p.buildtext, ['title'] = p.buildtitle, ['subheader2col'] = p.buildSubheader2col, } if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then return blocktypes['invalid'](block) end return blocktypes[block.type](block) end p.buildBlock = p.buildblock

function p.build()

localdata = require( 'Module:Infobox/Localdata' ) if type( localdata.item ) == 'table' then localdata.item = localdata.item.id 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 localdata.item then local itemlink = mw.wikibase.sitelink(localdata.item) local pagetitle = page.prefixedText if (itemlink or ) ~= pagetitle then infoboxrank = 'secondary' end end localdata.infoboxrank = infoboxrank

-- load infobox module page local moduledata = require('Module:Infobox/' .. localdata.modulename) moduledata.name = localdata.modulename

-- maintenance categories given by the module page if moduledata.categories then for i, j in pairs(moduledata.categories) do if (type(j) == 'string') then addMaintenanceCat(j) end if (type(j) == 'table') then addMaintenanceCat(j[1],j[2]) end end end

-- defines main color maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or localdata['couleur boite'] or moduledata.maincolor secondcolor = moduledata.secondcolor thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor if maincolor and ( #maincolor == 6 or #maincolor == 3 ) and maincolor:match( '^%x+$' ) then maincolor = '#' .. maincolor end if thirdcolor and (thirdcolor == 'non' or thirdcolor == 'false') then thirdcolor = '#fff' end

-- classes local classes = mw.getCurrentFrame():expandTemplate{ title = 'Classes début infobox', args = { version = '3' } } classes = classes .. ' large ' .. (moduledata.class or )

-- style local style = moduledata.style or {}

-- templatestyles local templatestyles = if moduledata.templatestyles then templatestyles = templatestyles .. mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = moduledata.templatestyles} } end

-- build infobox infobox :addClass(classes) :css(style) for i, j in pairs( moduledata.parts ) do infobox:node( p.buildblock(j) ) end infobox :node(p.buildfooter(moduledata.footer)) :done()

return templatestyles .. tostring(infobox) .. externaltext, maintenance end

return p </syntaxhighlight>

Infoboxes and user style

Users can have user CSS that hides any infoboxes in their own browsers.

To hide all infoboxes, add the following to Special:MyPage/common.css (for all skins, or Special:MyPage/skin.css for just the current skin), on a line by itself: <syntaxhighlight lang="css">div.mw-parser-output .infobox { display: none; }</syntaxhighlight>

Alternatively, you can add the following code to your common.js or into a browser user script that is executed by an extension like Greasemonkey:

<syntaxhighlight lang="js">$('.infobox').hide();</syntaxhighlight>

Be aware that although{{#if:||, per WP:Manual of Style/Infoboxes,}} all information in an infobox ideally should also be found in the main body of an article, there isn't perfect compliance with this guideline. For example, the full taxonomic hierarchy in {{Taxobox}}, and the OMIM and other medical database codes of {{Infobox disease}} are often not found in the main article content. The infobox is also often the location of the most significant, even only, image in an article. There is a userscript which removes infoboxes but moves the images contained to separate thumbnails: User:Maddy from Celeste/disinfobox.js.

Porting to other MediaWikis

The infobox template requires the Scribunto and TemplateStyles extensions. WikiProject Transwiki has a version of this template that has been modified to work on other MediaWikis.

TemplateData

{{#if:|{{#switch:
|=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3AInfobox%7CInfobox%7CInfobox%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}}
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|no|S|s}}ee a monthly parameter usage report] for {{#if:Infobox|Template:Infobox|this template}} in articles{{#ifeq:{{safesubst:#switch: y

|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:Infobox|its|this}} TemplateData}}.

|None|none=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3AInfobox%7CInfobox%7CInfobox%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}}
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|no|P|p}}arameter usage report]{{#ifeq:{{safesubst:#switch: y

|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:Infobox|its|this}} TemplateData}}

|for|For=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3AInfobox%7CInfobox%7CInfobox%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}}
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|no|P|p}}arameter usage report] for {{#if:Infobox|Template:Infobox|Template:Infobox}}{{#ifeq:{{safesubst:#switch: y

|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:Infobox|its|this}} TemplateData}}.

|#default=[1]{{#ifeq:{{safesubst:#switch: y
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:Infobox|its|this}} TemplateData}} }}|This is the {{#if:|TemplateData|TemplateData}} for this template used by TemplateWizard, VisualEditor and other tools. {{#switch:

|=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3AInfobox%7CInfobox%7CInfobox%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}}
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|no|S|s}}ee a monthly parameter usage report] for {{#if:Infobox|Template:Infobox|this template}} in articles{{#ifeq:{{safesubst:#switch: y

|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:Infobox|its|this}} TemplateData}}.

|None|none=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3AInfobox%7CInfobox%7CInfobox%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}}
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|no|P|p}}arameter usage report]{{#ifeq:{{safesubst:#switch: y

|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:Infobox|its|this}} TemplateData}}

|for|For=[https://bambots.brucemyers.com/TemplateParam.php?wiki=enwiki&template=%7B%7B%23if%3AInfobox%7CInfobox%7CInfobox%7D%7D {{#ifeq:{{safesubst:#switch: {{{lc}}}
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|no|P|p}}arameter usage report] for {{#if:Infobox|Template:Infobox|Template:Infobox}}{{#ifeq:{{safesubst:#switch: y

|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:Infobox|its|this}} TemplateData}}.

|#default=[2]{{#ifeq:{{safesubst:#switch: y
|no
|n
|f
|false
|off
|0        = no
|         = no
|¬        = no
|yes
|y
|t
|true
|on
|1        = yes
|#default = no

}}|yes| based on {{#if:Infobox|its|this}} TemplateData}} }}}}

TemplateData for Infobox

{{#switch:

 {{#if:
 | {{{demospace}}}    
 | {{#ifeq:Modèle|Modèle
   | template
   | other
   }}
 }}

| template = {{#if:{{#ifeq:doc|sandbox|1}}{{#ifeq:doc|doc|1}}||

}} | other | #default = }} <templatedata> { "description": "This template is intended as a meta template, a template used for constructing other templates. In general, it is not meant for use directly in an article but can be used on a one-off basis if required.", "format": "Modèle:\n\n", "params": {

		"name": {

"label": "name",

			"description": ""
        },
		"child": {

"label": "child",

			"description": ""
        },
		"subbox": {

"label": "subbox",

			"description": ""
        },
		"italic title": {

"label": "italic title",

			"description": ""
        },
 		"templatestyles": {

"label": "templatestyles",

			"description": ""
        },
		"child templatestyles": {

"label": "child templatestyles",

			"description": ""
        },
		"grandchild templatestyles": {

"label": "grandchild templatestyles",

			"description": ""
        },
		"bodystyle": {

"label": "bodystyle",

			"description": ""
        },
		"titlestyle": {

"label": "titlestyle",

			"description": ""
        },
		"abovestyle": {

"label": "abovestyle",

			"description": ""
        },
		"subheaderstyle": {

"label": "subheaderstyle",

			"description": ""
        },

"title": { "label": "Title", "description": "Title displayed above the infobox", "type": "string", "suggested": true },

		"above": {

"label": "above",

			"description": ""
        },
		"subheader": {

"label": "subheader",

			"description": ""
        },
		"imagestyle": {

"label": "imagestyle",

			"description": ""
        },
		"captionstyle": {

"label": "captionstyle",

			"description": ""
        },

"image": { "label": "Image", "description": "Image illustrating the topic. Use full image syntax.", "type": "content", "suggested": true, "example": "Example alt text" }, "caption": { "label": "Caption", "description": "caption for the image", "type": "content", "suggested": true },

		"image2": {

"label": "image2",

			"description": ""
        },
		"caption2": {

"label": "caption2",

			"description": ""
        },
		"headerstyle": {

"label": "headerstyle",

			"description": ""
        },
		"labelstyle": {

"label": "labelstyle",

			"description": ""
        },
		"datastyle": {

"label": "datastyle",

			"description": ""
        },
		"header1": {

"label": "header1",

			"description": ""
        },
		"label1": {

"label": "label1",

			"description": ""
        },
		"data1": {

"label": "data1",

			"description": ""
        },
		"header2": {

"label": "header2",

			"description": ""
        },
		"label2": {

"label": "label2",

			"description": ""
        },
		"data2": {

"label": "data2",

			"description": ""
        },
		"header3": {

"label": "header3",

			"description": ""
        },
		"label3": {

"label": "label3",

			"description": ""
        },
		"data3": {

"label": "data3",

			"description": ""
        },
		"header4": {

"label": "header4",

			"description": ""
        },
		"label4": {

"label": "label4",

			"description": ""
        },
		"data4": {

"label": "data4",

			"description": ""
        },
		"header5": {

"label": "header5",

			"description": ""
        },
		"label5": {

"label": "label5",

			"description": ""
        },
		"data5": {

"label": "data5",

			"description": ""
        },
		"header6": {

"label": "header6",

			"description": ""
        },
		"label6": {

"label": "label6",

			"description": ""
        },
		"data6": {

"label": "data6",

			"description": ""
        },
		"header7": {

"label": "header7",

			"description": ""
        },
		"label7": {

"label": "label7",

			"description": ""
        },
		"data7": {

"label": "data7",

			"description": ""
        },
		"header8": {

"label": "header8",

			"description": ""
        },
		"label8": {

"label": "label8",

			"description": ""
        },
		"data8": {

"label": "data8",

			"description": ""
        },
		"header9": {

"label": "header9",

			"description": ""
        },
		"label9": {

"label": "label9",

			"description": ""
        },
		"data9": {

"label": "data9",

			"description": ""
        },
		"header10": {

"label": "header10",

			"description": ""
        },
		"label10": {

"label": "label10",

			"description": ""
        },
		"data10": {

"label": "data10",

			"description": ""
        },
		"header11": {

"label": "header11",

			"description": ""
        },
		"label11": {

"label": "label11",

			"description": ""
        },
		"data11": {

"label": "data11",

			"description": ""
        },
		"header12": {

"label": "header12",

			"description": ""
        },
		"label12": {

"label": "label12",

			"description": ""
        },
		"data12": {

"label": "data12",

			"description": ""
        },
		"header13": {

"label": "header13",

			"description": ""
        },
		"label13": {

"label": "label13",

			"description": ""
        },
		"data13": {

"label": "data13",

			"description": ""
        },
		"header14": {

"label": "header14",

			"description": ""
        },
		"label14": {

"label": "label14",

			"description": ""
        },
		"data14": {

"label": "data14",

			"description": ""
        },
		"header15": {

"label": "header15",

			"description": ""
        },
		"label15": {

"label": "label15",

			"description": ""
        },
		"data15": {

"label": "data15",

			"description": ""
        },
		"header16": {

"label": "header16",

			"description": ""
        },
		"label16": {

"label": "label16",

			"description": ""
        },
		"data16": {

"label": "data16",

			"description": ""
        },
		"header17": {

"label": "header17",

			"description": ""
        },
		"label17": {

"label": "label17",

			"description": ""
        },
		"data17": {

"label": "data17",

			"description": ""
        },
		"header18": {

"label": "header18",

			"description": ""
        },
		"label18": {

"label": "label18",

			"description": ""
        },
		"data18": {

"label": "data18",

			"description": ""
        },
		"header19": {

"label": "header19",

			"description": ""
        },
		"label19": {

"label": "label19",

			"description": ""
        },
		"data19": {

"label": "data19",

			"description": ""
        },
		"header20": {

"label": "header20",

			"description": ""
        },
		"label20": {

"label": "label20",

			"description": ""
        },
		"data20": {

"label": "data20",

			"description": ""
        },
		"belowstyle": {

"label": "belowstyle",

			"description": ""
        },
		"below": {

"label": "below",

			"description": ""
        }

}, "paramOrder": [ "name", "child", "subbox", "italic title", "templatestyles", "child templatestyles", "grandchild templatestyles", "bodystyle", "titlestyle", "abovestyle", "subheaderstyle", "title", "above", "subheader", "imagestyle", "captionstyle", "image", "caption", "image2", "caption2", "headerstyle", "labelstyle", "datastyle", "header1", "label1", "data1", "header2", "label2", "data2", "header3", "label3", "data3", "header4", "label4", "data4", "header5", "label5", "data5", "header6", "label6", "data6", "header7", "label7", "data7", "header8", "label8", "data8", "header9", "label9", "data9", "header10", "label10", "data10", "header11", "label11", "data11", "header12", "label12", "data12", "header13", "label13", "data13", "header14", "label14", "data14", "header15", "label15", "data15", "header16", "label16", "data16", "header17", "label17", "data17", "header18", "label18", "data18", "header19", "label19", "data19", "header20", "label20", "data20", "belowstyle", "below" ] } </templatedata>

Tracking categories

See also