Moduuli:Fr:Infobox
Ulkoasu
Käyttöohje ja tekniset tiedot moduulille Fr:Infobox
[ muokkaa ]
Tämä moduuli on osa ranskankielisestä Wikipediasta kopioitua Wikidata ja Interface Wikidata -moduulikokonaisuutta (ks. ohjeet ja esimerkit). Listauksen kaikista tähän liittyvistä moduuleista löydät Ranskankielisen Wikipedian Wikidata-moduulit -sivulta.
- Esimerkit käytöstä
- Alkuperäinen
- Ohjeet
- Tämän moduulin käyttämät moduulit
- Module:Fr:Linguistique
- Module:Fr:Wikidata
- Module:Fr:Carte
- Module:Fr:Infobox/Localdata
- Module:Fr:Formatage du titre
- Moduulit jotka käyttävät tätä
- Muutokset
- Käännökset ja nimiavaruuksien lokalisointi: [1]
- tyylit tulevat tyylisivulta Moduuli:Infobox v3/styles.css
local p = {}
local lang = 'fi'
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
}
-- uusi fr
--local maincolor, secondcolor, thirdcolor = 'var(--background-color-interactive-subtle, #f8f9fa)', 'var(--background-color-interactive-subtle, #f8f9fa)', 'var(--color-emphasized, #000000)'
-- vanha fi
--local maincolor, secondcolor, thirdcolor = '#E0E0E0', '#E0E0E0', '#000000'
-- uusi fi
-- todo: remove these colors from module, we get colors via css page
local maincolor, secondcolor = 'var(--background-color-interactive-subtle, #E0E0E0)', 'var(--background-color-interactive-subtle, #E0E0E0)'
--local thirdcolor = 'var(--color-emphasized, #000000)' -- text color, from css by theme now
-- l'objet principal à retournerp
local infobox = mw.html.create('div')
-- objes secondaires à retournerw
local maintenance = '' -- chaîne retournfoée avec le module : cats de maintenance
local externaltext = '' -- par exemple coordonnées en titre
-- modules importés
local linguistic = require "Module:Fr:Linguistique"
local wd = require 'Module:Fr:Wikidata'
local yesno = require 'Module:Yesno'
local valueexpl = wd.translate("activate-query")
-- maintenance des images dupliquées
local usedImages = {}
local i18n = {
['show wikidata backlinks'] = 'Näytä Wikidatasta tulevat arvot', -- Documentation du modèle
['see doc'] = 'Tietolaatikon dokumentaatio', -- Documentation du modèle
['edit'] = 'muokkaa', -- modifier
['edit code'] = 'muokkaa wikitekstiä', -- 'modifier le code
['edit item'] = 'muokkaa Wikidataa', -- modifier Wikidata
['tracking cat'] = "Wikidataa hyödyntävät artikkelit", -- Page utilisant des données de Wikidata
['invalid block type'] = "Tietolaatikon tyyppivirhe", -- Bloc de données invalide dans le module d'infobox
['default cat'] = "Huomiota kaipaavat tietolaatikot", -- Maintenance des infobox
}
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 praramè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.property and not params[wikidataparam] then params[wikidataparam] = {property = params.property} 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
if type(params[wikidataparam]) == 'table' then
if params[wikidataparam].ucfirst ~= "-" then
v = linguistic.ucfirst(v)
end
end
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
local sortkeycode
if sortkey then sortkeycode = '|' .. sortkey else sortkeycode = '' end
maintenance = maintenance .. '[[Category:'.. cat .. sortkeycode .. ']]'
end
end
function p.separator(params)
local classes = params['separator classes']
local style = params['separator style'] or {}
style.height = style.height or '2px'
style['background-color'] = style['background-color'] or maincolor
if style['background-color'] then
style.color = 'var( --color-base )'
end
return mw.html.create('hr'):addClass( classes ):css( style )
end
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
-- subtext returned by getWikidataValue is html. This fails if text is html too.
if subtext and ((text ~= subtext) and (string.find(subtext, ">" .. text .."[%[%<]") == nil)) then
text = text .. '<br /><small>' .. subtext .. '</small>'
end
if string.len(text) > 20 then
text = text .. "[[category:Sivut, joiden tietolaatikon otsikko on pitkä]]"
end
local icon = params.icon or ''
if icon ~= '' and not params.large then
icon = 'icon ' .. icon
end
local classes = 'entete ' .. icon
local italic = params.italic and yesno(localdata['titre en italique'] or '', true, true)
-- this css class is not currently in fi-wiki
--if italic then
-- classes = classes .. ' italique'
--end
if params.setdisplaytitle and yesno(localdata['titre article en italique'] or '', true, true) then
local formatTitleModule = require( 'Module:Fr:Formatage du titre' )
text = text .. formatTitleModule.setDisplayTitle{ args = {
lang = lang,
italic = italic,
options = 'noreplace',
} }
end
-- overwrites with those provided in the module
local style = {}
--style['background-color'] = maincolor
--style['color'] = thirdcolor -- text color
if params.style then
for i, j in pairs(params.style) do
style[i] = j
end
end
local title = mw.html.create('div')
:addClass(classes)
:css(style)
:tag('div')
:wikitext(text)
:allDone()
return title
end
function p.buildnavbox(params)
-- définition du style
--local class = "overflow nav " .. (params.class or '')
local classes = "overflow infobox-navigateur " .. (params.class or '')
local style = params.style or {}
if params.separated then -- options pour ajouter une ligne de séparation au dessus
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(classes)
:css(style)
:tag('div')
:addClass('prev_bloc')
:wikitext(previousval)
:done()
:tag('div')
:addClass('next_bloc')
:wikitext(nextval)
:done()
:allDone()
return navbox
end
-- korvaa aiemman buildnavbox()
function p.buildnavigator(params)
-- définition du style
local classes = "overflow infobox-navigateur " .. (params.class or '')
local style = params.style or {}
if params.separated then -- options pour ajouter une ligne de séparation au dessus
classes = classes .. ' bordered'
if maincolor then
style['border-top'] = '1px solid' .. maincolor
end
end
-- ajustement des paramètres de données
params.previousval = params.previousval or params.previousparameter -- nom de paramètre obsolète
params.nextval = params.nextval or params.nextparameter
if params.previousproperty then
params.previouswikidata = {property = params.previousproperty}
end
if params.nextproperty then
params.nextwikidata = {property = params.nextproperty}
end
local previousval = getValue(params.previousval, params) or getWikidataValue(params, 'previouswikidata')
local nextval = getValue(params.nextval, params) or getWikidataValue(params, 'nextwikidata')
if previousval == '-' then previousval = nil end
if nextval == '-' then nextval = nil end
local navigator
if params.inner then -- pour celles qui sont à l'intérieur d'une table
navigator = mw.html.create('tr'):tag('th'):attr('colspan', 2)
style['font-weight'] = style['font-weight'] or 'normal'
else
navigator = mw.html.create('div')
end
if previousval or nextval then
navigator
:addClass(classes)
:css(style)
:tag('div')
:addClass('prev_bloc')
:wikitext(previousval)
:done()
:tag('div')
:addClass('next_bloc')
:wikitext(nextval)
:done()
:allDone()
return navigator
end
return nil
end
--p.buildNavigator = p.buildnavigator
function p.buildimages(params)
local images = {}
local upright, link, caption, alt, size -- size is deprecated
local wikidataimageclass = ""
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 = wd.getClaims(wdq)
end
if type(wdq) == 'function' then
images = params.wikidata()
if type(images) == 'string' then
return images
end --c'est probablement une erreur dans la requête => afficher le message
end
if (not images) then
images = {}
end
if (#images > 0) and (params.wikidata.property) then
maintenance = maintenance .. wd.addTrackingCat(params.wikidata.property)
wikidataimageclass="wikidataimages"
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 or 2) 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 = mw.ustring.gsub(numsize, 'x.*', '')
numsize = tonumber(numsize)
if type(numsize) ~= 'number' or numsize > 300 then
addMaintenanceCat("Virheellinen kuvan koko" .. numsize)
end
if tonumber(size) then
size = size .. 'px'
end
size = '|' .. size
else
size = ''
end
if tonumber(upright) then
upright = tostring(tonumber(upright) )
end
if tonumber(size) then
size = tostring(tonumber(size) ) / #images
end
--local style = params.style or {padding ='2px 0',}
local style = params.style or {padding ='0',}
-- Partie image
local imagesString = ''
for i,image in pairs(images) do
if image == '-' then
return
end
imagesString = imagesString .. '[[Image:' .. 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
-- kielikohtainen versio svg:stä, toimiiko suomeksi jos ei ole kuvaa?
--if image:sub(-4):lower() == '.svg' then
-- imagesString = imagesString .. '|lang=' .. wikiLang
--end
imagesString = imagesString .. ']]'
-- pitäisi olla käytössä numval=1 fiwikissä, tuleeko turhia luokkia tällä?
--if usedImages[image] then
-- addMaintenanceCat('Infobox avec plusieurs images identiques')
--end
--usedImages[image] = true
end
local image = mw.html.create('div')
:addClass("images")
:addClass(wikidataimageclass)
: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) 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
-- käytetäänkö tätä jotain kautta?
-- korvaa navboxin joissain tapauksissa (uudempi)
function p.buildsuccession(params)
if not params.value then
return nil
end
--local style = params.style or {}
--style['text-align'] = style['text-align'] or 'center'
--style['color'] = style['color'] or '#000000'
--style['background-color'] = style['background-color'] or '#F9F9F9'
local rowI = mw.html.create('tr')
local styleI = {}
local colspan = '2'
styleI['padding'] = '1px'
local cellI = mw.html.create('td')
:attr({colspan = colspan})
:attr({align = 'center'})
:css(styleI)
local styleT = {
margin = '0',
['background-color'] = 'transparent',
color = 'inherit',
width = '100%'
}
local tabC = mw.html.create('table')
:attr({cellspacing = '0'})
:addClass('navigation-not-searchable')
:css(styleT)
local row = mw.html.create('tr')
local color = params.color
local style = {}
local arrowLeft = '[[Fichier:Arrleft.svg|13px|alt=Précédent|link=]]'
local arrowRight = '[[Fichier:Arrright.svg|13px|alt=Suivant|link=]]'
if color ~= 'default' then
style['background-color'] = color
end
local styleTrans = {}
local values = params.value
local before = values['before']
local center = values['center']
local after = values['after']
local widthCenter
local widthCell = '44%'
if center then
widthCenter = '28%'
widthCell = '29%'
end
local formattedbefore
if before then
formattedbefore = mw.html.create('td')
:attr({valign = 'middle'})
:attr({align = 'left'})
:attr({width = '5%'})
:css(style)
:wikitext(arrowLeft)
:done()
row:node(formattedbefore)
formattedbefore = mw.html.create('td')
:attr({width = '1%'})
:css(style)
:wikitext('')
:done()
row:node(formattedbefore)
formattedbefore = mw.html.create('td')
:attr({align = 'left'})
:attr({valign = 'middle'})
:attr({width = widthCell})
:css(style)
:wikitext(before)
:done()
row:node(formattedbefore)
else
formattedbefore = mw.html.create('td')
:attr({valign = 'middle'})
:attr({align = 'left'})
:attr({width = '5%'})
:css(styleTrans)
:wikitext('')
:done()
row:node(formattedbefore)
formattedbefore = mw.html.create('td')
:attr({width = '1%'})
:css(styleTrans)
:wikitext('')
:done()
row:node(formattedbefore)
formattedbefore = mw.html.create('td')
:attr({align = 'left'})
:attr({valign = 'middle'})
:attr({width = widthCell})
:css(styleTrans)
:wikitext('')
:done()
row:node(formattedbefore)
end
local formattedcenter
formattedcenter = mw.html.create('td')
:attr({width = '1%'})
:css(styleTrans)
:wikitext('')
:done()
row:node(formattedcenter)
if center then
formattedcenter = mw.html.create('td')
:attr({align = 'center'})
:attr({valign = 'middle'})
:attr({width = widthCenter})
:css(style)
:wikitext(center)
:done()
row:node(formattedcenter)
formattedcenter = mw.html.create('td')
:attr({width = '1%'})
:css(styleTrans)
:wikitext('')
:done()
row:node(formattedcenter)
end
local formattedafter
if after then
formattedafter = mw.html.create('td')
:attr({align = 'right'})
:attr({valign = 'middle'})
:attr({width = widthCell})
:css(style)
:wikitext(after)
:done()
row:node(formattedafter)
formattedbefore = mw.html.create('td')
:attr({width = '1%'})
:css(style)
:wikitext('')
:done()
row:node(formattedbefore)
formattedafter = mw.html.create('td')
:attr({align = 'right'})
:attr({valign = 'middle'})
:attr({width = '5%'})
:css(style)
:wikitext(arrowRight)
:done()
row:node(formattedafter)
else
formattedafter = mw.html.create('td')
:attr({align = 'right'})
:attr({valign = 'middle'})
:attr({width = widthCell})
:css(styleTrans)
:wikitext('')
:done()
row:node(formattedafter)
formattedbefore = mw.html.create('td')
:attr({width = '1%'})
:css(styleTrans)
:wikitext('')
:done()
row:node(formattedbefore)
formattedafter = mw.html.create('td')
:attr({align = 'right'})
:attr({valign = 'middle'})
:attr({width = '5%'})
:css(styleTrans)
:wikitext('')
:done()
row:node(formattedafter)
end
row:done()
tabC:node(row)
tabC:done()
cellI:node(tabC)
cellI:done()
rowI:node(cellI)
rowI:allDone()
return rowI
end
--p.buildSuccession = p.buildsuccession
-- väliotsikolle
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
elseif params.color and params.color ~= '' then
rowcolor = params.color
end
-- tätä ei enää ole fr-wikissä..
local style = {}
style['padding'] = '4px'
style['text-align'] = 'center'
style['background-color'] = rowcolor or 'var(--couleur-fond-boite-grise, #f9f9f9)'
style['color'] = 'var(--color-emphasized, #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['color'] = style['color'] or thirdcolor
style['margin'] = '0.4em 0px 0px 5px'
style['border-bottom'] = style['background-color'] or maincolor .. ' 1px solid'
--style['background-color'] = style['background-color'] or maincolor
--style['text-align'] = style['text-align'] or 'center' -- center is not really centered with this ?
-- -> somehow this is in a nested table so we are not aligned to true left side of infobox,
-- see if this is fixed in fr-wiki
local colspan ='2'
title = mw.html.create('caption')
:attr({colspan = colspan})
:css(style)
:wikitext(text)
:done()
end
if title then
tab:node(title)
end
for i, j in pairs (rows) do
tab:node(j)
end
if params.separator then
local separator = p.separator(params)
tab:node(separator)
end
tab:allDone()
return tab
end
--p.buildTable = p.buildtable
--------------------------------------------------------------------------------
-- Fonction créant une ligne d’en-tête à 2 colonnes (subheader2col)
--------------------------------------------------------------------------------
function p.buildSubheader2col(params)
local row = mw.html.create('tr')
local col1 = mw.html.create('th')
:attr('scope', 'col')
:wikitext(params.col1)
:done()
local col2 = mw.html.create('th')
:attr('scope', 'col')
:wikitext(params.col2)
:done()
row:node(col1)
row:node(col2)
row:done()
return row
end
function p.buildinvalidblock(args)
addMaintenanceCat(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)-- 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 290
if width > 290 then
addMaintenanceCat("Erreur d'Infobox/Image trop grande")
return 'image trop grande, la largeur doit être inférieure ou égale à 290px'
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 = wd.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, ids = params.ids }
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:Fr: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§ion=0' ) ) .. ' ' .. i18n['edit'] .. ']'
.. ' - [' .. tostring( mw.uri.fullUrl( page.name, 'action=edit§ion=0' ) ) .. ' ' .. i18n['edit code'] .. ']'
local itemlinkstr
if localdata.entity_id then
itemlinkstr = '[[d:' .. localdata.entity_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 showwikidatabacklinkstr="[[File:Wikidata-logo.svg|25px|".. i18n['show wikidata backlinks'] .. "|link=#]]"
local showwikidatabacklinkspan = mw.html.create('span')
:css({['text-align'] = "right", ['display'] = "none"})
:addClass('showlinkback')
:wikitext(showwikidatabacklinkstr)
:done()
local footer = mw.html.create('p')
:addClass(class)
:css(style)
:node(editlinkspan)
:node(doclinkspan)
:node(showwikidatabacklinkspan)
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,
--['navigator'] = p.buildnavigator, -- navbox nimetty uudelleen
['table'] = p.buildtable,
['row'] = p.buildrow,
['row1col'] = p.buildrow1col,
['succession'] = p.buildnavbox,
--['succession'] = p.buildsuccession, -- erona navboxista
['text'] = p.buildtext,
['title'] = p.buildtitle,
--['subheader2col'] = p.buildSubheader2col,
}
if type(block) ~= 'table' or (not block.type) or (not blocktypes[block.type]) then
return blocktypes['invalid'](block)
end
return blocktypes[block.type](block)
end
--p.buildBlock = p.buildblock
function p.build()
localdata = require( 'Module:Fr: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.entity_id then
local itemlink = mw.wikibase.sitelink(localdata.entity_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:Fr:Infobox/' .. localdata.modulename)
moduledata.name = localdata.modulename
-- defines main color
maincolor = localdata['couleur infobox'] or localdata['couleur boîte'] or moduledata.maincolor or maincolor
-- background for some sub-headings
secondcolor = moduledata.secondcolor or secondcolor
--thirdcolor = moduledata.thirdcolor or thirdcolor -- text, comes from theme now
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()
-- use templatestyles-extension to fetch sanitized css and combine it
local styleext = mw.getCurrentFrame():extensionTag('templatestyles', '', {src = 'Module:Infobox v3/styles.css'})
-- wrap whole thing inside infobox-div so mobileview parser will detect it as infobox
-- fix mobileview parser?
local infobox_wrapper = mw.html.create('div')
infobox_wrapper :addClass("infobox")
:css("border", "none")
:css("margin", "0")
:css("margin-left", "0.5em")
:css("padding", "0")
:node(infobox)
:done()
-- note: we want templatestyles-extension here so we can use another style sheet
-- via css sanitizer and deduplication
return styleext .. tostring(infobox_wrapper) .. externaltext, maintenance
end
return p