Utilisateur:Zebulon84/Archive module
Apparence
function Z.testparam (frame)
local frameargs = type (frame.args)
local getParent = type (frame.getParent)
local frameparent, parentargs, arg1 = '', '', ''
if getParent == 'function' then
frameparent = type (frame:getParent())
end
if frameparent == 'table' then
parentargs = type (frame:getParent().args)
arg1 = type (frame:getParent().args[1])
end
return 'frameargs : ' .. frameargs
.. '\n\ngetParent : ' .. getParent
.. '\n\nframeparent : ' .. frameparent
.. '\n\nparentargs : ' .. parentargs
.. '\n\narg1 : ' .. arg1
end
function z.nombre(frame)
local s = frame.args[1]
if s then
local n = mw.language:parseFormattedNumber (s)
s = mw.language:formatNum (n)
else
s = ''
end
return s
end
function z.inTable (val, tab)
for i, j in pairs(tab) do
if val == j then return true end
end
end
function z.trim (texte)
return texte and string.match (texte, '^%s*(.-)%s*$')
end
function z.testparam(frame)
local a, b = string.match (frame.args[1], '^(%d*)/?(%a*)$')
return 'a = ' .. type(a) .. ', ' .. (a or '')
.. '\nb = ' .. type(b) .. ', ' .. (b or '')
end
-- --------------------------------------------------------
-- code principal de Modèle:Tableau Coupe 16 (3 sets) --
-- programmé avec des div plutôt qu'une grande table --
-- --------------------------------------------------------
function z.tableau_16_div (frame)
local pargs = frame:getParent().args -- paramètre du modèle
local nSet = 3
local sport = frame.args.sport
local wikiTable = { } -- chaque élément de cette table reprèsentera le wikiTexte d'une ligne du tableau
local wikiText = '' -- pour saisie de texte temporaire.
local txt = '' -- variable texte locale
local match -- reçois les la table avec les deux lignes de chaque match
local namesMatch1, namesMatch2 -- nil si aucun nom de joueur pour le match (1er tour uniquement)
local argsPerMatch = 2 * (nSet + 1) -- nombre de de paramètre non nommé par match, 8 pour 3 sets, 12 pour 5 sets
local lineEnd = 'border-style:solid;border-color:#999999"| ' -- fin du texte (toujours identique) des cellules générant une ligne de liason
local nSetFinal -- nombre de set de la finale
local nSetFinal2 -- nombre de set de la petite finale
-- Sachant que pour chaque match il y a 2 joueurs, et 6 scores de set (8 paramètres)
-- 15 match avec la finale => 120 paramètres normalement.
if pargs[125] then -- s'il y a un paramètre 125, il y a une petite finale
if pargs[129] then -- la finale est en 5 sets
if pargs[133] then -- la petite finale aussi
nSetFinal = 5
nSetFinal2 = 5
else
nSetFinal = 5
nSetFinal2 = 3
end
else
nSetFinal = 3
nSetFinal2 = 3
end
else
if pargs[121] then -- s'il y a un paramètre 121, la finale est en 5 set
nSetFinal = 5
else
nSetFinal = 3
end
end
wikiText = '<div style=" height:25px;">\n</div>' -- acceillera la ligne de titre
wikiText = wikiText
.. '<div style="position:relative; font-size:11px; text-align:center;">' -- bloc finale
.. '<div style="display:table-cell;">'
for i = 0, 1 do
-- bloc 1/2 finale ----------------
wikiText = wikiText
.. '<div style="position:relative;">'
.. '<div style="display:table-cell;">'
for j = 0, 1 do
-- bloc 1/4 de finale ----------------
wikiText = wikiText
.. '<div style="position:relative;">'
.. '<div style="display:table-cell;">'
-- bloc 1/8 de finale ----------------
.. '<div style="position:relative; padding:10px 25px 10px 0">'
-- ligne titre
local txt = ''
if i == 1 or j == 1 then
txt = 'display:none; ' -- le titre n'est affiché qu'une fois, sauf pout les navigateur sans css.
end
wikiText = wikiText .. '<div style="' .. txt .. 'position:absolute; margin-right:25px; top:-25px;">'
.. '<div style="display:table-cell; background:#CFCFCF; width:252px; height:23px; vertical-align:middle;">'
.. '<strong>1<sup>er</sup> tour</strong>'
.. '</div>'
.. '</div>'
-- matchs 1
local nMatch = 2 * j + 4 * i -- nombre de match avant celui-ci dans la syntaxe du modèle
local nArg = 1 + nMatch * argsPerMatch -- numéro de du premier argument non nommé lié à ce match
wikiText = wikiText .. matchTable (
pargs, nSet, nArg,
'DH' .. (1 + 2 * nMatch),
'DH' .. (2 * (nMatch + 1)),
sport,
{
hide = (pargs [nArg] == '') and (pargs [nArg + nSet + 1] == ''),
margin = '0 0 15px 0',
line = '<div style="position:absolute; top:48%; bottom:-10px; right:-15px; left:100%; border-style:solid; border-width:2px 2px 0 0; border-color:#999999;"></div>'
}
)
-- matchs 2
nMatch = nMatch + 1
nArg = 1 + nMatch * argsPerMatch
wikiText = wikiText .. matchTable (
pargs, nSet, nArg,
'DH' .. (1 + 2 * nMatch),
'DH' .. (2 * (nMatch + 1)),
sport,
{
hide = (pargs [nArg] == '') and (pargs [nArg + nSet + 1] == ''),
line = '<div style="position:absolute; top:-10px; bottom:48%; right:-15px; left:100%; border-style:solid; border-width:0 2px 2px 0; border-color:#999999;"></div>'
}
)
-- lignes raccordement centre
wikiText = wikiText .. '<div style="position:absolute; right:0; top:-1px; height:50%; width:10px; border-bottom:solid 2px #999999;">'
.. '</div>'
-- fin de bloc 1/8 de finale ----------------
.. '</div>'
-- 1/4 de finale ----------------
.. '</div>'
.. '<div style="display:table-cell; vertical-align:middle;">'
-- ligne titre
txt = ''
if i == 1 or j == 1 then
txt = 'display:none; '
end
wikiText = wikiText .. '<div style="' .. txt .. 'position:absolute; margin-right:25px; top:-25px;">'
.. '<div style="display:table-cell; background:#CFCFCF; width:252px; height:23px; vertical-align:middle;">'
.. '<strong>1/4 de finale</strong>'
.. '</div>'
.. '</div>'
-- match
nMatch = j + 2 * i
wikiText = wikiText .. matchTable (
pargs, nSet,
1 + (8 + nMatch) * argsPerMatch,
'DQ' .. (1 + 2 * nMatch),
'DQ' .. (2 * (nMatch + 1)),
sport,
{ margin = '0 25px 0 0' }
)
-- ligne raccordement
wikiText = wikiText .. '<div style="position:absolute; width:23px; height:50%; right:0; '
if j == 0 then
wikiText = wikiText .. 'bottom:-1px; border-style:solid; border-width:2px 2px 0 0;'
else
wikiText = wikiText .. 'top:-1px; border-style:solid; border-width:0 2px 2px 0;'
end
wikiText = wikiText .. 'border-color:#999999;"></div>'
-- fin de bloc 1/4 de finale ----------------
wikiText = wikiText
.. '</div>'
.. '</div>'
end
-- 1/2 finale ----------------
wikiText = wikiText
.. '</div>'
.. '<div style="display:table-cell; vertical-align:middle;">'
-- ligne titre
txt = ''
if i == 1 then
txt = 'display:none; '
end
wikiText = wikiText
.. '<div style="' .. txt .. 'margin:0 25px 0 -120px; position:absolute; top:0;">'
.. '<div style="display:table-cell; background:#CFCFCF; width:253px; height:23px; vertical-align:middle;">'
.. '<strong>1/2 finale</strong>'
.. '</div>'
.. '</div>'
-- match
wikiText = wikiText .. matchTable (
pargs, nSet,
1 + (8 + 4 + i) * argsPerMatch,
'DD' .. (1 + 2 * i),
'DD' .. (2 + 2 * i),
sport,
{ margin = '0 25px 0 -120px' }
)
-- ligne raccordement
wikiText = wikiText .. '<div style="position:absolute; width:23px; height:50%; right:0; '
if i == 0 then
wikiText = wikiText .. 'bottom:-1px; border-style:solid; border-width:2px 2px 0 0;'
else
wikiText = wikiText .. 'top:-1px; border-style:solid; border-width:0 2px 2px 0;'
end
wikiText = wikiText .. 'border-color:#999999;"></div>'
-- fin de bloc 1/2 de finale ----------------
wikiText = wikiText
.. '</div>'
.. '</div>'
end
-- Finale ----------------
wikiText = wikiText
.. '</div>'
.. '<div style="display:table-cell; vertical-align:middle;">'
-- ligne titre
wikiText = wikiText
.. '<div style="margin-left:-140px; position:absolute; top:-25px;">'
.. '<div style="display:table-cell; background:#CFCFCF; height:23px; width:253px; vertical-align:middle;">'
.. '<strong>Finale</strong>'
.. '</div>'
.. '</div>'
-- match
wikiText = wikiText .. matchTable (
pargs, nSet,
1 + (8 + 4 + 2) * argsPerMatch,
'DF1',
'DF2',
sport,
{ margin = '0 0 0 -140px' }
)
-- fin bloc finale ----------------
wikiText = wikiText
.. '</div>'
.. '</div>'
return wikiText
end
-- donne l'heure au moment ou ce code est éxécuter (précision : 1 seconde)
function p.time ( frame )
return 'heure : ' .. os.date( '!%T' ) .. ' (UTC)'
end
function p.langueData()
local langue = require 'Module:Langue/Data'
for k, v in pairs(langue) do
if v.code then
if k:lower() ~= v.code:lower() and k:lower() ~= v.nom:lower() then
if v.autre then
table.insert( v.autre, k )
else
v.autre = { k }
end
end
end
end
local data = {}
for k, v in pairs( langue ) do
if k:lower() == (v.code and v.code:lower()) then
data[k] = v
end
end
return data
end
function p.compareLangueData()
local data = require 'Module:Langue/Data'
local bas = require 'Module:Langue/Data/Bac à sable'
local difference = { missing= {}, code = {}, nom = {} }
for k, v in pairs(data) do
if not bas[ k ] then
table.insert( difference.missing, k )
elseif not v.invalide then
if bas[ k ].code ~= v.code then
table.insert( difference.code, k .. " : " .. v.code .. " → " .. bas[ k ].code )
end
if bas[ k ].nom ~= v.nom then
table.insert( difference.nom, k .. " : " .. v.nom .. " → " .. bas[ k ].nom )
end
end
end
return difference
end
local trim = require( 'Module:Outils' ).trim
function p.templatestyles( pictogramme )
pictogramme = trim( pictogramme )
if not pictogramme then
return ''
end
pictogramme = trim( pictogramme
:gsub( '^entete ', '' )
:gsub( ' entete ', '' )
:gsub( ' entete$', '' )
:gsub( 'defaut', '' )
)
if pictogramme then
if pictogramme:match( '%s' ) then
return '[[Catégorie:Infobox avec plusieurs class]]'
else
return mw.getCurrentFrame():extensionTag(
'templatestyles',
'',
{ src = 'Infobox/Pictogramme/' .. mw.text.trim( pictogramme ) .. '.css' }
)
end
end
return ''
end
function p.couleurs( background, color )
local couleur = require( 'Module:Dièse couleur web' ).couleur
background = trim( background ) or '#E1E1E1'
color = trim( color ) or 'black'
return 'background-color:' .. couleur( background ) .. ';'
.. 'color:' .. couleur( color ) .. ';'
end
function p.V2( frame )
local args = frame.getParent and frame:getParent().args or frame
local colspan = Outils.trim( args[5] ) or '2'
local texte = Outils.trim( args[1] ) or mw.title.getCurrentTitle().text
local classes = Outils.trim( args[3] ) or 'defaut'
return 'colspan="' .. colspan .. '" '
.. 'class="entete ' .. classes .. '" '
.. 'style="' .. p.couleurs( args[2], args[4] ) .. '" '
.. ' | '
.. texte
.. p.templatestyles( args[3] )
end
local badgesList = {
Q6540291 = 'portail de qualité',
Q6540326 = 'thème de qualité',
Q17437796 = 'article de qualité',
Q17437798 = 'bon article',
Q17506997 = 'liste de qualité',
Q17507019 = 'Le saviez-vous',
Q17559452 = 'recommended article',
Q17580674 = 'featured portal',
Q17580678 = 'A-Class articles',
Q17580679 = 'B-Class articles',
Q17580680 = 'C-Class articles',
Q17580682 = 'Top-importance articles',
}
local badgesCategory = {
Q17437796 = 'Article de qualité',
Q17437798 = 'Bon article',
Q17506997 = 'Article de qualité' -- 'liste de qualité',
}
local linkCategorySuffix = {
default = ' dans une autre langue',
}
function p.badgesCategories( frame )
local sitelinks = ( mw.wikibase.getEntity() or {} ).sitelinks
if not sitelinks then
return ''
end
local wikitext = {}
local categoryNs = mw.site.namespaces[14].name
for siteid, linkTable in pairs( sitelinks ) do
if siteid:sub( -4 ) == 'wiki' and siteid ~= 'frwiki' then
for i, badgeId in ipairs( linkTable.badges ) do
local main = badgesCategory[ badgeId ]
if main then
local suffix = linkCategorySuffix[ siteid ] or linkCategorySuffix.default
local category = string.format('[[%s:%s]]', categoryNs, main .. suffix )
table.insert( wikitext, category )
end
end
end
end
return table.concat( wikitext )
end