« Module:Fix » : différence entre les versions
Contenu supprimé Contenu ajouté
je viens de me faire avoir sur la signification de l'astérisque dans le 1er test ; note à propos : je viens de survoler les cas utilisant ":" (indentation), ils ont l'air quasiment tout le temps erronés |
copie de Module:Fix/Bac à sable, changement de l'affichage des refnec suite à Discussion_Projet:Scribunto#Infobulle dans la balise des modèles de révision - Module:Fix. |
||
Ligne 1 : | Ligne 1 : | ||
local p = {} |
local p = {} |
||
function p.necessiteCadre(frame) |
|||
local source = frame.args[1] |
|||
if source:match('\n[ \t]*\n') -- ligne vide (donc plusieurs paragraphes) |
|||
or source:match('\n[*#:]') -- liste à puces, liste numérotée, indentation |
|||
then |
|||
return '1' |
|||
else |
|||
return '' |
|||
end |
|||
end |
|||
function p.affichageBloc( args ) |
function p.affichageBloc( args ) |
||
Ligne 35 : | Ligne 22 : | ||
:cssText( 'position:absolute; top:-0.6em; left:1em; padding:0 0.5em; font-size:80%; line-height:1em;') |
:cssText( 'position:absolute; top:-0.6em; left:1em; padding:0 0.5em; font-size:80%; line-height:1em;') |
||
:css{ background = background } |
:css{ background = background } |
||
:wikitext( args. |
:wikitext( args.message2 ) |
||
:allDone() |
:allDone() |
||
Ligne 41 : | Ligne 28 : | ||
end |
end |
||
function p.affichageInline( args ) |
function p.affichageInline( args , ajouterinfobulle ) |
||
local html = mw.html.create( '' ) |
local html = mw.html.create( '' ) |
||
if args[1] and args[1] ~= '' then |
if args[1] and mw.text.trim(args[1]) ~= '' then |
||
html:tag( 'span' ) |
html:tag( 'span' ) |
||
:addClass( 'need_ref' ) |
:addClass( 'need_ref' ) |
||
:cssText( 'cursor:help;' ) |
:cssText( 'cursor:help;' ) |
||
:attr{ title = args.titre } |
:attr{ title = args.titre } |
||
:wikitext( args[1] ) |
:wikitext( mw.text.trim(args[1]) ) |
||
:done() |
:done() |
||
ajouterinfobulle=false--Facultatif, on pourrait accepter l'infobulle sur l'exposant quel que soit le cas. |
|||
end |
end |
||
if ajouterinfobulle then |
|||
html:tag( 'sup' ) |
|||
:addClass( 'need_ref_tag' ) |
:addClass( 'need_ref_tag' ) |
||
:cssText ( 'padding-left:2px;' ) |
:cssText ( 'padding-left:2px;' ) |
||
: |
:attr{ title = args.titre2 } |
||
:wikitext( args.message2 ) |
|||
:allDone() |
:allDone() |
||
else |
|||
html:tag( 'sup' ) |
|||
:addClass( 'need_ref_tag' ) |
|||
:cssText ( 'padding-left:2px;' ) |
|||
:wikitext( args.message2 ) |
|||
:allDone() |
|||
end |
|||
return tostring( html ) |
return tostring( html ) |
||
end |
end |
||
function p.generateMessage( args, nommodele, modeinfobulle)-- Le dernier paramètre sert de booléen pour forcer une infobulle dans le lien interne. |
|||
local modeinfobulle = modeinfobulle or false |
|||
local messageloc='' |
|||
local infobulle_mise=false |
|||
if args.message and args.message ~= '' then |
|||
if args.message_lien and args.message_lien ~= '' then |
|||
if args.message_lien=='non' then |
|||
messageloc= "[" .. args.message .. "]" |
|||
if not args.message:find("%[%[") then |
|||
args.titre2=args.titre |
|||
end |
|||
else |
|||
if modeinfobulle==true then-- On force l'infobulle à l'intérieur. Il y aurait peut-être plus smple, avec un seul message et l'ajout d'une classe désactivant les infobulles sur les liens internes |
|||
--messageloc= "[[[" .. args.message_lien .. "|" .. '<span title="' .. args.titre2 ..'">' .. args.message .. "</span>" .. "]]]"--CHOIX |
|||
messageloc= "[[" .. args.message_lien .. "|" .. '<span title="' .. args.titre2 ..'">[' .. args.message .. "]</span>" .. "]]" |
|||
infobulle_mise=true |
|||
else |
|||
--messageloc= "[[[" .. args.message_lien .. "|" .. args.message .. "]]]"--CHOIX |
|||
messageloc= "[[" .. args.message_lien .. "|[" .. args.message .. "]]]" |
|||
infobulle_mise=true--Facultatif mais on peut bien considérer inutile d'ajouter une autre infobulle autour de ce contenu. Cela est encore plus vrai si lien interne créé à la ligne précédente est sur l'intégralité du message. |
|||
end |
|||
end |
|||
else |
|||
if modeinfobulle==true then |
|||
--messageloc= "[[[" .. args.message .. "|" .. '<span title="' .. args.titre2 ..'">' .. args.message .. "</span>" .. "]]]" .. tostring(table.concat(args))--CHOIX |
|||
messageloc= "[[" .. args.message .. "|" .. '<span title="' .. args.titre2 ..'">[' .. args.message .. "]</span>" .. "]]" .. tostring(table.concat(args)) |
|||
infobulle_mise=true |
|||
else |
|||
--messageloc= "[[[" .. args.message .. "]]]"--CHOIX |
|||
messageloc= "[[" .. args.message .. "|[" .. args.message .. "]]]" |
|||
infobulle_mise=true--Facultatif, idem plus haut |
|||
end |
|||
end |
|||
-- trois lignes qui suivent : test temporaire à activer lors de la transition d'affichage pour les appels qui introduisent déjà un lien via le paramètre message |
|||
if (args.message:find("%[") or args.message:find("%]")) and (args.message_lien or '')~='non' then |
|||
messageloc= args.message |
|||
end |
|||
else |
|||
messageloc= '<span class="error">argument « message » manquant dans le modèle ' .. nommodele .. '.</span>' |
|||
args.titre2="Erreur dans l'appel du modèle Fix" |
|||
end |
|||
return messageloc, infobulle_mise |
|||
end |
|||
function p.affichageFix( frame ) |
function p.affichageFix( frame ) |
||
local args = frame.getParent and frame:getParent().args or frame |
local args = frame.getParent and frame:getParent().args or frame |
||
local nommodele = frame.getParent and frame:getParent():getTitle() or frame:getTitle() |
|||
local messageDate = '' |
|||
if args[1] and args[1] ~= '' then |
|||
local messageAide = ' ; v' |
|||
local ponctuation="." |
|||
if args.date and args.date ~= '' then |
|||
messageDate = ' (demandé le ' .. args.date .. ')' |
|||
else |
|||
local infobulle_texte= mw.text.trim((args.infobulle or ''):gsub( '%b<>', '' )) |
|||
if infobulle_texte ~= '' then |
|||
if infobulle_texte:match( '[!?…]$' ) then |
|||
messageAide = ' V' |
|||
ponctuation="" |
|||
end |
|||
else |
|||
messageAide = 'V' |
|||
ponctuation="" |
|||
end |
end |
||
end |
|||
messageAide = messageAide .. 'oir l\'aide.' |
|||
args.titre = ( args.infobulle or '' ):gsub( '%.$', '' ) .. messageDate .. '.' |
|||
args.titre = mw.text.trim(( args.infobulle or '' ):gsub( '[,.;:]$', '' )) .. messageDate .. ponctuation |
|||
args.titre2 = mw.text.trim(( args.infobulle or '' ):gsub( '[,.;:]$', '' )) .. messageDate .. messageAide |
|||
if args[1] and mw.text.trim(args[1]) ~= '' then |
|||
args.message2, infobulle_mise =p.generateMessage(args, nommodele) |
|||
if args[1]:match('\n[ \t]*\n') |
if args[1]:match('\n[ \t]*\n') |
||
or args[1]:match('\n[*#:]') |
or args[1]:match('\n[*#:]') |
||
Ligne 80 : | Ligne 136 : | ||
return p.affichageBloc( args ) |
return p.affichageBloc( args ) |
||
end |
end |
||
else |
|||
args.message2, infobulle_mise =p.generateMessage(args, nommodele, true) |
|||
end |
end |
||
return p.affichageInline( args ) |
return p.affichageInline( args, not infobulle_mise ) |
||
end |
end |
||
Version du 18 avril 2021 à 00:17
[voir] [modifier] [historique] [purger]
Module utilisé par le métamodèle {{Fix}}, et indirectement par le modèle {{Référence nécessaire}} et dérivés.
La documentation de ce module est générée par le modèle {{Documentation module}}.
Elle est incluse depuis sa sous-page de documentation. Veuillez placer les catégories sur cette page-là.
Les éditeurs peuvent travailler dans le bac à sable (modifier).
Voir les statistiques d'appel depuis le wikicode sur l'outil wstat et les appels depuis d'autres modules.
local p = {}
function p.affichageBloc( args )
local background = args.background or ''
if background == '' then
background = 'white'
end
local html = mw.html.create( '' )
:wikitext( '\n' )
:tag( 'div' )
:cssText( 'position:relative; margin-top:0.8em;')
:tag( 'div' )
:addClass( 'need_ref' )
:cssText( 'cursor:help; overflow:hidden; padding-bottom:0;' )
:css{ background = background }
:attr{ title = args.titre }
:wikitext( args[1], '\n' )
:done()
:tag( 'div' )
:addClass( 'need_ref_tag' )
:cssText( 'position:absolute; top:-0.6em; left:1em; padding:0 0.5em; font-size:80%; line-height:1em;')
:css{ background = background }
:wikitext( args.message2 )
:allDone()
return tostring( html )
end
function p.affichageInline( args , ajouterinfobulle )
local html = mw.html.create( '' )
if args[1] and mw.text.trim(args[1]) ~= '' then
html:tag( 'span' )
:addClass( 'need_ref' )
:cssText( 'cursor:help;' )
:attr{ title = args.titre }
:wikitext( mw.text.trim(args[1]) )
:done()
ajouterinfobulle=false--Facultatif, on pourrait accepter l'infobulle sur l'exposant quel que soit le cas.
end
if ajouterinfobulle then
html:tag( 'sup' )
:addClass( 'need_ref_tag' )
:cssText ( 'padding-left:2px;' )
:attr{ title = args.titre2 }
:wikitext( args.message2 )
:allDone()
else
html:tag( 'sup' )
:addClass( 'need_ref_tag' )
:cssText ( 'padding-left:2px;' )
:wikitext( args.message2 )
:allDone()
end
return tostring( html )
end
function p.generateMessage( args, nommodele, modeinfobulle)-- Le dernier paramètre sert de booléen pour forcer une infobulle dans le lien interne.
local modeinfobulle = modeinfobulle or false
local messageloc=''
local infobulle_mise=false
if args.message and args.message ~= '' then
if args.message_lien and args.message_lien ~= '' then
if args.message_lien=='non' then
messageloc= "[" .. args.message .. "]"
if not args.message:find("%[%[") then
args.titre2=args.titre
end
else
if modeinfobulle==true then-- On force l'infobulle à l'intérieur. Il y aurait peut-être plus smple, avec un seul message et l'ajout d'une classe désactivant les infobulles sur les liens internes
--messageloc= "[[[" .. args.message_lien .. "|" .. '<span title="' .. args.titre2 ..'">' .. args.message .. "</span>" .. "]]]"--CHOIX
messageloc= "[[" .. args.message_lien .. "|" .. '<span title="' .. args.titre2 ..'">[' .. args.message .. "]</span>" .. "]]"
infobulle_mise=true
else
--messageloc= "[[[" .. args.message_lien .. "|" .. args.message .. "]]]"--CHOIX
messageloc= "[[" .. args.message_lien .. "|[" .. args.message .. "]]]"
infobulle_mise=true--Facultatif mais on peut bien considérer inutile d'ajouter une autre infobulle autour de ce contenu. Cela est encore plus vrai si lien interne créé à la ligne précédente est sur l'intégralité du message.
end
end
else
if modeinfobulle==true then
--messageloc= "[[[" .. args.message .. "|" .. '<span title="' .. args.titre2 ..'">' .. args.message .. "</span>" .. "]]]" .. tostring(table.concat(args))--CHOIX
messageloc= "[[" .. args.message .. "|" .. '<span title="' .. args.titre2 ..'">[' .. args.message .. "]</span>" .. "]]" .. tostring(table.concat(args))
infobulle_mise=true
else
--messageloc= "[[[" .. args.message .. "]]]"--CHOIX
messageloc= "[[" .. args.message .. "|[" .. args.message .. "]]]"
infobulle_mise=true--Facultatif, idem plus haut
end
end
-- trois lignes qui suivent : test temporaire à activer lors de la transition d'affichage pour les appels qui introduisent déjà un lien via le paramètre message
if (args.message:find("%[") or args.message:find("%]")) and (args.message_lien or '')~='non' then
messageloc= args.message
end
else
messageloc= '<span class="error">argument « message » manquant dans le modèle ' .. nommodele .. '.</span>'
args.titre2="Erreur dans l'appel du modèle Fix"
end
return messageloc, infobulle_mise
end
function p.affichageFix( frame )
local args = frame.getParent and frame:getParent().args or frame
local nommodele = frame.getParent and frame:getParent():getTitle() or frame:getTitle()
local messageDate = ''
local messageAide = ' ; v'
local ponctuation="."
if args.date and args.date ~= '' then
messageDate = ' (demandé le ' .. args.date .. ')'
else
local infobulle_texte= mw.text.trim((args.infobulle or ''):gsub( '%b<>', '' ))
if infobulle_texte ~= '' then
if infobulle_texte:match( '[!?…]$' ) then
messageAide = ' V'
ponctuation=""
end
else
messageAide = 'V'
ponctuation=""
end
end
messageAide = messageAide .. 'oir l\'aide.'
args.titre = mw.text.trim(( args.infobulle or '' ):gsub( '[,.;:]$', '' )) .. messageDate .. ponctuation
args.titre2 = mw.text.trim(( args.infobulle or '' ):gsub( '[,.;:]$', '' )) .. messageDate .. messageAide
if args[1] and mw.text.trim(args[1]) ~= '' then
args.message2, infobulle_mise =p.generateMessage(args, nommodele)
if args[1]:match('\n[ \t]*\n')
or args[1]:match('\n[*#:]')
or args.bloc and args.bloc ~= ''
then
return p.affichageBloc( args )
end
else
args.message2, infobulle_mise =p.generateMessage(args, nommodele, true)
end
return p.affichageInline( args, not infobulle_mise )
end
return p