« Module:Drapeau » : différence entre les versions
m (1 version) |
m (1 version) |
||
(Une version intermédiaire par le même utilisateur non affichée) | |||
Ligne 4 : | Ligne 4 : | ||
]] | ]] | ||
math_mod = | drapeau = {}; | ||
gdata = | --math_mod = mw.loadData( "Module:Math" ); | ||
-- Chargement du de la base de donnée des langues avec gestion d'erreur. | |||
local gdata | |||
local success, resultat = pcall (mw.loadData, "Module:Drapeau/Data" ) | |||
if success then | |||
gdata = resultat | |||
else | |||
-- Base de donnée à minima en cas de bug sur le Module:Langue/Data | |||
gdata={} | |||
gdata.data={}; | |||
gdata.idByName={}; | |||
gdata.idByCIO={}; | |||
gdata.data[142]={qid="Q142", flag="Flag_of_France.svg", label="France", sitelink="$label", cio="FRA", genre="fs"} | |||
gdata.idByName['france']=142; | |||
gdata.idByCIO['FRA']=142; | |||
end | |||
local gflag | |||
local success, resultat = pcall (mw.loadData, "Module:Drapeau/Image" ) | |||
if success then | |||
gflag = resultat | |||
else | |||
-- Base de donnée à minima en cas de bug sur le Module:Langue/Data | |||
gflag={} | |||
gflag.flag={}; | |||
end | |||
local gdomaine | |||
local success, resultat = pcall (mw.loadData, "Module:Drapeau/Domaine" ) | |||
if success then | |||
gdomaine = resultat | |||
else | |||
-- Base de donnée à minima en cas de bug sur le Module:Langue/Data | |||
gdomaine={} | |||
gdomaine.domainelist={ | |||
defaut = {regexp="[[$sitelink|$label]]" , desc="article sur le pays"} | |||
,drapeau = {regexp="drapeau", desc=""} | |||
} | |||
gdomaine.genre={ms={},msa={},msi={},msia={},fs={},fsa={},fsi={},fsia={},mp={},fp={}} | |||
gdomaine.jo={} | |||
end | |||
globalFrame = nil | globalFrame = nil | ||
function _getFlag(image,aaaammjj,imagesecours) | |||
local indexdate=(aaaammjj..mw.ustring.rep( 0, 8 )):sub (1, 8) | |||
, | if (indexdate ~= '00000000' and image~=nil) then | ||
for k,v in pairs( image) do | |||
if v["debut"] <= indexdate and indexdate <= v["fin"] then | |||
return v | |||
end | |||
end | |||
end | |||
if(image~=nil) then | |||
d= image[1]; | |||
elseif(imagesecours["flag"]~=nil) then | |||
local f=imagesecours["flag"] | |||
d= {civilflag=f,stateflag=f,warflag=f,civilensign=f,stateensign=f,warensign=f}; | |||
else | |||
local f="Flag_of_None.svg" | |||
d= {civilflag=f,stateflag=f,warflag=f,civilensign=f,stateensign=f,warensign=f}; | |||
end | |||
return d; | |||
end | |||
function _getCompetition(c,aaaa) | |||
local rep=""; | |||
if(c=="CM" or c=="coupedumonde") then | |||
rep="à la Coupe du monde" | |||
elseif(c=="CE" or c=="euro") then | |||
rep="au championnat d'Europe" | |||
elseif(c=="ChM") then | |||
rep="au championnat du monde" | |||
elseif(c=="CAN" or c=="coupedesconfederations") then | |||
rep="à la Coupe des Confédérations" | |||
elseif(c=="en" ) then | |||
rep="en" | |||
elseif(c=="jo" ) then | |||
rep="aux Jeux olympiques" | |||
elseif(c=="jp" ) then | |||
rep="aux Jeux paralympiques" | |||
end | |||
--edition | |||
if(aaaa ~= nil and aaaa ~= "") then | |||
if(c=="jo" or c=="jp" ) then | |||
local o=gdomaine.jo["_"..aaaa]; | |||
if(o ~= nil) then | |||
rep=rep.." "..o | |||
end | |||
else | |||
rep=rep.." "..aaaa | |||
end | |||
end | |||
return rep | |||
end | |||
--[[ | --[[ | ||
pays | pays | ||
Ligne 78 : | Ligne 113 : | ||
]] | ]] | ||
function | function printIcon(data,image,domaine,size,day) | ||
local border=''; | local border=''; | ||
local alt=''; | local alt=''; | ||
if | if data["flagborder"] ~= "no" then | ||
border='border|' | border='border|' | ||
end | end | ||
alt=string.gsub(domainelist["drapeau"]["regexp"], "%$(%w+)", genre[ | local datagenre=data["genre"] or "ms" | ||
alt=string.gsub(alt, "%$(%w+)", | alt=string.gsub(gdomaine.domainelist["drapeau"]["regexp"], "%$(%w+)",gdomaine.genre[datagenre]) | ||
alt=string.gsub(alt, "%$(%w+)", | alt=string.gsub(alt, "%$(%w+)", data) | ||
alt=string.gsub(alt, "%$(%w+)", data) --dernière passe pour $name | |||
local filescr="$civilflag" ; | |||
if(gdomaine.domainelist[domaine]~=nil and gdomaine.domainelist[domaine]["flag"]~=nil) then | |||
--drapeau adequat | |||
filescr=gdomaine.domainelist[domaine]["flag"] | |||
end | |||
pastimage=_getFlag(image,day,data) | |||
filescr=string.gsub(filescr, "%$(%w+)", pastimage) | |||
filescr=string.gsub(filescr, "%$(%w+)", pastimage) | |||
return '<span class="flagicon">' .. | return '<span class="flagicon">' .. | ||
'[[Fichier:' .. | '[[Fichier:' .. filescr .. '|' .. size ..'px|' .. border .. alt ..']]' .. | ||
'</span>'; | '</span>'; | ||
end | end | ||
function | function printData(text,domaine,extra) | ||
local target=''; | local target=''; | ||
if text[" | local datagenre=text["genre"] or "ms" | ||
target=string.gsub(domainelist[domaine]["regexp"], "%$(%w+)", genre[ | if text["label"] ~= nil and gdomaine.domainelist[domaine] ~= nil then | ||
target=string.gsub(gdomaine.domainelist[domaine]["regexp"], "%$(%w+)", gdomaine.genre[datagenre]) | |||
target=string.gsub(target, "%$(%w+)", text) | target=string.gsub(target, "%$(%w+)", text) | ||
target=string.gsub(target, "%$(%w+)", text) --dernière passe pour $name | target=string.gsub(target, "%$(%w+)", text) --dernière passe pour $name | ||
target=string.gsub(target, "%$(%w+)", extra) | |||
target=string.gsub(target, "%$(%w+)", "") --une toute dernière pour supprimer les non-attribué | |||
end | end | ||
return target; | return target; | ||
Ligne 125 : | Ligne 175 : | ||
function _cletri(tmparg) | function _cletri(tmparg) | ||
local pays=tmparg; | |||
--2>--remove case | --2>--remove case | ||
tmparg=mw.ustring.lower(tmparg); | tmparg=mw.ustring.lower(tmparg); | ||
Ligne 146 : | Ligne 197 : | ||
tmparg=mw.ustring.gsub(tmparg, "^du ", ""); | tmparg=mw.ustring.gsub(tmparg, "^du ", ""); | ||
return '<span class="datasortkey" data-sort-value="'..tmparg..'" style="display:none;"> | return '<span class="datasortkey" data-sort-value="'..tmparg..'" style="display:none;">'..pays..'</span>'; | ||
end | end | ||
Ligne 167 : | Ligne 218 : | ||
local extra={} | |||
if(args[1]=='libelle') then | if(args[1]=='libelle') then | ||
res="{|class='wikitable' \n!code!!descriptif!!exemple "..mw.wikibase.sitelink(gdata.data[142]["qid"] ).."!!exemple "..mw.wikibase.sitelink(gdata.data[31]["qid"] ).."!!exemple "..mw.wikibase.sitelink(gdata.data[30]["qid"] ).."\n|-\n" | res="{|class='wikitable sortable' \n!code!!descriptif!!exemple "..mw.wikibase.sitelink(gdata.data[142]["qid"] ).."!!exemple "..mw.wikibase.sitelink(gdata.data[31]["qid"] ).."!!exemple "..mw.wikibase.sitelink(gdata.data[30]["qid"] ).."\n|-\n" | ||
for k,v in pairs( domainelist ) do | for k,v in pairs( gdomaine.domainelist ) do | ||
res= res .. "|<code>" .. k .. "<\code> ||".. | res= res .. "|<code>" .. k .. "<\code> ||".. v["desc"] .. "||" ..printData(gdata.data[142],k,extra) .. "||" ..printData(gdata.data[31],k,extra) .. "||" ..printData(gdata.data[30],k,extra) .. "\n|-\n" | ||
end | end | ||
res=res .. "|}" | res=res .. "|}" | ||
end | end | ||
if(args[1]=='pays') then | if(args[1]=='pays') then | ||
res="{|class='wikitable sortable' \n!Nom!!Code CIO!!usage classique!!Drapeau!!Équipe sportive (de football)\n|-\n" | |||
for k,v in pairs( gdata.data ) do | for k,v in pairs( gdata.data ) do | ||
res= res .. " | local cio=v["cio"] or "" | ||
res= res .. "|"..v["label"].."||<code>" .. cio .. "<\code> ||" .._cletri(v["label"])..printIcon(v,nil,"defaut",'20x15',"")..printData(v,"defaut",extra) .. "|| [[" ..printData(v,"drapeau",extra) .. "]] ||" ..printData(v,"football",extra) .. "\n|-\n" | |||
end | end | ||
res=res .. "|}" | |||
end | end | ||
return res; | return res; | ||
Ligne 206 : | Ligne 261 : | ||
--1>--remove whitespace | --1>--remove whitespace | ||
args[i]=args[i]:match( '^%s*(.-)%s*$' ); | args[i]=args[i]:match( '^%s*(.-)%s*$' ); | ||
end | end | ||
end | end | ||
local key=_latinise(args[1]); | |||
--par défaut | --par défaut | ||
local taille = args["taille"] or '20x15' | |||
if (args["domaine"] == nil) then args["domaine"] = 'defaut' end | if (args["domaine"] == nil) then args["domaine"] = 'defaut' else args["domaine"] = _latinise(args["domaine"]) end | ||
local align = args["align"] or 'left' | |||
if (args[" | local lien = args["lien"] or 'oui' | ||
local annee = args[2] or args["année"] or '' | |||
local extra={} | |||
if (args["compétition"] ~= nil) then | |||
extra["competition"] = " ".._getCompetition(_latinise(args["compétition"]),args["édition"]) | |||
end | |||
local q=0; | local q=0; | ||
local data; | local data; | ||
if(args["CIO"]~= nil) then | if(#key==3) then | ||
q=gdata.idByCIO[mw.ustring.upper(key)] | |||
elseif(args["CIO"]~= nil) then | |||
q=gdata.idByCIO[args["CIO"]] | q=gdata.idByCIO[args["CIO"]] | ||
else | else | ||
q=gdata.idByName[ | q=gdata.idByName[key] | ||
end | end | ||
local data=gdata.data[q]; | local data=gdata.data[q]; | ||
local image=gflag.flag[q]; | |||
local res=''; | local res=''; | ||
if(args["t"] == '1') then | local reserror=''; | ||
res=res .. _cletri(data[" | --le pays est inconnu!! | ||
end | if(data == nil) then | ||
if( | data={qid="", flag="Flag_of_None.svg", label=args[1], sitelink="$label", cio="" | ||
res=res .. | , genre="ms" , namelong="$label", gentileMS="$label",gentileFS="$label",gentileMP="$label",gentileFP="$label"} | ||
reserror = reserror .. '<strong class="error">Aucun pays paramètré</strong>' | |||
end | |||
--clé automatique if(args["t"] == '1') then | |||
res=res .. _cletri(data["label"]); | |||
--end | |||
if(align == 'left') then | |||
res=res .. printIcon(data,image,args["domaine"],taille,annee)..' '; | |||
end | end | ||
if(args["cible"] ~= nil) then | if(args["cible"] ~= nil) then | ||
res=res .. args["cible"] .. ' <span style="font-size:90%;" class="nowrap">('; | res=res .. args["cible"] .. ' <span style="font-size:90%;" class="nowrap">('; | ||
end | end | ||
if( | if(lien == 'oui' and data["label"] ~= '') then | ||
res=res .. | res=res ..printData(data,args["domaine"],extra); | ||
end | end | ||
if(args["cible"] ~= nil) then | if(args["cible"] ~= nil) then | ||
res=res .. ')</span>'; | res=res .. ')</span>'; | ||
end | end | ||
if( | if(align == 'right') then | ||
res=res .. ' ' .. | res=res .. ' ' .. printIcon(data,image,args["domaine"],taille,annee); | ||
end | end | ||
return res; | return res .. reserror; | ||
end | end |
Version du 14 janvier 2014 à 00:01
La documentation pour ce module peut être créée à Module:Drapeau/doc
Erreur de script : Erreur Lua : impossible de créer le processus : proc_open n’est pas disponible. Vérifiez la directive de configuration PHP « disable_functions ».
--[[ This module is intended to replace the functionality of {{drapeau2}} and related templates. It provides several methods, including ]] drapeau = {}; --math_mod = mw.loadData( "Module:Math" ); -- Chargement du de la base de donnée des langues avec gestion d'erreur. local gdata local success, resultat = pcall (mw.loadData, "Module:Drapeau/Data" ) if success then gdata = resultat else -- Base de donnée à minima en cas de bug sur le Module:Langue/Data gdata={} gdata.data={}; gdata.idByName={}; gdata.idByCIO={}; gdata.data[142]={qid="Q142", flag="Flag_of_France.svg", label="France", sitelink="$label", cio="FRA", genre="fs"} gdata.idByName['france']=142; gdata.idByCIO['FRA']=142; end local gflag local success, resultat = pcall (mw.loadData, "Module:Drapeau/Image" ) if success then gflag = resultat else -- Base de donnée à minima en cas de bug sur le Module:Langue/Data gflag={} gflag.flag={}; end local gdomaine local success, resultat = pcall (mw.loadData, "Module:Drapeau/Domaine" ) if success then gdomaine = resultat else -- Base de donnée à minima en cas de bug sur le Module:Langue/Data gdomaine={} gdomaine.domainelist={ defaut = {regexp="[[$sitelink|$label]]" , desc="article sur le pays"} ,drapeau = {regexp="drapeau", desc=""} } gdomaine.genre={ms={},msa={},msi={},msia={},fs={},fsa={},fsi={},fsia={},mp={},fp={}} gdomaine.jo={} end globalFrame = nil function _getFlag(image,aaaammjj,imagesecours) local indexdate=(aaaammjj..mw.ustring.rep( 0, 8 )):sub (1, 8) if (indexdate ~= '00000000' and image~=nil) then for k,v in pairs( image) do if v["debut"] <= indexdate and indexdate <= v["fin"] then return v end end end if(image~=nil) then d= image[1]; elseif(imagesecours["flag"]~=nil) then local f=imagesecours["flag"] d= {civilflag=f,stateflag=f,warflag=f,civilensign=f,stateensign=f,warensign=f}; else local f="Flag_of_None.svg" d= {civilflag=f,stateflag=f,warflag=f,civilensign=f,stateensign=f,warensign=f}; end return d; end function _getCompetition(c,aaaa) local rep=""; if(c=="CM" or c=="coupedumonde") then rep="à la Coupe du monde" elseif(c=="CE" or c=="euro") then rep="au championnat d'Europe" elseif(c=="ChM") then rep="au championnat du monde" elseif(c=="CAN" or c=="coupedesconfederations") then rep="à la Coupe des Confédérations" elseif(c=="en" ) then rep="en" elseif(c=="jo" ) then rep="aux Jeux olympiques" elseif(c=="jp" ) then rep="aux Jeux paralympiques" end --edition if(aaaa ~= nil and aaaa ~= "") then if(c=="jo" or c=="jp" ) then local o=gdomaine.jo["_"..aaaa]; if(o ~= nil) then rep=rep.." "..o end else rep=rep.." "..aaaa end end return rep end --[[ pays Affiche le pays accompagné de son drapeau {{drapeau2}} Usage: {{ Invoke:Drapeau | pays | France }} ]] function printIcon(data,image,domaine,size,day) local border=''; local alt=''; if data["flagborder"] ~= "no" then border='border|' end local datagenre=data["genre"] or "ms" alt=string.gsub(gdomaine.domainelist["drapeau"]["regexp"], "%$(%w+)",gdomaine.genre[datagenre]) alt=string.gsub(alt, "%$(%w+)", data) alt=string.gsub(alt, "%$(%w+)", data) --dernière passe pour $name local filescr="$civilflag" ; if(gdomaine.domainelist[domaine]~=nil and gdomaine.domainelist[domaine]["flag"]~=nil) then --drapeau adequat filescr=gdomaine.domainelist[domaine]["flag"] end pastimage=_getFlag(image,day,data) filescr=string.gsub(filescr, "%$(%w+)", pastimage) filescr=string.gsub(filescr, "%$(%w+)", pastimage) return '<span class="flagicon">' .. '[[Fichier:' .. filescr .. '|' .. size ..'px|' .. border .. alt ..']]' .. '</span>'; end function printData(text,domaine,extra) local target=''; local datagenre=text["genre"] or "ms" if text["label"] ~= nil and gdomaine.domainelist[domaine] ~= nil then target=string.gsub(gdomaine.domainelist[domaine]["regexp"], "%$(%w+)", gdomaine.genre[datagenre]) target=string.gsub(target, "%$(%w+)", text) target=string.gsub(target, "%$(%w+)", text) --dernière passe pour $name target=string.gsub(target, "%$(%w+)", extra) target=string.gsub(target, "%$(%w+)", "") --une toute dernière pour supprimer les non-attribué end return target; end function _latinise(tmparg) --2>--remove case tmparg=mw.ustring.lower(tmparg); --2>--remove acccent tmparg=mw.ustring.gsub(tmparg, "[àáâãäå]", "a"); tmparg=mw.ustring.gsub(tmparg, "[æ]", "ae"); tmparg=mw.ustring.gsub(tmparg, "[ç]", "c"); tmparg=mw.ustring.gsub(tmparg, "[èéêë]", "e"); tmparg=mw.ustring.gsub(tmparg, "[ìíîï]", "i"); tmparg=mw.ustring.gsub(tmparg, "[ñ]", "n"); tmparg=mw.ustring.gsub(tmparg, "[òóôõö]", "o"); tmparg=mw.ustring.gsub(tmparg, "[œ]", "oe"); tmparg=mw.ustring.gsub(tmparg, "[ùúûü]", "u"); tmparg=mw.ustring.gsub(tmparg, "[ýÿ]", "y"); --3>--remove ponct tmparg=mw.ustring.gsub(tmparg, "[' -_]", ""); return tmparg; end function _cletri(tmparg) local pays=tmparg; --2>--remove case tmparg=mw.ustring.lower(tmparg); --2>--remove acccent tmparg=mw.ustring.gsub(tmparg, "[àáâãäå]", "a"); tmparg=mw.ustring.gsub(tmparg, "[æ]", "ae"); tmparg=mw.ustring.gsub(tmparg, "[ç]", "c"); tmparg=mw.ustring.gsub(tmparg, "[èéêë]", "e"); tmparg=mw.ustring.gsub(tmparg, "[ìíîï]", "i"); tmparg=mw.ustring.gsub(tmparg, "[ñ]", "n"); tmparg=mw.ustring.gsub(tmparg, "[òóôõö]", "o"); tmparg=mw.ustring.gsub(tmparg, "[œ]", "oe"); tmparg=mw.ustring.gsub(tmparg, "[ùúûü]", "u"); tmparg=mw.ustring.gsub(tmparg, "[ýÿ]", "y"); --3>--remove ponct tmparg=mw.ustring.gsub(tmparg, "['-_]", " "); --4>--remove forme longue tmparg=mw.ustring.gsub(tmparg, "^republique ", ""); tmparg=mw.ustring.gsub(tmparg, "^iles ", ""); tmparg=mw.ustring.gsub(tmparg, "^de ", ""); tmparg=mw.ustring.gsub(tmparg, "^du ", ""); return '<span class="datasortkey" data-sort-value="'..tmparg..'" style="display:none;">'..pays..'</span>'; end function drapeau.list(frame) globalFrame = frame local args = frame.args local res=""; if args[1] == nil then local pFrame = frame:getParent(); args = pFrame.args; for k,v in pairs( frame.args ) do args[k] = v; end end if args[2] == nil then args[2]=142 --France par défaut end local extra={} if(args[1]=='libelle') then res="{|class='wikitable sortable' \n!code!!descriptif!!exemple "..mw.wikibase.sitelink(gdata.data[142]["qid"] ).."!!exemple "..mw.wikibase.sitelink(gdata.data[31]["qid"] ).."!!exemple "..mw.wikibase.sitelink(gdata.data[30]["qid"] ).."\n|-\n" for k,v in pairs( gdomaine.domainelist ) do res= res .. "|<code>" .. k .. "<\code> ||".. v["desc"] .. "||" ..printData(gdata.data[142],k,extra) .. "||" ..printData(gdata.data[31],k,extra) .. "||" ..printData(gdata.data[30],k,extra) .. "\n|-\n" end res=res .. "|}" end if(args[1]=='pays') then res="{|class='wikitable sortable' \n!Nom!!Code CIO!!usage classique!!Drapeau!!Équipe sportive (de football)\n|-\n" for k,v in pairs( gdata.data ) do local cio=v["cio"] or "" res= res .. "|"..v["label"].."||<code>" .. cio .. "<\code> ||" .._cletri(v["label"])..printIcon(v,nil,"defaut",'20x15',"")..printData(v,"defaut",extra) .. "|| [[" ..printData(v,"drapeau",extra) .. "]] ||" ..printData(v,"football",extra) .. "\n|-\n" end res=res .. "|}" end return res; end function drapeau.List(frame) return drapeau.list(frame) end function drapeau.pays(frame) globalFrame = frame local args = frame.args local tmparg; if args[1] == nil then local pFrame = frame:getParent(); args = pFrame.args; for k,v in pairs( frame.args ) do args[k] = v; end end for i=1,10 do if args[i] == nil then args[i] = "" else --1>--remove whitespace args[i]=args[i]:match( '^%s*(.-)%s*$' ); end end local key=_latinise(args[1]); --par défaut local taille = args["taille"] or '20x15' if (args["domaine"] == nil) then args["domaine"] = 'defaut' else args["domaine"] = _latinise(args["domaine"]) end local align = args["align"] or 'left' local lien = args["lien"] or 'oui' local annee = args[2] or args["année"] or '' local extra={} if (args["compétition"] ~= nil) then extra["competition"] = " ".._getCompetition(_latinise(args["compétition"]),args["édition"]) end local q=0; local data; if(#key==3) then q=gdata.idByCIO[mw.ustring.upper(key)] elseif(args["CIO"]~= nil) then q=gdata.idByCIO[args["CIO"]] else q=gdata.idByName[key] end local data=gdata.data[q]; local image=gflag.flag[q]; local res=''; local reserror=''; --le pays est inconnu!! if(data == nil) then data={qid="", flag="Flag_of_None.svg", label=args[1], sitelink="$label", cio="" , genre="ms" , namelong="$label", gentileMS="$label",gentileFS="$label",gentileMP="$label",gentileFP="$label"} reserror = reserror .. '<strong class="error">Aucun pays paramètré</strong>' end --clé automatique if(args["t"] == '1') then res=res .. _cletri(data["label"]); --end if(align == 'left') then res=res .. printIcon(data,image,args["domaine"],taille,annee)..' '; end if(args["cible"] ~= nil) then res=res .. args["cible"] .. ' <span style="font-size:90%;" class="nowrap">('; end if(lien == 'oui' and data["label"] ~= '') then res=res ..printData(data,args["domaine"],extra); end if(args["cible"] ~= nil) then res=res .. ')</span>'; end if(align == 'right') then res=res .. ' ' .. printIcon(data,image,args["domaine"],taille,annee); end return res .. reserror; end function drapeau.Pays(frame) return drapeau.pays(frame) end return drapeau