Module:Infobox : Différence entre versions

Sauter à la navigation Sauter à la recherche
(Undid revision 906073835 by Gonnym (talk) errors in code were reported)
 
fr>FDo64
(Maintenance)
Ligne 1 : Ligne 1 :
--
+
local p = {}
-- This module implements {{Infobox}}
+
local lang = 'fr'
--
+
 
 +
local item = nil -- l'élément Wikidata lié
 +
local localdata = {}-- données concernant les paramètres passés au modèle
 +
local page = { -- données concernant la page où est affichée l'infobox
 +
name = mw.title.getCurrentTitle().prefixedText,
 +
namespace =  mw.title.getCurrentTitle().namespace
 +
}
 +
local maincolor, secondcolor, thirdcolor = '#E1E1E1', '#E1E1E1', '#000000'
 +
-- l'objet principal à 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 linguistic = require "Module:Linguistique"
 +
local wd = require 'Module:Wikidata'
 +
local valueexpl = wd.translate("activate-query")
 +
 
 +
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 p = {}
+
local function addWikidataCat(prop)
 +
maintenance = maintenance .. wd.addTrackingCat(prop)
 +
end
 +
 
 +
local function expandQuery(query)
 +
local value, number -- valeur à retourner, nombre de valeurs pour accorder le libellé
 +
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), #claims -- pour l'accord au pluriel
 +
end
  
local navbar = require('Module:Navbar')._navbar
+
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
  
local args = {}
+
if params.blockers then -- blockers are local parameters that disable the wikidata query
local origArgs
+
local blockers = params.blockers
local root
+
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 function notempty( s ) return s and s:match( '%S' ) end
+
local v, valnum -- la valeur à retourner, et le 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
  
local function fixChildBoxes(sval, tt)
+
if params[wikidataparam] then
if notempty(sval) then
+
if type(params[wikidataparam]) == 'function' then
local marker = '<span class=special_infobox_marker>'
+
v, valnum = params[wikidataparam](localdata.item)
local s = sval
+
elseif type(params[wikidataparam]) == 'table' then
s = mw.ustring.gsub(s, '(<%s*[Tt][Rr])', marker .. '%1')
+
v, valnum = expandQuery(params[wikidataparam])
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>)', '%1' .. marker)
+
else
if s:match(marker) then
+
v, valnum = params[wikidataparam]
s = mw.ustring.gsub(s, marker .. '%s*' .. marker, '')
 
s = mw.ustring.gsub(s, '([\r\n]|-[^\r\n]*[\r\n])%s*' .. marker, '%1')
 
s = mw.ustring.gsub(s, marker .. '%s*([\r\n]|-)', '%1')
 
s = mw.ustring.gsub(s, '(</[Cc][Aa][Pp][Tt][Ii][Oo][Nn]%s*>%s*)' .. marker, '%1')
 
s = mw.ustring.gsub(s, '(<%s*[Tt][Aa][Bb][Ll][Ee][^<>]*>%s*)' .. marker, '%1')
 
s = mw.ustring.gsub(s, '^(%{|[^\r\n]*[\r\n]%s*)' .. marker, '%1')
 
s = mw.ustring.gsub(s, '([\r\n]%{|[^\r\n]*[\r\n]%s*)' .. marker, '%1')
 
s = mw.ustring.gsub(s,  marker .. '(%s*</[Tt][Aa][Bb][Ll][Ee]%s*>)', '%1')
 
s = mw.ustring.gsub(s,  marker .. '(%s*\n|%})', '%1')
 
 
end
 
end
if s:match(marker) then
+
end
local subcells = mw.text.split(s, marker)
+
if not v then
s = ''
+
return nil
for k = 1, #subcells do
+
end
if k == 1 then
+
v = linguistic.ucfirst(v)
s = s .. subcells[k] .. '</' .. tt .. '></tr>'
+
return v, valnum
elseif k == #subcells then
+
end
local rowstyle = ' style="display:none"'
+
 
if notempty(subcells[k]) then rowstyle = '' end
+
local function getValue(val, params)
s = s .. '<tr' .. rowstyle ..'><' .. tt .. ' colspan=2>\n' .. subcells[k]
+
if type(val) == 'string' then
elseif notempty(subcells[k]) then
+
return localdata[val]
if (k % 2) == 0 then
+
elseif type(val) == 'function' then
s = s .. subcells[k]
+
return val(localdata, localdata.item, params)
else
+
elseif type(val) == 'table' then
s = s .. '<tr><' .. tt .. ' colspan=2>\n' .. subcells[k] .. '</' .. tt .. '></tr>'
+
for i, j in pairs(val) do -- si plusieurs paramètres possibles (legacy de vieux code), prendre le premier non vide
end
+
if localdata[j] then
end
+
return localdata[j]
 
end
 
end
 
end
 
end
-- the next two lines add a newline at the end of lists for the PHP parser
 
-- https://en.wikipedia.org/w/index.php?title=Template_talk:Infobox_musical_artist&oldid=849054481
 
-- remove when [[:phab:T191516]] is fixed or OBE
 
s = mw.ustring.gsub(s, '([\r\n][%*#;:][^\r\n]*)$', '%1\n')
 
s = mw.ustring.gsub(s, '^([%*#;:][^\r\n]*)$', '%1\n')
 
s = mw.ustring.gsub(s, '^([%*#;:])', '\n%1')
 
s = mw.ustring.gsub(s, '^(%{%|)', '\n%1')
 
return s
 
else
 
return sval
 
 
end
 
end
 
end
 
end
  
local function union(t1, t2)
+
local function addMaintenanceCat(cat, sortkey)
    -- Returns the union of the values of two tables, as a sequence.
+
if page.namespace ~= 0 then
    local vals = {}
+
return ''
    for k, v in pairs(t1) do
+
end
        vals[v] = true
+
if cat then
    end
+
maintenance = maintenance .. '[[Category:' .. cat .. '|' .. (sortkey or page.name) .. ']]'
    for k, v in pairs(t2) do
+
end
        vals[v] = true
 
    end
 
    local ret = {}
 
    for k, v in pairs(vals) do
 
        table.insert(ret, k)
 
    end
 
    return ret
 
 
end
 
end
  
local function getArgNums(prefix)
+
function p.separator(params)
    -- Returns a table containing the numbers of the arguments that exist
+
local style = params['separator style'] or {}
    -- for the specified prefix. For example, if the prefix was 'data', and
+
style.height = style.height or '2px'
    -- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}.
+
style['background-color'] = style['background-color'] or maincolor
    local nums = {}
+
    for k, v in pairs(args) do
+
return mw.html.create('hr'):css( style )
        local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
 
        if num then table.insert(nums, tonumber(num)) end
 
    end
 
    table.sort(nums)
 
    return nums
 
 
end
 
end
  
local function addRow(rowArgs)
+
function p.buildtitle(params)
    -- Adds a row to the infobox, with either a header cell
+
local text = getValue(params.value, params) or params.textdefaultvalue or  getWikidataValue(params) or mw.title.getCurrentTitle().text
    -- or a label/data cell combination.
+
local subtext = getValue(params.subtitle) or  getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue
    if rowArgs.header then
+
if subtext and (subtext ~= text) then
        root
+
text = text .. '<br /><small>' .. subtext .. '</small>'
            :tag('tr')
+
end
                :addClass(rowArgs.rowclass)
+
local icon = params.icon or ''
                :cssText(rowArgs.rowstyle)
+
if icon ~= '' and icon ~= 'defaut' then
                :attr('id', rowArgs.rowid)
+
text = text .. mw.getCurrentFrame():extensionTag('templatestyles', '', {src = 'Infobox/Pictogramme/' .. mw.text.trim(icon) .. '.css'})
                :tag('th')
+
if not params.large then
                    :attr('colspan', 2)
+
icon = 'icon ' .. icon
                    :attr('id', rowArgs.headerid)
+
end
                    :addClass(rowArgs.class)
+
end
                    :addClass(args.headerclass)
+
local class = 'entete ' .. icon
                    :css('text-align', 'center')
+
                    :cssText(args.headerstyle)
+
-- overwrites with those provided in the module
                    :cssText(rowArgs.rowcellstyle)
+
local style = {}
                    :wikitext(fixChildBoxes(rowArgs.header, 'th'))
+
style['background-color'] = maincolor
    elseif rowArgs.data then
+
style['color'] = thirdcolor
        local row = root:tag('tr')
+
if params.style then
        row:addClass(rowArgs.rowclass)
+
for i, j in pairs(params.style) do
        row:cssText(rowArgs.rowstyle)
+
style[i] = j
        row:attr('id', rowArgs.rowid)
+
end
        if rowArgs.label then
+
end
            row
+
local title = mw.html.create('div')
                :tag('th')
+
:addClass(class)
                    :attr('scope', 'row')
+
:css(style)
                    :attr('id', rowArgs.labelid)
+
:tag('div')
                    :cssText(args.labelstyle)
+
:wikitext(text)
                    :cssText(rowArgs.rowcellstyle)
+
:allDone()
                    :wikitext(rowArgs.label)
+
return title
                    :done()
 
        end
 
       
 
        local dataCell = row:tag('td')
 
        if not rowArgs.label then
 
            dataCell
 
                :attr('colspan', 2)
 
                :css('text-align', 'center')  
 
        end
 
        dataCell
 
            :attr('id', rowArgs.dataid)
 
            :addClass(rowArgs.class)
 
            :cssText(rowArgs.datastyle)
 
            :cssText(rowArgs.rowcellstyle)
 
            :wikitext(fixChildBoxes(rowArgs.data, 'td'))
 
    end
 
 
end
 
end
 +
p.buildTitle = p.buildtitle
 +
 +
function p.buildnavbox(params)
 +
 +
-- définition du style
 +
local class = "overflow nav " .. (params.class or '')
 +
local style = params.style or {}
 +
 +
if params.separated then -- options pour ajouter une ligne de séparation au dessus
 +
class = class .. ' bordered'
 +
style['border-top'] = '1px solid' .. maincolor
 +
end
  
local function renderTitle()
+
-- ajustement des paramètres de données
    if not args.title then return end
+
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
 +
  
    root
+
local previousval = getValue(params.previousval, params) or getWikidataValue(params, 'previouswikidata')
        :tag('caption')
+
local nextval = getValue(params.nextval, params) or getWikidataValue(params, 'nextwikidata')
            :addClass(args.titleclass)
+
            :cssText(args.titlestyle)
+
local navbox
            :wikitext(args.title)
+
if params.inner then -- pour celles qui sont à l'intérieur d'une table
 +
navbox = mw.html.create('tr'):tag('th'):attr('colspan', 2)
 +
style['font-weight'] = style['font-weight'] or 'normal'
 +
else
 +
navbox = mw.html.create('div')
 +
end
 +
 +
navbox
 +
:addClass(class)
 +
:css(style)
 +
:tag('div')
 +
:addClass('prev_bloc')
 +
:wikitext(previousval)
 +
:done()
 +
:tag('div')
 +
:addClass('next_bloc')
 +
:wikitext(nextval)
 +
:done()
 +
:allDone()
 +
return navbox
 
end
 
end
 +
p.buildNavbox = p.buildnavbox
 +
 +
function p.buildimages(params)
 +
local images = {}
 +
local upright, link, caption, 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
 +
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
 +
addWikidataCat(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 = 'fr'}) or wd.getFormattedQualifiers(images[i], {'P805'})
 +
end
 +
images[i] = image.mainsnak.datavalue.value
 +
end
 +
end
 +
end
 +
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
 +
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
 +
alt = alt or getValue( params.altparameter) or params.defaultalt
 +
 +
-- taille avec "size" (obsolète)
 +
size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated
 +
if size then
 +
local numsize = size:gsub('px', '')
 +
numsize = mw.ustring.gsub(numsize, 'x.*', '')
 +
numsize = tonumber(numsize)
 +
if type(numsize) ~= 'number' or numsize > 280 then
 +
addMaintenanceCat("taille d'image invalide")
 +
end
 +
if tonumber(size) then
 +
size = size .. 'px'
 +
end
 +
size = '|' .. size
 +
else
 +
size = ''
 +
end
 +
 +
if tonumber(upright) then
 +
upright = tostring(tonumber(upright) ) / #images
 +
end
 +
if tonumber(size) then
 +
size = tostring(tonumber(size) ) / #images
 +
end
 +
 +
local style = params.style or {padding ='2px 0',}
 +
 +
-- Partie image
 +
 +
local imagesString = ''
 +
for i,image in pairs(images) do
 +
if image == '-' then
 +
return
 +
end
 +
imagesString = imagesString ..  '[[Fichier:' .. image .. size .. '|frameless'
 +
if alt then
 +
imagesString = imagesString .. '|alt=' .. alt
 +
end
 +
if link then
 +
imagesString = imagesString .. '|link=' .. link
 +
end
 +
if upright then
 +
imagesString = imagesString .. '|upright=' .. upright
 +
elseif #images > 1 then
 +
imagesString = imagesString .. '|upright=' .. ( 1 / #images )
 +
end
 +
imagesString = imagesString .. ']]'
 +
end
 +
 +
local image = mw.html.create('div')
 +
:addClass("images")
 +
:css(style)
 +
:wikitext(imagesString)
  
local function renderAboveRow()
+
-- Partie légende
    if not args.above then return end
+
local captionobj
   
+
if caption then
    root
+
captionobj = mw.html.create('div')
        :tag('tr')
+
:wikitext(caption)
            :tag('th')
+
:css(params.legendstyle or {})
                :attr('colspan', 2)
+
:addClass("legend")
                :addClass(args.aboveclass)
+
:done()
                :css('text-align', 'center')
+
end
                :css('font-size', '125%')
+
                :css('font-weight', 'bold')
+
-- séparateur
                :cssText(args.abovestyle)
+
local separator
                :wikitext(fixChildBoxes(args.above,'th'))
+
if params.separator then
 +
separator = separator(params)
 +
end
 +
return mw.html.create('div')
 +
:node(image)
 +
:node(captionobj)
 +
:node(separator)
 +
:done()
 
end
 
end
 +
p.buildImages = p.buildimages
  
local function renderBelowRow()
+
function p.buildtext(params)
    if not args.below then return end
+
local class = params.class or ''
   
+
local style = {
    root
+
['text-align'] = 'center',
        :tag('tr')
+
['font-weight'] = 'bold'
            :tag('td')
+
}
                :attr('colspan', '2')
+
if params.style then
                :addClass(args.belowclass)
+
for i, j in pairs(params.style) do
                :css('text-align', 'center')
+
style[i] = j
                :cssText(args.belowstyle)
+
end
                :wikitext(fixChildBoxes(args.below,'td'))
+
end
 +
local text = getValue(params.value, params) or getWikidataValue(params) or params.defaultvalue
 +
if text == '-' then
 +
return
 +
end
 +
if not text then
 +
addMaintenanceCat(params.maintenancecat, params.sortkey)
 +
return nil
 +
end
 +
local formattedtext = mw.html.create('p')
 +
:addClass(class)
 +
:css(style)
 +
:wikitext(text)
 +
:done()
 +
return formattedtext
 
end
 
end
 +
p.buildText = p.buildtext
  
local function renderSubheaders()
+
function p.buildrow(params)
    if args.subheader then
+
local class = params.class or ''
        args.subheader1 = args.subheader
+
local style = params.style or {}
    end
+
local value, number =  getValue(params.value, params)
    if args.subheaderrowclass then
+
if (value == valueexpl) then
        args.subheaderrowclass1 = args.subheaderrowclass
+
value = nil
    end
+
params.wikidata.expl = false
    local subheadernums = getArgNums('subheader')
+
end
    for k, num in ipairs(subheadernums) do
+
if (not value) then
        addRow({
+
value, number =  getWikidataValue(params, 'wikidata')
            data = args['subheader' .. tostring(num)],
+
end
            datastyle = args.subheaderstyle,
+
if (not value) and (params.property) then
            rowcellstyle = args['subheaderstyle' .. tostring(num)],
+
value, number = expandQuery{ property = params.property, ucfirst = params.ucfirst }
            class = args.subheaderclass,
+
end
            rowclass = args['subheaderrowclass' .. tostring(num)]
+
if not value then
        })
+
value = params.defaultvalue
    end
+
end
 +
if value == '-' then
 +
return nil
 +
end
 +
if not number then
 +
number = 0 -- == indéfini
 +
end
 +
 
 +
if not value then
 +
if params.maintenancecat then
 +
local maintenancecat = getValue(params.maintenancecat, params)
 +
addMaintenanceCat(maintenancecat, params.sortkey)
 +
end
 +
return nil
 +
end
 +
 
 +
local label = params.label
 +
if number > 1 and (params.plurallabel) then
 +
label = params.plurallabel
 +
elseif number == 1 and (params.singularlabel) then
 +
label = params.singularlabel
 +
end
 +
if type(label) == 'function' then
 +
label = label(localdata, localdata.item)
 +
end
 +
 
 +
-- format
 +
local formattedvalue = mw.html.create('div')
 +
:wikitext('\n' .. value) -- Le '\n' est requis lorsque value est une liste commençant par '*' ou '#'
 +
 +
if (params.hidden == true)then
 +
formattedvalue
 +
:attr({class="NavContent", style="display: none; text-align: left;"})
 +
formattedvalue = mw.html.create('div')
 +
:attr({class="NavFrame", title="[Afficher]/[Masquer]", style="border: none; padding: 0;"})
 +
:node(formattedvalue)
 +
end
 +
formattedvalue = mw.html.create('td')
 +
:node(formattedvalue)
 +
:allDone()
 +
 +
local formattedlabel
 +
if label then
 +
formattedlabel = mw.html.create('th')
 +
:attr('scope', 'row')
 +
:wikitext(label)
 +
:done()
 +
end
 +
local row = mw.html.create('tr')
 +
:addClass(class)
 +
:css(style)
 +
:node(formattedlabel)
 +
:node(formattedvalue)
 +
:done()
 +
 +
return row
 
end
 
end
 +
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 colspan = '2'
 +
cellI = mw.html.create('td')
 +
:attr({colspan = colspan})
 +
:attr({align = 'center'})
 +
 +
local styleT = {}
 +
styleT['background-color'] = 'transparent'
 +
styleT['width'] = '100%'
 +
tabC = mw.html.create('table')
 +
:attr({cellspacing = '0'})
 +
:addClass('navigation-not-searchable')
 +
:css(styleT)
 +
 +
local row = mw.html.create('tr')
  
local function renderImages()
+
local color = params.color
    if args.image then
+
 
        args.image1 = args.image
+
local style = {}
    end
+
local arrowLeft
    if args.caption then
+
local arrowRight
        args.caption1 = args.caption
+
    end
+
if color == 'default' then
    local imagenums = getArgNums('image')
+
style['background-color'] = '#E6E6E6'
    for k, num in ipairs(imagenums) do
+
arrowLeft = '[[Fichier:Fleche-defaut-gauche.png|13px|alt=Précédent|link=]]'
        local caption = args['caption' .. tostring(num)]
+
arrowRight = '[[Fichier:Fleche-defaut-droite.png|13px|alt=Précédent|link=]]'
        local data = mw.html.create():wikitext(args['image' .. tostring(num)])
+
else
        if caption then
+
style['background-color'] = color
            data
+
arrowLeft = '[[Fichier:Fleche-defaut-gauche-gris-32.png|13px|alt=Suivant|link=]]'
                :tag('div')
+
arrowRight = '[[Fichier:Fleche-defaut-droite-gris-32.png|13px|alt=Suivant|link=]]'
                    :cssText(args.captionstyle)
+
end
                    :wikitext(caption)
+
        end
+
local styleTrans = {}
        addRow({
+
styleTrans['background-color'] = '#F9F9F9'
            data = tostring(data),
+
            datastyle = args.imagestyle,
+
local values = params.value
            class = args.imageclass,
+
local before = values['before']
            rowclass = args['imagerowclass' .. tostring(num)]
+
local center = values['center']
        })
+
local after = values['after']
    end
+
 +
local widthCell = '44%'
 +
if center then
 +
widthCenter = '28%'
 +
widthCell = '29%'
 +
end
 +
 +
local formattedbefore
 +
if before then
 +
formattedbefore = mw.html.create('td')
 +
:attr({valign = 'middle'})
 +
:attr({align = 'left'})
 +
:attr({width = '5%'})
 +
:css(style)
 +
:wikitext(arrowLeft)
 +
:done()
 +
row:node(formattedbefore)
 +
formattedbefore = mw.html.create('td')
 +
:attr({width = '1%'})
 +
:css(style)
 +
:wikitext('')
 +
:done()
 +
row:node(formattedbefore)
 +
formattedbefore = mw.html.create('td')
 +
:attr({align = 'left'})
 +
:attr({valign = 'middle'})
 +
:attr({width = widthCell})
 +
:css(style)
 +
:wikitext(before)
 +
:done()
 +
row:node(formattedbefore)
 +
else
 +
formattedbefore = mw.html.create('td')
 +
:attr({valign = 'middle'})
 +
:attr({align = 'left'})
 +
:attr({width = '5%'})
 +
:css(styleTrans)
 +
:wikitext('')
 +
:done()
 +
row:node(formattedbefore)
 +
formattedbefore = mw.html.create('td')
 +
:attr({width = '1%'})
 +
:css(styleTrans)
 +
:wikitext('')
 +
:done()
 +
row:node(formattedbefore)
 +
formattedbefore = mw.html.create('td')
 +
:attr({align = 'left'})
 +
:attr({valign = 'middle'})
 +
:attr({width = widthCell})
 +
:css(styleTrans)
 +
:wikitext('')
 +
:done()
 +
row:node(formattedbefore)
 +
end
 +
 +
local formattedcenter
 +
formattedcenter = mw.html.create('td')
 +
:attr({width = '1%'})
 +
:css(styleTrans)
 +
:wikitext('')
 +
:done()
 +
row:node(formattedcenter)
 +
 +
if center then
 +
formattedcenter = mw.html.create('td')
 +
:attr({align = 'center'})
 +
:attr({valign = 'middle'})
 +
:attr({width = widthCenter})
 +
:css(style)
 +
:wikitext(center)
 +
:done()
 +
row:node(formattedcenter)
 +
formattedcenter = mw.html.create('td')
 +
:attr({width = '1%'})
 +
:css(styleTrans)
 +
:wikitext('')
 +
:done()
 +
row:node(formattedcenter)
 +
end
 +
 +
local formattedafter
 +
if after then
 +
formattedafter = mw.html.create('td')
 +
:attr({align = 'right'})
 +
:attr({valign = 'middle'})
 +
:attr({width = widthCell})
 +
:css(style)
 +
:wikitext(after)
 +
:done()
 +
row:node(formattedafter)
 +
formattedbefore = mw.html.create('td')
 +
:attr({width = '1%'})
 +
:css(style)
 +
:wikitext('')
 +
:done()
 +
row:node(formattedbefore)
 +
formattedafter = mw.html.create('td')
 +
:attr({align = 'right'})
 +
:attr({valign = 'middle'})
 +
:attr({width = '5%'})
 +
:css(style)
 +
:wikitext(arrowRight)
 +
:done()
 +
row:node(formattedafter)
 +
else
 +
formattedafter = mw.html.create('td')
 +
:attr({align = 'right'})
 +
:attr({valign = 'middle'})
 +
:attr({width = widthCell})
 +
:css(styleTrans)
 +
:wikitext('')
 +
:done()
 +
row:node(formattedafter)
 +
formattedbefore = mw.html.create('td')
 +
:attr({width = '1%'})
 +
:css(styleTrans)
 +
:wikitext('')
 +
:done()
 +
row:node(formattedbefore)
 +
formattedafter = mw.html.create('td')
 +
:attr({align = 'right'})
 +
:attr({valign = 'middle'})
 +
:attr({width = '5%'})
 +
:css(styleTrans)
 +
:wikitext('')
 +
:done()
 +
row:node(formattedafter)
 +
end
 +
 +
row:done()
 +
tabC:node(row)
 +
tabC:done()
 +
cellI:node(tabC)
 +
cellI:done()
 +
rowI:node(cellI)
 +
rowI:allDone()
 +
 +
return rowI
 
end
 
end
 +
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 class = params.class
 +
local rowcolor
 +
if params.color == 'secondcolor' then
 +
rowcolor = secondcolor
 +
else
 +
rowcolor = params.color
 +
end
 +
 +
local style = {}
 +
style['padding'] = '4px'
 +
style['text-align'] = 'center'
 +
style['background-color'] = rowcolor or '#F9F9F9'
 +
style['color'] = '#000000'
 +
 +
local text = params.value
 +
 +
local colspan ='2'
  
local function renderRows()
+
local formattedlabel
    -- Gets the union of the header and data argument numbers,
+
formattedlabel = mw.html.create('th')
    -- and renders them all in order using addRow.
+
:attr({colspan = colspan})
    local rownums = union(getArgNums('header'), getArgNums('data'))
+
:css(style)
    table.sort(rownums)
+
:wikitext(text)
    for k, num in ipairs(rownums) do
+
:done()
        addRow({
+
 
            header = args['header' .. tostring(num)],
+
local row = mw.html.create('tr')
            label = args['label' .. tostring(num)],
+
:addClass(class)
            data = args['data' .. tostring(num)],
+
:css(style)
            datastyle = args.datastyle,
+
:node(formattedlabel)
            class = args['class' .. tostring(num)],
+
:done()
            rowclass = args['rowclass' .. tostring(num)],
+
            rowstyle = args['rowstyle' .. tostring(num)],
+
return row
            rowcellstyle = args['rowcellstyle' .. tostring(num)],
 
            dataid = args['dataid' .. tostring(num)],
 
            labelid = args['labelid' .. tostring(num)],
 
            headerid = args['headerid' .. tostring(num)],
 
            rowid = args['rowid' .. tostring(num)]
 
        })
 
    end
 
 
end
 
end
 +
p.buildRow1Col = p.buildrow1col
 +
 +
function p.buildtable(params)
 +
local tab = mw.html.create('table'):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
  
local function renderNavBar()
+
-- ADD TITLE
    if not args.name then return end
+
local title
   
+
if params.title or params.singulartitle or params.pluraltitle then
    root
+
local text
        :tag('tr')
+
if #rows > 1 and params.pluraltitle then
            :tag('td')
+
text = params.pluraltitle
                :attr('colspan', '2')
+
elseif #rows == 1 and params.singulartitle then
                :css('text-align', 'right')
+
text = params.singulartitle
                :wikitext(navbar{
+
else
                    args.name,
+
text = params.title
                    mini = 1,
+
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
 
end
 +
p.buildTable = p.buildtable
  
local function renderItalicTitle()
+
function p.buildinvalidblock(args)
    local italicTitle = args['italic title'] and mw.ustring.lower(args['italic title'])
+
addMaintenanceCat(defaultcat)
    if italicTitle == '' or italicTitle == 'force' or italicTitle == 'yes' then
+
local text = ''
        root:wikitext(mw.getCurrentFrame():expandTemplate({title = 'italic title'}))
+
if type(args) ~= 'table' then
    end
+
text = "Les blocs d'infobox doivent être des tables"
 +
else
 +
text = i18n["invalid block type"] .. ' : ' .. (args.type or '??')
 +
end
 +
return text
 
end
 
end
 +
p.buildInvalidBlock = p.buildinvalidblock
 +
 +
function p.buildmap(params)
  
local function renderTrackingCategories()
+
-- paramètre d'affichage
    if args.decat ~= 'yes' then
+
local maplist = getValue(params.maps)
    if args.child == 'yes' then
+
local pointtype = params.pointtype
        if args.title then
+
local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.)
            root:wikitext('[[Category:Pages which use embedded infobox templates with the title parameter]]')
+
if type(maplist) == 'function' then
        end
+
maplist = maplist(localdata, localdata.item)
        elseif #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then
+
end
            root:wikitext('[[Category:Articles which use infobox templates with no data rows]]')
+
local width = tonumber(params.width) or 280
        end
+
if width > 280 then
    end
+
addMaintenanceCat("Erreur d'Infobox/Image trop grande")
 +
return 'image trop grande, la largeur doit être inférieure ou égale à 280px'
 +
end
 +
 
 +
-- récupération des données locales
 +
local 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
 
end
 +
p.buildMap = p.buildmap
  
local function _infobox()
+
function p.buildexternaltext(params)
    -- Specify the overall layout of the infobox, with special settings
+
local value = getValue(params.value)
    -- if the infobox is used as a 'child' inside another infobox.
+
if value and (type(value) == 'string') then
    if args.child ~= 'yes' then
+
externaltext = externaltext .. value
        root = mw.html.create('table')
+
end
       
+
end
        root
+
p.buildExternalText = p.buildexternaltext
            :addClass((args.subbox ~= 'yes') and 'infobox' or nil)
+
 
            :addClass(args.bodyclass)
+
function p.buildfooter(params)
           
+
if not params then
            if args.subbox == 'yes' then
+
params = {}
                root
+
end
                    :css('padding', '0')
+
                    :css('border', 'none')
+
local class = 'navbar noprint bordered ' .. (params.class or '')
                    :css('margin', '-3px')
+
local style = params.style or {}
                    :css('width', 'auto')
+
style['border-top'] = style['border-top'] or '1px solid ' .. maincolor
                    :css('min-width', '100%')
+
                    :css('font-size', '100%')
+
local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.name, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']'
                    :css('clear', 'none')
+
.. ' - [' .. tostring( mw.uri.fullUrl( page.name, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'
                    :css('float', 'none')
 
                    :css('background-color', 'transparent')
 
            else
 
                root
 
                    :css('width', '22em')
 
            end
 
        root
 
            :cssText(args.bodystyle)
 
   
 
        renderTitle()
 
        renderAboveRow()
 
    else
 
        root = mw.html.create()
 
       
 
        root
 
            :wikitext(args.title)
 
    end
 
  
    renderSubheaders()
+
local itemlinkstr
    renderImages()  
+
if localdata.item then
    renderRows()  
+
itemlinkstr = '[[d:' .. localdata.item.id .. '|' .. i18n['edit item'] .. ']]'
    renderBelowRow()
+
end
    renderNavBar()
+
local editstr = backlinkstr
    renderItalicTitle()
+
if itemlinkstr then
    renderTrackingCategories()
+
editstr = editstr .. ' - ' .. itemlinkstr
   
+
end
    return tostring(root)
+
local editlinkspan =  mw.html.create('span')
 +
:css({['text-align'] = "left"})
 +
:addClass('plainlinks')
 +
:wikitext(editstr)
 +
:done()
 +
local doclinkstr = '[[Fichier:Info Simple.svg|12px|link=' .. localdata.templatename .. '|' .. 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(class)
 +
:css(style)
 +
:node(editlinkspan)
 +
:node(doclinkspan)
 +
return footer
 
end
 
end
 +
p.buildFooter = p.buildfooter
  
local function preprocessSingleArg(argName)
+
function p.buildblock(block)
    -- If the argument exists and isn't blank, add it to the argument table.
+
if type(block) == 'function' then
    -- Blank arguments are treated as nil to match the behaviour of ParserFunctions.
+
block = block( localdata )
    if origArgs[argName] and origArgs[argName] ~= '' then
+
end
        args[argName] = origArgs[argName]
+
 
    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,
 +
['navbox'] = p.buildnavbox,
 +
['table'] = p.buildtable,
 +
['row'] = p.buildrow,
 +
['row1col'] = p.buildrow1col,
 +
['succession'] = p.buildnavbox,
 +
['text'] = p.buildtext,
 +
['title'] = p.buildtitle,
 +
}
 +
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
 
end
 +
p.buildBlock = p.buildblock
  
local function preprocessArgs(prefixTable, step)
+
function p.build()
    -- Assign the parameters with the given prefixes to the args table, in order, in batches
+
    -- of the step size specified. This is to prevent references etc. from appearing in the
+
localdata = require( 'Module:Infobox/Localdata' )
    -- wrong order. The prefixTable should be an array containing tables, each of which has
+
item = localdata.item
    -- two possible fields, a "prefix" string and a "depend" table. The function always parses
 
    -- parameters containing the "prefix" string, but only parses parameters in the "depend"
 
    -- table if the prefix parameter is present and non-blank.
 
    if type(prefixTable) ~= 'table' then
 
        error("Non-table value detected for the prefix table", 2)
 
    end
 
    if type(step) ~= 'number' then
 
        error("Invalid step value detected", 2)
 
    end
 
   
 
    -- Get arguments without a number suffix, and check for bad input.
 
    for i,v in ipairs(prefixTable) do
 
        if type(v) ~= 'table' or type(v.prefix) ~= "string" or (v.depend and type(v.depend) ~= 'table') then
 
            error('Invalid input detected to preprocessArgs prefix table', 2)
 
        end
 
        preprocessSingleArg(v.prefix)
 
        -- Only parse the depend parameter if the prefix parameter is present and not blank.
 
        if args[v.prefix] and v.depend then
 
            for j, dependValue in ipairs(v.depend) do
 
                if type(dependValue) ~= 'string' then
 
                    error('Invalid "depend" parameter value detected in preprocessArgs')
 
                end
 
                preprocessSingleArg(dependValue)
 
            end
 
        end
 
    end
 
  
    -- Get arguments with number suffixes.
+
-- assign rank to the infobox, "secondary" means special formatting like no displaytitle for coordinates
    local a = 1 -- Counter variable.
+
local infoboxrank = 'main' -- main infobox of the page, with coordinates displayed in title etc.
    local moreArgumentsExist = true
+
if page.namespace ~= 0 then
    while moreArgumentsExist == true do
+
infoboxrank = 'secondary'
        moreArgumentsExist = false
+
end
        for i = a, a + step - 1 do
+
-- if infobox is linked to another item: rank = secondary
            for j,v in ipairs(prefixTable) do
+
if localdata.item then
                local prefixArgName = v.prefix .. tostring(i)
+
local itemlink = mw.wikibase.sitelink(localdata.item.id)
                if origArgs[prefixArgName] then
+
local pagetitle = mw.title.getCurrentTitle().text
                    moreArgumentsExist = true -- Do another loop if any arguments are found, even blank ones.
+
if (itemlink or '') ~= pagetitle then
                    preprocessSingleArg(prefixArgName)
+
infoboxrank = 'secondary'
                end
+
end
                -- Process the depend table if the prefix argument is present and not blank, or
+
end
                -- we are processing "prefix1" and "prefix" is present and not blank, and
+
localdata.infoboxrank = infoboxrank
                -- if the depend table is present.
+
 
                if v.depend and (args[prefixArgName] or (i == 1 and args[v.prefix])) then
+
-- load infobox module page
                    for j,dependValue in ipairs(v.depend) do
+
local moduledata = require('Module:Infobox/' .. localdata.modulename)
                        local dependArgName = dependValue .. tostring(i)
+
moduledata.name = localdata.modulename
                        preprocessSingleArg(dependArgName)
+
-- defines main color
                    end
+
maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or moduledata.maincolor or maincolor
                end
+
secondcolor = moduledata.secondcolor or secondcolor
            end
+
thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor or thirdcolor
        end
+
if maincolor:match( '^%x%x%x%x%x%x$' ) or maincolor:match( '^%x%x%x$' ) then
        a = a + step
+
maincolor = '#' .. maincolor
    end
+
end
 +
if thirdcolor:match ('oui') or thirdcolor:match( 'true' ) then
 +
thirdcolor = '#000'
 +
end
 +
if thirdcolor:match ('non') or thirdcolor:match( 'false' ) then
 +
thirdcolor = '#fff'
 +
end
 +
 +
-- class
 +
local class = 'infobox_v3 large'
 +
if moduledata.class then
 +
class = class .. ' ' .. moduledata.class
 +
end
 +
 +
-- style
 +
local style = moduledata.style or {}
 +
 +
-- build infobox
 +
infobox :addClass(class)
 +
:css(style)
 +
for i, j in pairs( moduledata.parts ) do
 +
infobox:node( p.buildblock(j) )
 +
end
 +
infobox :node(p.buildfooter(moduledata.footer))
 +
:done()
 +
 
 +
return tostring(infobox) .. externaltext, maintenance
 
end
 
end
+
 
function p.infobox(frame)
 
    -- If called via #invoke, use the args passed into the invoking template.
 
    -- Otherwise, for testing purposes, assume args are being passed directly in.
 
    if frame == mw.getCurrentFrame() then
 
        origArgs = frame:getParent().args
 
    else
 
        origArgs = frame
 
    end
 
   
 
    -- Parse the data parameters in the same order that the old {{infobox}} did, so that
 
    -- references etc. will display in the expected places. Parameters that depend on
 
    -- another parameter are only processed if that parameter is present, to avoid
 
    -- phantom references appearing in article reference lists.
 
    preprocessSingleArg('child')
 
    preprocessSingleArg('bodyclass')
 
    preprocessSingleArg('subbox')
 
    preprocessSingleArg('bodystyle')
 
    preprocessSingleArg('title')
 
    preprocessSingleArg('titleclass')
 
    preprocessSingleArg('titlestyle')
 
    preprocessSingleArg('above')
 
    preprocessSingleArg('aboveclass')
 
    preprocessSingleArg('abovestyle')
 
    preprocessArgs({
 
        {prefix = 'subheader', depend = {'subheaderstyle', 'subheaderrowclass'}}
 
    }, 10)
 
    preprocessSingleArg('subheaderstyle')
 
    preprocessSingleArg('subheaderclass')
 
    preprocessArgs({
 
        {prefix = 'image', depend = {'caption', 'imagerowclass'}}
 
    }, 10)
 
    preprocessSingleArg('captionstyle')
 
    preprocessSingleArg('imagestyle')
 
    preprocessSingleArg('imageclass')
 
    preprocessArgs({
 
        {prefix = 'header'},
 
        {prefix = 'data', depend = {'label'}},
 
        {prefix = 'rowclass'},
 
        {prefix = 'rowstyle'},
 
        {prefix = 'rowcellstyle'},
 
        {prefix = 'class'},
 
        {prefix = 'dataid'},
 
        {prefix = 'labelid'},
 
        {prefix = 'headerid'},
 
        {prefix = 'rowid'}
 
    }, 50)
 
    preprocessSingleArg('headerclass')
 
    preprocessSingleArg('headerstyle')
 
    preprocessSingleArg('labelstyle')
 
    preprocessSingleArg('datastyle')
 
    preprocessSingleArg('below')
 
    preprocessSingleArg('belowclass')
 
    preprocessSingleArg('belowstyle')
 
    preprocessSingleArg('name')
 
    args['italic title'] = origArgs['italic title'] -- different behaviour if blank or absent
 
    preprocessSingleArg('decat')
 
 
    return _infobox()
 
end
 
 
 
return p
 
return p

Version du 8 septembre 2019 à 21:45

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

local p = {}
local lang = 'fr'

local item = nil -- l'élément Wikidata lié
local localdata = {}-- données concernant les paramètres passés au modèle
local page = { -- données concernant la page où est affichée l'infobox
	name = mw.title.getCurrentTitle().prefixedText,
	namespace =  mw.title.getCurrentTitle().namespace
}
local maincolor, secondcolor, thirdcolor = '#E1E1E1', '#E1E1E1', '#000000'
-- l'objet principal à 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 linguistic = require "Module:Linguistique"
local wd = require 'Module:Wikidata'
local valueexpl = wd.translate("activate-query")

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 addWikidataCat(prop)
	maintenance = maintenance .. wd.addTrackingCat(prop)
end

local function expandQuery(query)
	local value, number -- valeur à retourner, nombre de valeurs pour accorder le libellé
	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), #claims -- pour l'accord au pluriel
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, valnum -- la valeur à retourner, et le 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[wikidataparam] then
		if type(params[wikidataparam]) == 'function' then
			v, valnum = params[wikidataparam](localdata.item)
		elseif type(params[wikidataparam]) == 'table' then
			v, valnum = expandQuery(params[wikidataparam])
		else
			v, valnum = params[wikidataparam]
		end
	end
	if not v then
		return nil
	end
	v = linguistic.ucfirst(v)
	return v, valnum
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
		maintenance = maintenance .. '[[Category:' .. cat .. '|' .. (sortkey or page.name) .. ']]'
	end
end

function p.separator(params)
	local style = params['separator style'] or {}
	style.height = style.height or '2px'
	style['background-color'] = style['background-color'] or maincolor
	
	return mw.html.create('hr'):css( style )	
end

function p.buildtitle(params)
	local text = getValue(params.value, params) or params.textdefaultvalue or  getWikidataValue(params) or mw.title.getCurrentTitle().text
	local subtext = getValue(params.subtitle) or  getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue
	if subtext and (subtext ~= text) then
		text = text .. '<br /><small>' .. subtext .. '</small>'
	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 class = 'entete ' .. icon
	
	-- overwrites with those provided in the module
	local style = {}
	style['background-color'] = maincolor
	style['color'] = thirdcolor
	if params.style then
		for i, j in pairs(params.style) do
			style[i] = j
		end
	end
	local title = mw.html.create('div')
		:addClass(class)
		:css(style)
		:tag('div')
			:wikitext(text)
		:allDone()
	return title
end
p.buildTitle = p.buildtitle

function p.buildnavbox(params)
	
	-- définition du style
	local class = "overflow nav " .. (params.class or '')
	local style = params.style or {}

	if params.separated then -- options pour ajouter une ligne de séparation au dessus
		class = class .. ' bordered'
		style['border-top'] = '1px solid' .. maincolor
	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')
	
	local navbox
	if params.inner then -- pour celles qui sont à l'intérieur d'une table
		navbox = mw.html.create('tr'):tag('th'):attr('colspan', 2)
		style['font-weight'] = style['font-weight'] or 'normal'
	else
		navbox = mw.html.create('div')
	end
	
	navbox
		:addClass(class)
		:css(style)
		:tag('div')
			:addClass('prev_bloc')
			:wikitext(previousval)
			:done()
		:tag('div')
			:addClass('next_bloc')
			:wikitext(nextval)
			:done()
		:allDone()
	return navbox
end
p.buildNavbox = p.buildnavbox

function p.buildimages(params)
	local images = {}
	local upright, link, caption, 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 
	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
				addWikidataCat(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 = 'fr'}) or wd.getFormattedQualifiers(images[i], {'P805'})
					end
					images[i] = image.mainsnak.datavalue.value
				end
			end
		end
	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
			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
	alt = alt or getValue( params.altparameter) or params.defaultalt

	-- taille avec "size" (obsolète)
	size = size or getValue(params.sizeparameter) or params.defaultsize -- deprecated
	if size then
		local numsize = size:gsub('px', '')
		numsize = mw.ustring.gsub(numsize, 'x.*', '')
		numsize = tonumber(numsize)
		if type(numsize) ~= 'number' or numsize > 280 then
			addMaintenanceCat("taille d'image invalide")
		end
		if tonumber(size) then
			size = size .. 'px'
		end
		size = '|' .. size
	else
		size = ''
	end
	
	if tonumber(upright) then
		upright = tostring(tonumber(upright) ) / #images
	end
	if tonumber(size) then
		size = tostring(tonumber(size) ) / #images
	end

	local style = params.style or {padding ='2px 0',}

	-- Partie image

	local imagesString = ''
	for i,image in pairs(images) do
		if image == '-' then
			return
		end
		imagesString = imagesString ..  '[[Fichier:' .. image .. size .. '|frameless'
		if alt then
			imagesString = imagesString .. '|alt=' .. alt
		end
		if link then
			imagesString = imagesString .. '|link=' .. link
		end
		if upright then
			imagesString = imagesString .. '|upright=' .. upright
		elseif #images > 1 then
			imagesString = imagesString .. '|upright=' .. ( 1 / #images )
		end
		imagesString = imagesString .. ']]'
	end

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

	-- Partie légende
	local captionobj
	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 = 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 class = 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
		addMaintenanceCat(params.maintenancecat, params.sortkey)
		return nil
	end
	local formattedtext = mw.html.create('p')
		:addClass(class)
		:css(style)
		:wikitext(text)
		:done()
	return formattedtext
end
p.buildText = p.buildtext

function p.buildrow(params)
	local class = params.class or ''
	local style = params.style or {}
	local value, number =  getValue(params.value, params)
	if (value == valueexpl) then
		value = nil
		params.wikidata.expl = false
	end
	if (not value) then
		value, number =  getWikidataValue(params, 'wikidata')
	end
	if (not value) and (params.property) then
		value, number = expandQuery{ property = params.property, ucfirst = params.ucfirst }
	end
	if not value then
		value = params.defaultvalue
	end
	if value == '-' then
		return nil
	end
	if not number then
		number = 0 -- == indéfini
	end

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

	local label = params.label
	if number > 1 and (params.plurallabel) then
		label = params.plurallabel
	elseif number == 1 and (params.singularlabel) then
		label = params.singularlabel
	end
	if type(label) == 'function' then
			label = label(localdata, localdata.item)
	end

	-- format
	local formattedvalue = mw.html.create('div')
		:wikitext('\n' .. value) -- Le '\n' est requis lorsque value est une liste commençant par '*' ou '#'
		
	if (params.hidden == true)then
		formattedvalue
			:attr({class="NavContent", style="display: none; text-align: left;"})
		formattedvalue = mw.html.create('div')
			:attr({class="NavFrame", title="[Afficher]/[Masquer]", style="border: none; padding: 0;"})
			:node(formattedvalue)
	end
	formattedvalue =  mw.html.create('td')
			:node(formattedvalue)
			:allDone()
	
	local formattedlabel
	if label then
		formattedlabel = mw.html.create('th')
			:attr('scope', 'row')
			:wikitext(label)
			:done()
	end
	local row = mw.html.create('tr')
		:addClass(class)
		:css(style)
		:node(formattedlabel)
		:node(formattedvalue)
		:done()
	
	return row
end
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 colspan = '2'
	cellI = mw.html.create('td')
			:attr({colspan = colspan})
			:attr({align = 'center'})
	
	local styleT = {}
	styleT['background-color'] = 'transparent'
	styleT['width'] = '100%'
	tabC = mw.html.create('table')
			:attr({cellspacing = '0'})
			:addClass('navigation-not-searchable')
			:css(styleT)
	
	local row = mw.html.create('tr')

	local color = params.color

	local style = {}
	local arrowLeft
	local arrowRight
	
	if color == 'default' then
		style['background-color'] = '#E6E6E6'
		arrowLeft = '[[Fichier:Fleche-defaut-gauche.png|13px|alt=Précédent|link=]]'
		arrowRight = '[[Fichier:Fleche-defaut-droite.png|13px|alt=Précédent|link=]]'
	else
		style['background-color'] = color
		arrowLeft = '[[Fichier:Fleche-defaut-gauche-gris-32.png|13px|alt=Suivant|link=]]'
		arrowRight = '[[Fichier:Fleche-defaut-droite-gris-32.png|13px|alt=Suivant|link=]]'
	end
	
	local styleTrans = {}
	styleTrans['background-color'] = '#F9F9F9'
	
	local values = params.value
	local before = values['before']
	local center = values['center']
	local after = values['after']
	
	local widthCell = '44%'
	if center then
		widthCenter = '28%'
		widthCell = '29%'
	end
	
	local formattedbefore
	if before then
		formattedbefore = mw.html.create('td')
			:attr({valign = 'middle'})
			:attr({align = 'left'})
			:attr({width = '5%'})
			:css(style)
			:wikitext(arrowLeft)
			:done()
		row:node(formattedbefore)
		formattedbefore = mw.html.create('td')
			:attr({width = '1%'})
			:css(style)
			:wikitext('')
			:done()
		row:node(formattedbefore)
		formattedbefore = mw.html.create('td')
			:attr({align = 'left'})
			:attr({valign = 'middle'})
			:attr({width = widthCell})
			:css(style)
			:wikitext(before)
			:done()
		row:node(formattedbefore)
	else
		formattedbefore = mw.html.create('td')
			:attr({valign = 'middle'})
			:attr({align = 'left'})
			:attr({width = '5%'})
			:css(styleTrans)
			:wikitext('')
			:done()
		row:node(formattedbefore)
		formattedbefore = mw.html.create('td')
			:attr({width = '1%'})
			:css(styleTrans)
			:wikitext('')
			:done()
		row:node(formattedbefore)
		formattedbefore = mw.html.create('td')
			:attr({align = 'left'})
			:attr({valign = 'middle'})
			:attr({width = widthCell})
			:css(styleTrans)
			:wikitext('')
			:done()
		row:node(formattedbefore)
	end
	
	local formattedcenter
	formattedcenter = mw.html.create('td')
		:attr({width = '1%'})
		:css(styleTrans)
		:wikitext('')
		:done()
	row:node(formattedcenter)
	
	if center then
		formattedcenter = mw.html.create('td')
			:attr({align = 'center'})
			:attr({valign = 'middle'})
			:attr({width = widthCenter})
			:css(style)
			:wikitext(center)
			:done()
		row:node(formattedcenter)
		formattedcenter = mw.html.create('td')
			:attr({width = '1%'})
			:css(styleTrans)
			:wikitext('')
			:done()
		row:node(formattedcenter)
	end
	
	local formattedafter
	if after then
		formattedafter = mw.html.create('td')
			:attr({align = 'right'})
			:attr({valign = 'middle'})
			:attr({width = widthCell})
			:css(style)
			:wikitext(after)
			:done()
		row:node(formattedafter)
		formattedbefore = mw.html.create('td')
			:attr({width = '1%'})
			:css(style)
			:wikitext('')
			:done()
		row:node(formattedbefore)
		formattedafter = mw.html.create('td')
			:attr({align = 'right'})
			:attr({valign = 'middle'})
			:attr({width = '5%'})
			:css(style)
			:wikitext(arrowRight)
			:done()
		row:node(formattedafter)
	else
		formattedafter = mw.html.create('td')
			:attr({align = 'right'})
			:attr({valign = 'middle'})
			:attr({width = widthCell})
			:css(styleTrans)
			:wikitext('')
			:done()
		row:node(formattedafter)
		formattedbefore = mw.html.create('td')
			:attr({width = '1%'})
			:css(styleTrans)
			:wikitext('')
			:done()
		row:node(formattedbefore)
		formattedafter = mw.html.create('td')
			:attr({align = 'right'})
			:attr({valign = 'middle'})
			:attr({width = '5%'})
			:css(styleTrans)
			:wikitext('')
			:done()
		row:node(formattedafter)
	end
	
	row:done()
	tabC:node(row)
	tabC:done()
	cellI:node(tabC)
	cellI:done()
	rowI:node(cellI)
	rowI:allDone()
	
	return rowI
end
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 class = params.class
	local rowcolor
	if params.color == 'secondcolor' then
		rowcolor = secondcolor
	else
		rowcolor = params.color
	end
	
	local style = {}
	style['padding'] = '4px'
	style['text-align'] = 'center'
	style['background-color'] = rowcolor or '#F9F9F9'
	style['color'] = '#000000'
	
	local text = params.value

	local colspan ='2'

	local formattedlabel
	formattedlabel = mw.html.create('th')
		:attr({colspan = colspan})
		:css(style)
		:wikitext(text)
		:done()

	local row = mw.html.create('tr')
		:addClass(class)
		:css(style)
		:node(formattedlabel)
		:done()
	
	return row
end
p.buildRow1Col = p.buildrow1col

function p.buildtable(params)
	local tab = mw.html.create('table'):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

function p.buildinvalidblock(args)
	addMaintenanceCat(defaultcat)
	local text = ''
	if type(args) ~= 'table' then
		text = "Les blocs d'infobox doivent être des tables"
	else
		text = i18n["invalid block type"] .. ' : ' .. (args.type or '??')
	end
	return text
end
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("Erreur d'Infobox/Image trop grande")
		return 'image trop grande, la largeur doit être inférieure ou égale à 280px'
	end

	-- récupération des données locales
	local 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 class = 'navbar noprint bordered ' .. (params.class or '')
	local style = params.style or {}
	style['border-top'] = style['border-top'] or '1px solid ' .. maincolor
	
	local backlinkstr = '[' .. tostring( mw.uri.fullUrl( page.name, 'veaction=edit&section=0' ) ) .. ' ' .. i18n['edit'] .. ']'
		.. ' - [' .. tostring( mw.uri.fullUrl( page.name, 'action=edit&section=0' ) ) .. ' ' .. i18n['edit code'] .. ']'

	local itemlinkstr
	if localdata.item then
		itemlinkstr = '[[d:' .. localdata.item.id .. '|' .. 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 = '[[Fichier:Info Simple.svg|12px|link=' .. localdata.templatename .. '|' .. 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(class)
		: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,
		['navbox'] = p.buildnavbox,
		['table'] = p.buildtable,
		['row'] = p.buildrow,
		['row1col'] = p.buildrow1col,
		['succession'] = p.buildnavbox,
		['text'] = p.buildtext,
		['title'] = p.buildtitle,
	}
	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' )
	item = localdata.item

	-- 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.id)
		local pagetitle = mw.title.getCurrentTitle().text
		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
	-- defines main color
	maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or moduledata.maincolor or maincolor
	secondcolor = moduledata.secondcolor or secondcolor
	thirdcolor = localdata['texte noir'] or localdata['couleur texte'] or moduledata.thirdcolor or thirdcolor
	if maincolor:match( '^%x%x%x%x%x%x$' ) or maincolor:match( '^%x%x%x$' ) then
		maincolor = '#' .. maincolor
	end
	if thirdcolor:match ('oui') or thirdcolor:match( 'true' ) then
		thirdcolor = '#000'
	end
	if thirdcolor:match ('non') or thirdcolor:match( 'false' ) then
		thirdcolor = '#fff'
	end
	
	-- class
	local class = 'infobox_v3 large'
	if moduledata.class then
		class = class .. ' ' .. moduledata.class
	end
	
	-- style
	local style = moduledata.style or {}
	
	-- build infobox
	infobox	:addClass(class)
			:css(style)
	for i, j in pairs( moduledata.parts ) do
		infobox:node( p.buildblock(j) )
	end
	infobox	:node(p.buildfooter(moduledata.footer))
			:done()

	return tostring(infobox) .. externaltext, maintenance
end

return p