Module:Infobox : Différence entre versions

De Lagny-sur-Marne Wiki
Aller à : navigation, rechercher
(+ passage de marker et default_zoom)
 
(275 révisions intermédiaires par 13 utilisateurs non affichées)
Ligne 1 : Ligne 1 :
--
 
-- This module implements {{Infobox}}
 
--
 
 
 
local p = {}
 
local p = {}
+
local lang = 'fr'
local HtmlBuilder = require('Module:HtmlBuilder')
+
 
+
local item = nil -- l'élément Wikidata lié
local args = {}
+
local localdata = {}-- données concernant les paramètres passés au modèle
local origArgs
+
local page = { -- données concernant la page où est affichée l'infobox
local root
+
name = mw.title.getCurrentTitle().prefixedText,
+
namespace =  mw.title.getCurrentTitle().namespace
function union(t1, t2)
+
}
    -- Returns the union of the values of two tables, as a sequence.
+
local maincolor, secondcolor, thirdcolor = '#E1E1E1', '#E1E1E1', '#000000'
    local vals = {}
+
-- l'objet principal à retournerp
    for k, v in pairs(t1) do
+
local infobox = mw.html.create('div')
        vals[v] = true
+
 
    end
+
-- objes secondaires à retourner
    for k, v in pairs(t2) do
+
local maintenance = '' -- chaîne retournfoée avec le module : cats de maintenance
        vals[v] = true
+
local externaltext = '' -- par exemple coordonnées en titre
    end
+
-- modules importés
    local ret = {}
+
local wikidata = require('Module:Interface Wikidata').fromLua
    for k, v in pairs(vals) do
+
local valueexpl = wikidata.translate("activate-query")
        table.insert(ret, k)
+
local linguistic = require "Module:Linguistique"
    end
+
local wd = require 'Module:Wikidata'
    return ret
+
local mapmod = require "Module:Carte"
 +
 
 +
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 .. wikidata.addtrackingcat(prop)
 
end
 
end
+
 
local function getArgNums(prefix)
+
local function expandquery(query)
    -- Returns a table containing the numbers of the arguments that exist
+
local value, number -- valeur à retourner, nombre de valeurs pour accorder le libellé
    -- for the specified prefix. For example, if the prefix was 'data', and
+
if not query.entity then
    -- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}.
+
query.entity = localdata.item
    local nums = {}
+
end
    for k, v in pairs(args) do
+
if not query.conjtype then
        local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
+
query.conjtype = 'comma'
        if num then table.insert(nums, tonumber(num)) end
+
end
    end
+
local claims = wikidata.getClaims(query)
    table.sort(nums)
+
if (not claims) then
    return nums
+
return nil
 +
end
 +
return wikidata.formatAndCat(query), #claims -- pour l'accord au pluriel
 
end
 
end
+
 
local function addRow(rowArgs)
+
local function getWikidataValue(params, wikidataparam)
    -- Adds a row to the infobox, with either a header cell
+
-- Récupère la valeur Wikidata pour la valeur, soit dans le paramètre "wikidata" soit dans le praramètre "property"
    -- or a label/data cell combination.
+
if not localdata.item then
    if rowArgs.header then
+
return nil
        root
+
end
            .tag('tr')
+
local v, valnum -- la valeur à retourner, et le nombre de de valeurs (pour l'accord grammatical)
                .tag('th')
+
                    .attr('colspan', 2)
+
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
                    .addClass(rowArgs.class)
+
wikidataparam = 'wikidata'
                    .css('text-align', 'center')
+
end
                    .cssText(args.headerstyle)
+
 
                    .wikitext(rowArgs.header)
+
if params[wikidataparam] then
    elseif rowArgs.data then
+
if type(params[wikidataparam]) == 'function' then
        local row = root.tag('tr')
+
v, valnum = params[wikidataparam](localdata.item)
        row.addClass(rowArgs.rowclass)
+
elseif type(params[wikidataparam]) == 'table' then
        if rowArgs.label then
+
v, valnum = expandquery(params[wikidataparam])
            row
+
else
                .tag('th')
+
v, valnum = params[wikidataparam]
                    .attr('scope', 'row')
+
end
                    .css('text-align', 'left')
+
end
                    .cssText(args.labelstyle)
+
if not v then
                    .wikitext(rowArgs.label)
+
return nil
                    .done()
+
end
        end
+
v = linguistic.ucfirst(v)
+
return v, valnum
        local dataCell = row.tag('td')
 
        if not rowArgs.label then  
 
            dataCell
 
                .attr('colspan', 2)
 
                .css('text-align', 'center')
 
        end
 
        dataCell
 
            .addClass(rowArgs.class)
 
            .cssText(rowArgs.datastyle)
 
            .newline()
 
            .wikitext(rowArgs.data)
 
    end
 
 
end
 
end
+
 
local function renderTitle()
+
local function getvalue(val, params)
    if not args.title then return end
+
if type(val) == 'string' then
+
return localdata[val]
    root
+
elseif type(val) == 'function' then
        .tag('caption')
+
return val(localdata, localdata.item, params)
            .addClass(args.titleclass)
+
elseif type(val) == 'table' then
            .cssText(args.titlestyle)
+
for i, j in pairs(val) do -- si plusieurs paramètres possibles (legacy de vieux code), prendre le preimeir non bide
            .wikitext(args.title)
+
if localdata[j] then
 +
return localdata[j]
 +
end
 +
end
 +
end
 
end
 
end
+
 
local function renderAboveRow()
+
local function addmaintenancecat(cat, sortkey)
    if not args.above then return end
+
if page.namespace ~= 0 then
+
return ''
    root
+
end
        .tag('tr')
+
if cat then
            .tag('th')
+
maintenance = maintenance .. '[[Category:' .. cat .. '|' .. (sortkey or page.name) .. ']]'
                .attr('colspan', 2)
+
end
                .addClass(args.aboveclass)
 
                .css('text-align', 'center')
 
                .css('font-size', '125%')
 
                .css('font-weight', 'bold')
 
                .cssText(args.abovestyle)
 
                .wikitext(args.above)
 
 
end
 
end
+
 
local function renderBelowRow()
+
function p.separator(params)
    if not args.below then return end
+
local style = params['separator style'] or {}
+
style.height = style.height or '2px'
    root
+
style['background-color'] = style['background-color'] or maincolor
        .tag('tr')
+
            .tag('td')
+
return mw.html.create('hr'):css( style )
                .attr('colspan', '2')
 
                .addClass(args.belowclass)
 
                .css('text-align', 'center')
 
                .cssText(args.belowstyle)
 
                .newline()
 
                .wikitext(args.below)
 
 
end
 
end
   
+
 
local function renderSubheaders()
+
function p.buildtitle(params)
    if args.subheader then
+
local text = getvalue(params.value, params) or params.textdefaultvalue or getWikidataValue(params) or mw.title.getCurrentTitle().text
        args.subheader1 = args.subheader
+
local subtext = getvalue(params.subtitle) or  getWikidataValue(params, 'wikidatasubtitle') or params.subtitledefaultvalue
    end
+
if subtext and (subtext ~= text) then
    if args.subheaderrowclass then
+
text = text .. '<br /><small>' .. subtext .. '</small>'
        args.subheaderrowclass1 = args.subheaderrowclass
+
end
    end
+
local icon = params.icon or ''
    local subheadernums = getArgNums('subheader')
+
if icon ~= '' and not params.large then
    for k, num in ipairs(subheadernums) do
+
icon = 'icon ' .. icon
        addRow({
+
end
            data = args['subheader' .. tostring(num)],
+
local class = 'entete ' .. icon
            datastyle = args.subheaderstyle or args['subheaderstyle' .. tostring(num)],
+
            class = args.subheaderclass,
+
-- overwrites with those provided in the module
            rowclass = args['subheaderrowclass' .. tostring(num)]
+
local style = {}
        })
+
style['background-color'] = maincolor
    end
+
style['color'] = thirdcolor
 +
if params.style then
 +
for i, j in pairs(params.style) do
 +
style[i] = j
 +
end
 +
end
 +
local title = mw.html.create('div')
 +
:addClass(class)
 +
:css(style)
 +
:tag('div')
 +
:wikitext(text)
 +
:allDone()
 +
return title
 
end
 
end
+
 
local function renderImages()
+
function p.buildnavbox(params)
    if args.image then
+
        args.image1 = args.image
+
-- définition du style
    end
+
local class = "overflow nav " .. (params.class or '')
    if args.caption then
+
local style = params.style or {}
        args.caption1 = args.caption
+
 
    end
+
if params.separated then -- options pour ajouter une ligne de séparation au dessus
    local imagenums = getArgNums('image')
+
class = class .. ' bordered'
    for k, num in ipairs(imagenums) do
+
style['border-top'] = '1px solid' .. maincolor
        local caption = args['caption' .. tostring(num)]
+
end
        local data = HtmlBuilder.create().wikitext(args['image' .. tostring(num)])
+
 
        if caption then
+
-- ajustement des paramètres de données
            data
+
params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète
                .tag('br', {selfClosing = true})
+
params.nextval = params.nextval or params.nextparameter
                    .done()
+
                .tag('div')
+
if params.previousproperty then
                    .cssText(args.captionstyle)
+
params.previouswikidata = {property = params.previousproperty}
                    .wikitext(caption)
+
end
        end
+
if params.nextproperty then
        addRow({
+
params.nextwikidata = {property = params.nextproperty}
            data = tostring(data),
+
end
            datastyle = args.imagestyle,
+
            class = args.imageclass,
+
 
            rowclass = args['imagerowclass' .. tostring(num)]
+
local previousval = getvalue(params.previousval, params) or getWikidataValue(params, 'previouswikidata')
        })
+
local nextval = getvalue(params.nextval, params) or getWikidataValue(params, 'nextwikidata')
    end
+
 +
local navbox
 +
if params.inner then -- pour celles qui sont à l'intérieur d'une table
 +
navbox = mw.html.create('tr'):tag('th'):attr('colspan', 2)
 +
style['font-weight'] = style['font-weight'] or 'normal'
 +
else
 +
navbox = mw.html.create('div')
 +
end
 +
 +
navbox
 +
:addClass(class)
 +
:css(style)
 +
:tag('div')
 +
:addClass('prev_bloc')
 +
:wikitext(previousval)
 +
:done()
 +
:tag('div')
 +
:addClass('next_bloc')
 +
:wikitext(nextval)
 +
:done()
 +
:allDone()
 +
return navbox
 
end
 
end
   
+
 
local function renderRows()
+
function p.buildimages(params)
    -- Gets the union of the header and data argument numbers,
+
local images = {}
    -- and renders them all in order using addRow.
+
local upright, link, caption, alt, size -- size is deprecated
    local rownums = union(getArgNums('header'), getArgNums('data'))
+
if type(params.imageparameters) == 'string' then
    table.sort(rownums)
+
params.imageparameters = {params.imageparameters}
    for k, num in ipairs(rownums) do
+
end
        addRow({
+
if not params.imageparameters then -- s'il n'y a pa de paramètre image, continuer, peut-être y-a-t-il une image par défaut définie dans le module d'infobox
            header = args['header' .. tostring(num)],
+
params.imageparameters = {}
            label = args['label' .. tostring(num)],
+
end
            data = args['data' .. tostring(num)],
+
for j, k in ipairs(params.imageparameters) do
            datastyle = args.datastyle,
+
table.insert(images, localdata[k])
            class = args['class' .. tostring(num)],
+
end
            rowclass = args['rowclass' .. tostring(num)]
+
        })
+
-- Images de Wikidata
    end
+
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
 +
if type(wdq) == 'table' then
 +
wdq.entity = wdq.entity or localdata.item
 +
images = wikidata.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
 +
-- Récupération des légendes de Wikidata (par P2096 seulement, à rendre optionnel et plus flexible)
 +
if type(images[1]) == 'table' then
 +
for i, j in pairs(images) do
 +
if j.mainsnak.snaktype ~= 'value' then
 +
return
 +
end
 +
local wdcaptions, wdcaption
 +
local q = images[i].qualifiers
 +
if q then
 +
wdcaptions = q['P2096']
 +
end
 +
if wdcaptions then
 +
for k, l in pairs(wdcaptions) do
 +
if l.datavalue.value and l.datavalue.value.language == lang then
 +
wdcaption = wd.formatSnak(l)
 +
end
 +
end
 +
end
 +
if wdcaption and caption then -- si deux légendes, désactivées pour éviter les conflits
 +
caption = nil
 +
elseif wdcaption then
 +
caption = wdcaption
 +
end
 +
if i > (params.numval) then
 +
images[i] = nil
 +
else
 +
images[i] = j.mainsnak.datavalue.value
 +
end
 +
end
 +
end
 +
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
 +
 +
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('p')
 +
:wikitext(caption)
 +
:css(params.style or {})
 +
:addClass("legend")
 +
:done()
 +
end
 +
 +
-- séparateur
 +
local separator
 +
if params.separator then
 +
separator = separator(params)
 +
end
 +
return mw.html.create('div')
 +
:node(image)
 +
:node(captionobj)
 +
:node(separator)
 +
:done()
 
end
 
end
+
 
local function renderNavBar()
+
function p.buildtext(params)
    if not args.name 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
                .css('text-align', 'right')
+
for i, j in pairs(params.style) do
                .wikitext(mw.getCurrentFrame():expandTemplate({
+
style[i] = j
                    title = 'navbar',  
+
end
                    args = { args.name, mini = 1 }
+
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
+
 
local function renderItalicTitle()
+
function p.buildrow(params)
    local italicTitle = args['italic title'] and mw.ustring.lower(args['italic title'])
+
local class = params.class or ''
    if italicTitle == '' or italicTitle == 'force' or italicTitle == 'yes' then
+
local style = params.style or {}
        root.wikitext(mw.getCurrentFrame():expandTemplate({title = 'italic title'}))
+
local value, number =  getvalue(params.value, params)
    end
+
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
 
end
+
 
local function renderTrackingCategories()
+
function p.buildsuccession(params)
    if args.decat ~= 'yes' then
+
if not params.value then
        if #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then
+
return nil
            root.wikitext('[[Category:Articles which use infobox templates with no data rows]]')
+
end
        end
+
        if args.child == 'yes' and args.title then
+
--local style = params.style or {}
            root.wikitext('[[Category:Articles which use embedded infobox templates with the title parameter]]')
+
--style['text-align'] = style['text-align'] or 'center'
        end
+
--style['color'] = style['color'] or '#000000'
    end
+
--style['background-color'] = style['background-color'] or '#F9F9F9'
 +
 +
local rowI = mw.html.create('tr')
 +
 +
local colspan = '2'
 +
cellI = mw.html.create('td')
 +
:attr({colspan = colspan})
 +
:attr({align = 'center'})
 +
 +
local styleT = {}
 +
styleT['background-color'] = 'transparent'
 +
styleT['width'] = '100%'
 +
tabC = mw.html.create('table')
 +
:attr({cellspacing = '0'})
 +
:css(styleT)
 +
 +
local row = mw.html.create('tr')
 +
 
 +
local color = params.color
 +
 
 +
local style = {}
 +
local arrowLeft
 +
local arrowRight
 +
 +
if color == 'default' then
 +
style['background-color'] = '#E6E6E6'
 +
arrowLeft = '[[Fichier:Fleche-defaut-gauche.png|13px|alt=Précédent|link=]]'
 +
arrowRight = '[[Fichier:Fleche-defaut-droite.png|13px|alt=Précédent|link=]]'
 +
else
 +
style['background-color'] = color
 +
arrowLeft = '[[Fichier:Fleche-defaut-gauche-gris-32.png|13px|alt=Suivant|link=]]'
 +
arrowRight = '[[Fichier:Fleche-defaut-droite-gris-32.png|13px|alt=Suivant|link=]]'
 +
end
 +
 +
local styleTrans = {}
 +
styleTrans['background-color'] = '#F9F9F9'
 +
 +
local values = params.value
 +
local before = values['before']
 +
local center = values['center']
 +
local after = values['after']
 +
 +
local widthCell = '44%'
 +
if center then
 +
widthCenter = '28%'
 +
widthCell = '29%'
 +
end
 +
 +
local formattedbefore
 +
if before then
 +
formattedbefore = mw.html.create('td')
 +
:attr({valign = 'middle'})
 +
:attr({align = 'left'})
 +
:attr({width = '5%'})
 +
:css(style)
 +
:wikitext(arrowLeft)
 +
:done()
 +
row:node(formattedbefore)
 +
formattedbefore = mw.html.create('td')
 +
:attr({width = '1%'})
 +
:css(style)
 +
:wikitext('')
 +
:done()
 +
row:node(formattedbefore)
 +
formattedbefore = mw.html.create('td')
 +
:attr({align = 'left'})
 +
:attr({valign = 'middle'})
 +
:attr({width = widthCell})
 +
:css(style)
 +
:wikitext(before)
 +
:done()
 +
row:node(formattedbefore)
 +
else
 +
formattedbefore = mw.html.create('td')
 +
:attr({valign = 'middle'})
 +
:attr({align = 'left'})
 +
:attr({width = '5%'})
 +
:css(styleTrans)
 +
:wikitext('')
 +
:done()
 +
row:node(formattedbefore)
 +
formattedbefore = mw.html.create('td')
 +
:attr({width = '1%'})
 +
:css(styleTrans)
 +
:wikitext('')
 +
:done()
 +
row:node(formattedbefore)
 +
formattedbefore = mw.html.create('td')
 +
:attr({align = 'left'})
 +
:attr({valign = 'middle'})
 +
:attr({width = widthCell})
 +
:css(styleTrans)
 +
:wikitext('')
 +
:done()
 +
row:node(formattedbefore)
 +
end
 +
 +
local formattedcenter
 +
formattedcenter = mw.html.create('td')
 +
:attr({width = '1%'})
 +
:css(styleTrans)
 +
:wikitext('')
 +
:done()
 +
row:node(formattedcenter)
 +
 +
if center then
 +
formattedcenter = mw.html.create('td')
 +
:attr({align = 'center'})
 +
:attr({valign = 'middle'})
 +
:attr({width = widthCenter})
 +
:css(style)
 +
:wikitext(center)
 +
:done()
 +
row:node(formattedcenter)
 +
formattedcenter = mw.html.create('td')
 +
:attr({width = '1%'})
 +
:css(styleTrans)
 +
:wikitext('')
 +
:done()
 +
row:node(formattedcenter)
 +
end
 +
 +
local formattedafter
 +
if after then
 +
formattedafter = mw.html.create('td')
 +
:attr({align = 'right'})
 +
:attr({valign = 'middle'})
 +
:attr({width = widthCell})
 +
:css(style)
 +
:wikitext(after)
 +
:done()
 +
row:node(formattedafter)
 +
formattedbefore = mw.html.create('td')
 +
:attr({width = '1%'})
 +
:css(style)
 +
:wikitext('')
 +
:done()
 +
row:node(formattedbefore)
 +
formattedafter = mw.html.create('td')
 +
:attr({align = 'right'})
 +
:attr({valign = 'middle'})
 +
:attr({width = '5%'})
 +
:css(style)
 +
:wikitext(arrowRight)
 +
:done()
 +
row:node(formattedafter)
 +
else
 +
formattedafter = mw.html.create('td')
 +
:attr({align = 'right'})
 +
:attr({valign = 'middle'})
 +
:attr({width = widthCell})
 +
:css(styleTrans)
 +
:wikitext('')
 +
:done()
 +
row:node(formattedafter)
 +
formattedbefore = mw.html.create('td')
 +
:attr({width = '1%'})
 +
:css(styleTrans)
 +
:wikitext('')
 +
:done()
 +
row:node(formattedbefore)
 +
formattedafter = mw.html.create('td')
 +
:attr({align = 'right'})
 +
:attr({valign = 'middle'})
 +
:attr({width = '5%'})
 +
:css(styleTrans)
 +
:wikitext('')
 +
:done()
 +
row:node(formattedafter)
 +
end
 +
 +
row:done()
 +
tabC:node(row)
 +
tabC:done()
 +
cellI:node(tabC)
 +
cellI:done()
 +
rowI:node(cellI)
 +
rowI:allDone()
 +
 +
return rowI
 
end
 
end
+
 
local function _infobox()
+
function p.buildrow1col(params)
    -- Specify the overall layout of the infobox, with special settings
+
    -- if the infobox is used as a 'child' inside another infobox.
+
if not params.value then
    if args.child ~= 'yes' then
+
return nil
        root = HtmlBuilder.create('table')
+
end
+
        root
+
--local style = params.style or {}
            .addClass('infobox')
+
--style['text-align'] = style['text-align'] or 'center'
            .addClass(args.bodyclass)
+
--style['color'] = style['color'] or '#000000'
            .attr('cellspacing', 3)
+
--style['background-color'] = style['background-color'] or '#F9F9F9'
            .css('border-spacing', '3px')
+
local class = params.class
+
local rowcolor
            if args.subbox == 'yes' then
+
if params.color == 'secondcolor' then
                root
+
rowcolor = secondcolor
                    .css('padding', '0')
+
else
                    .css('border', 'none')
+
rowcolor = params.color
                    .css('margin', '-3px')
+
end
                    .css('width', 'auto')
+
                    .css('min-width', '100%')
+
local style = {}
                    .css('font-size', '100%')
+
style['padding'] = '4px'
                    .css('clear', 'none')
+
style['text-align'] = 'center'
                    .css('float', 'none')
+
style['background-color'] = rowcolor or '#F9F9F9'
                    .css('background-color', 'transparent')
+
style['color'] = '#000000'
            else
+
                root
+
local text = params.value
                    .css('width', '22em')
+
 
            end
+
local colspan ='2'
        root
+
 
            .cssText(args.bodystyle)
+
local formattedlabel
+
formattedlabel = mw.html.create('th')
        renderTitle()
+
:attr({colspan = colspan})
        renderAboveRow()
+
:css(style)
    else
+
:wikitext(text)
        root = HtmlBuilder.create()
+
:done()
+
 
        root
+
local row = mw.html.create('tr')
            .wikitext(args.title)
+
:addClass(class)
    end
+
:css(style)
+
:node(formattedlabel)
    renderSubheaders()
+
:done()
    renderImages()  
+
    renderRows()
+
return row
    renderBelowRow() 
 
    renderNavBar()
 
    renderItalicTitle()
 
    renderTrackingCategories()
 
 
    return tostring(root)
 
 
end
 
end
+
 
local function preprocessSingleArg(argName)
+
function p.buildtable(params)
    -- If the argument exists and isn't blank, add it to the argument table.
+
local tab = mw.html.create('table'):css(params.style or {})
    -- Blank arguments are treated as nil to match the behaviour of ParserFunctions.
+
 
    if origArgs[argName] and origArgs[argName] ~= '' then
+
-- CREATE ROWS
        args[argName] = origArgs[argName]
+
local rows = {}
    end
+
for k, l in pairs(params.rows) do
 +
if type(l) == 'table' and l.type == 'multi' then -- when a single function is used for return several rows
 +
table.remove(params.rows, k)
 +
local count = 0
 +
for m, n in pairs(l.rows) do
 +
table.insert(params.rows, k + count, n)
 +
count = count + 1
 +
end
 +
l = params.rows[k]
 +
end
 +
 
 +
if type(l) == 'function' then --accepte les fonctions qui retournent des tables
 +
l = l(localdata, localdata.item)
 +
end
 +
if type(l) == 'nil' then
 +
--ne rien faire (quand la valeur est originellemenet une fonctin elle peut retourner nil)
 +
elseif type(l) ~= 'table' then
 +
return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l))
 +
else
 +
local row = p.buildblock(l)
 +
table.insert(rows, row)
 +
end
 +
end
 +
if #rows == 0 then
 +
return nil
 +
end
 +
 
 +
-- ADD TITLE
 +
local title
 +
if params.title or params.singulartitle or params.pluraltitle then
 +
local text
 +
if #rows > 1 and params.pluraltitle then
 +
text = 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
 
end
+
 
local function preprocessArgs(prefixTable, step)
+
function p.buildinvalidblock(args)
    -- Assign the parameters with the given prefixes to the args table, in order, in batches
+
addmaintenancecat(defaultcat)
    -- of the step size specified. This is to prevent references etc. from appearing in the
+
local text = ''
    -- wrong order. The prefixTable should be an array containing tables, each of which has
+
if type(args) ~= 'table' then
    -- two possible fields, a "prefix" string and a "depend" table. The function always parses
+
text = "Les blocs d'infobox doivent être des tables"
    -- parameters containing the "prefix" string, but only parses parameters in the "depend"
+
else
    -- table if the prefix parameter is present and non-blank.
+
text = i18n["invalid block type"] .. ' : ' .. (args.type or '??')
    if type(prefixTable) ~= 'table' then
+
end
        error("Non-table value detected for the prefix table", 2)
+
return text
    end
 
    if type(step) ~= 'number' then
 
        error("Invalid step value detected", 2)
 
    end
 
 
    -- Get arguments without a number suffix, and check for bad input.
 
    for i,v in ipairs(prefixTable) do
 
        if type(v) ~= 'table' or type(v.prefix) ~= "string" or (v.depend and type(v.depend) ~= 'table') then
 
            error('Invalid input detected to preprocessArgs prefix table', 2)
 
        end
 
        preprocessSingleArg(v.prefix)
 
        -- Only parse the depend parameter if the prefix parameter is present and not blank.
 
        if args[v.prefix] and v.depend then
 
            for j, dependValue in ipairs(v.depend) do
 
                if type(dependValue) ~= 'string' then
 
                    error('Invalid "depend" parameter value detected in preprocessArgs')
 
                end
 
                preprocessSingleArg(dependValue)
 
            end
 
        end
 
    end
 
 
    -- Get arguments with number suffixes.
 
    local a = 1 -- Counter variable.
 
    local moreArgumentsExist = true
 
    while moreArgumentsExist == true do
 
        moreArgumentsExist = false
 
        for i = a, a + step - 1 do
 
            for j,v in ipairs(prefixTable) do
 
                local prefixArgName = v.prefix .. tostring(i)
 
                if origArgs[prefixArgName] then
 
                    moreArgumentsExist = true -- Do another loop if any arguments are found, even blank ones.
 
                    preprocessSingleArg(prefixArgName)
 
                end
 
                -- Process the depend table if the prefix argument is present and not blank, or
 
                -- we are processing "prefix1" and "prefix" is present and not blank, and
 
                -- if the depend table is present.
 
                if v.depend and (args[prefixArgName] or (i == 1 and args[v.prefix])) then
 
                    for j,dependValue in ipairs(v.depend) do
 
                        local dependArgName = dependValue .. tostring(i)
 
                        preprocessSingleArg(dependArgName)
 
                    end
 
                end
 
            end
 
        end
 
        a = a + step
 
    end
 
 
end
 
end
+
 
function p.infobox(frame)
+
function p.buildmap(params)-- TODO  : gestion de plusieurs points
    -- If called via #invoke, use the args passed into the invoking template.
+
 
    -- Otherwise, for testing purposes, assume args are being passed directly in.
+
-- paramètre d'affichage
    if frame == mw.getCurrentFrame() then
+
local maplist = getvalue(params.maps)
        origArgs = frame:getParent().args
+
local pointtype = params.pointtype
    else
+
local maptype = params.maptype -- choisit le type de carte le plus approprié (relief, administratif, etc.)
        origArgs = frame
+
if type(maplist) == 'function' then
    end
+
maplist = maplist(localdata, localdata.item)
+
end
    -- Parse the data parameters in the same order that the old {{infobox}} did, so that
+
local width = tonumber(params.width) or 280
    -- references etc. will display in the expected places. Parameters that depend on
+
if width > 280 then
    -- another parameter are only processed if that parameter is present, to avoid
+
addmaintenancecat("Erreur d'Infobox/Image trop grande")
    -- phantom references appearing in article reference lists.
+
return 'image trop grande, la largeur doit être inférieure ou égale à 280px'
    preprocessSingleArg('child')
+
end
    preprocessSingleArg('bodyclass')
+
 
    preprocessSingleArg('subbox')
+
-- récupération des données locales
    preprocessSingleArg('bodystyle')
+
local latitude, longitude, globe = params.latitude, params.longitude, params.globe
    preprocessSingleArg('title')
+
if type(params.latitude) == 'function' then
    preprocessSingleArg('titleclass')
+
latitude, longitude = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item)
    preprocessSingleArg('titlestyle')
+
else
    preprocessSingleArg('above')
+
latitude, longitude = localdata[params.latitude], localdata[params.longitude]
    preprocessSingleArg('aboveclass')
+
end
    preprocessSingleArg('abovestyle')
+
    preprocessArgs({
+
-- récupération des données wikidata
        {prefix = 'subheader', depend = {'subheaderstyle', 'subheaderrowclass'}}
+
if (not latitude or not longitude) and params.wikidata then
    }, 10)
+
local query = params.wikidata
    preprocessSingleArg('subheaderstyle')
+
if type(query) == 'function' then
    preprocessSingleArg('subheaderclass')
+
query = query()
    preprocessArgs({
+
end
        {prefix = 'image', depend = {'caption', 'imagerowclass'}}
+
if not query then
    }, 10)
+
return nil
    preprocessSingleArg('captionstyle')
+
end
    preprocessSingleArg('imagestyle')
+
query.excludespecial = true
    preprocessSingleArg('imageclass')
+
query.entity = query.entity or localdata.item
    preprocessArgs({
+
local claims = wikidata.getClaims(query)
        {prefix = 'header'},
+
if not claims then
        {prefix = 'data', depend = {'label', 'rowclass'}},
+
return nil
        {prefix = 'class'}
+
end
    }, 50)
+
local val = wd.formatSnak( claims[1].mainsnak )
    preprocessSingleArg('headerstyle')
+
latitude, longitude, globe = val.latitude, val.longitude, val.globe
    preprocessSingleArg('labelstyle')
+
end
    preprocessSingleArg('datastyle')
+
    preprocessSingleArg('below')
+
if not latitude or not longitude then
    preprocessSingleArg('belowclass')
+
return nil
    preprocessSingleArg('belowstyle')
+
end
    preprocessSingleArg('name')
+
local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, latitude = latitude, longitude = longitude, globe = globe, marker=params.marker, default_zoom=params.default_zoom}
    args['italic title'] = origArgs['italic title'] -- different behaviour if blank or absent
+
if params.params and type(params.params) == 'table' then -- paramètres additionnels
    preprocessSingleArg('decat')
+
for i, j in pairs(params.params) do
+
newparams[i] = j
    return _infobox()
+
end
 +
end
 +
return mapmod.multimap(newparams)
 
end
 
end
   
+
 
 +
function p.buildexternaltext(params)
 +
local value = getvalue(params.value)
 +
if value and (type(value) == 'string') then
 +
externaltext = externaltext .. value
 +
end
 +
end
 +
 
 +
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 = '[[Image: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
 +
 
 +
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
 +
 
 +
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 =  moduledata.thirdcolor or thirdcolor
 +
if maincolor:match( '^%x%x%x%x%x%x$' ) or maincolor:match( '^%x%x%x$' ) then
 +
maincolor = '#' .. maincolor
 +
end
 +
 +
-- class
 +
local class = 'infobox_v3'
 +
if moduledata.class then
 +
class = class .. ' ' .. moduledata.class
 +
end
 +
 +
-- style
 +
local style = moduledata.style or {}
 +
if not style['max-width'] then
 +
style['max-width'] = '300px'
 +
end
 +
 +
-- build infobox
 +
infobox :addClass(class)
 +
:css(style)
 +
for i, j in pairs( moduledata.parts ) do
 +
infobox:node( p.buildblock(j) )
 +
end
 +
infobox :node(p.buildfooter(moduledata.footer))
 +
:done()
 +
 
 +
return tostring(infobox) .. externaltext, maintenance
 +
end
 +
 
 
return p
 
return p

Version actuelle datée du 20 mai 2017 à 09:18

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 à retournerp
local infobox = mw.html.create('div')

-- objes secondaires à retourner
local maintenance = '' -- chaîne retournfoée avec le module : cats de maintenance
local externaltext = '' -- par exemple coordonnées en titre
-- modules importés
local wikidata = require('Module:Interface Wikidata').fromLua
local valueexpl = wikidata.translate("activate-query")
local linguistic = require "Module:Linguistique"
local wd = require 'Module:Wikidata'
local mapmod = require "Module:Carte"

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 .. wikidata.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 = wikidata.getClaims(query)
		if (not claims) then
		return nil
	end
	return wikidata.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 praramètre "property"
	if not localdata.item then
		return nil
	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 preimeir non bide
			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 not params.large then
		icon = 'icon ' .. icon
	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

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

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 pa 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
			if type(wdq) == 'table' then
				wdq.entity = wdq.entity or localdata.item
				images = wikidata.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
			-- Récupération des légendes de Wikidata (par P2096 seulement, à rendre optionnel et plus flexible)
			if type(images[1]) == 'table' then
				for i, j in pairs(images) do
					if j.mainsnak.snaktype ~= 'value' then
						return
					end
					local wdcaptions, wdcaption
					local q = images[i].qualifiers
					if q then
						wdcaptions = q['P2096']
					end
					if wdcaptions then
						for k, l in pairs(wdcaptions) do
							if l.datavalue.value and l.datavalue.value.language == lang then
								wdcaption = wd.formatSnak(l)
							end
						end
					end
					if wdcaption and caption then -- si deux légendes, désactivées pour éviter les conflits
						caption = nil
					elseif wdcaption then
						caption = wdcaption
					end
					if i > (params.numval) then
						images[i] = nil
					else
						images[i] = j.mainsnak.datavalue.value
					end
				end
			end
		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
	
	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('p')
			:wikitext(caption)
			:css(params.style or {})
			:addClass("legend")
			:done()
	end
	
	-- séparateur
	local separator
	if params.separator then
		separator = separator(params)
	end
	return mw.html.create('div')
		:node(image)
		:node(captionobj)
		:node(separator)
		:done()
end

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

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

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'})
			: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

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

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

	-- CREATE ROWS
	local rows = {}
		for k, l in pairs(params.rows) do
		if type(l) == 'table' and l.type == 'multi' then -- when a single function is used for return several rows
			table.remove(params.rows, k)
			local count = 0
			for m, n in pairs(l.rows) do
				table.insert(params.rows, k + count, n)
				count = count + 1
			end
			l = params.rows[k]
		end

		if type(l) == 'function' then --accepte les fonctions qui retournent des tables
			l = l(localdata, localdata.item)
		end
		if type(l) == 'nil' then
			--ne rien faire (quand la valeur est originellemenet une fonctin elle peut retourner nil)
		elseif type(l) ~= 'table' then
			return error('les lignes d\'infobox ("rows") doivent être des tables, est ' .. type(l))
		else
			local row = p.buildblock(l)
			table.insert(rows, row)
		end
	end
	if #rows == 0 then
		return nil
	end

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

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

function p.buildmap(params)-- TODO  : gestion de plusieurs points

	-- 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 latitude, longitude, globe = params.latitude, params.longitude, params.globe
	if type(params.latitude) == 'function' then
		latitude, longitude = params.latitude(localdata, localdata.item), params.longitude(localdata, localdata.item)
	else
		latitude, longitude = localdata[params.latitude], localdata[params.longitude]
	end
	
	-- récupération des données wikidata
	if (not latitude or not longitude) and params.wikidata then
		local query = params.wikidata
		if type(query) == 'function' then
			query = query()
		end
		if not query then
			return nil
		end
		query.excludespecial = true
		query.entity = query.entity or localdata.item
		local claims = wikidata.getClaims(query)
		if not claims then
			return nil
		end
		local val = wd.formatSnak( claims[1].mainsnak )
		latitude, longitude, globe = val.latitude, val.longitude, val.globe
	end
	
	if not latitude or not longitude then
		return nil
	end
	local newparams = {maplist = maplist, pointtype = pointtype, maptype = maptype, width = width, item = localdata.item, latitude = latitude, longitude = longitude, globe = globe, marker=params.marker, default_zoom=params.default_zoom}
	if params.params and type(params.params) == 'table' then -- paramètres additionnels
		for i, j in pairs(params.params) do
			newparams[i] = j
		end
	end
	return mapmod.multimap(newparams)
end

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

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 = '[[Image: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

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

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 =  moduledata.thirdcolor or thirdcolor
	if maincolor:match( '^%x%x%x%x%x%x$' ) or maincolor:match( '^%x%x%x$' ) then
		maincolor = '#' .. maincolor
	end
	
	-- class
	local class = 'infobox_v3'
	if moduledata.class then
		class = class .. ' ' .. moduledata.class
	end
	
	-- style
	local style = moduledata.style or {}
	if not style['max-width'] then
		style['max-width'] = '300px'
	end
	
	-- build infobox
	infobox	:addClass(class)
			:css(style)
	for i, j in pairs( moduledata.parts ) do
		infobox:node( p.buildblock(j) )
	end
	infobox	:node(p.buildfooter(moduledata.footer))
			:done()

	return tostring(infobox) .. externaltext, maintenance
end

return p