మాడ్యూల్:Header template

వికీసోర్స్ నుండి
Voir Aide:Transclusion pour l’utilisation de la commande <pages index=… />.
  • Modèle utilisé par la balise <pages/> pour générer les boîtes titres
  • Les paramètres acceptés par ce modèle proviennent de la page d’index.
  • Les paramètres peuvent aussi être passés à la commande "pages".
  • Exemple :
 <pages index=foo header=1 auteur="[[Balzac]]" />
Détails techniques

Ce modèle est implémenté en Lua via le module Header Template. Il utilise les paramètres suivants définis par l’extension ProofreadPage :

paramètre description
from la valeur మూస:Vert définie par l’utilisateur, 1 par défaut
displayed_from le numéro de page à afficher pour la première page (par défaut celui défini dans la page Livre:)
to la valeur మూస:Vert définie par l’utilisateur, par défaut la dernière page
displayed_to le numéro de page à afficher pour la dernière page (par défaut celui défini dans la page Livre:)
current le nom du lien pointant vers la page courante dans le sommaire de la page d’index du Livre
prev le nom du lien pointant vers la page précédant la page courante dans le sommaire de la page d’index du Livre
next le nom du lien pointant vers la page suivant la page courante dans le sommaire de la page d’index du Livre
value la valeur de l’attribut మూస:Vert de la balise మూస:Vert, ou మూస:Vert si ni మూస:Vert ni మూస:Vert ne sont précisés

Les autres paramètres sont les noms des champs apparaissant dans le formulaire de l’index du Livre. Leur valeur est celle qui apparaît dans le formulaire, sauf si l’utilisateur l'a redéfinie dans la balise మూస:Vert, auquel cas, la valeur de la balise a priorité sur celle de l’index.

Pour le paramètre మూస:Vert, la valeur apparaissant dans le menu déroulant du formulaire de la page d’index est convertie en un nom à usage interne suivant le tableau de correspondance suivant :

valeur interne valeur du menu déroulant
book Livre
collection Recueil
journal Journal ou revue
phdthesis Thèse, rapport
dictionary Dictionnaire, encyclopédie, ouvrage de référence

C’est la valeur interne qui est utilisée par le modèle. De même, si l’utilisateur souhaite redéfinir la valeur du champ type à l’intérieur de la balise మూస:Vert, il doit utiliser la valeur interne.


function cleanCoinsParameter( param )
	param = string.gsub( param, "%[%[.*|(.*)%]%]", "%1" )
	return string.gsub( param, "%[%[(.*)%]%]", "%1" )
end

function headerTemplate( frame )
    local parentFrame = frame:getParent()
    local args = parentFrame.args
    local page = mw.title.getCurrentTitle()
    local headerType = args.value
    if args.header_type and args.header_type ~= '' then
        headerType = args.header_type
    end

    headerType = mw.ustring.lower( headerType ) --Permet d'écrire le type en majuscule ou en minuscule
    local estSommaire = (headerType == 'sommaire' or headerType == 'toc')

	--Custom page numbers
	local from = ''
	if args.displayed_from and args.displayed_from ~= '' then
		from = args.displayed_from
	elseif args.from then
		from = args.from
	end

	local to = ''
	if args.displayed_to and args.displayed_to ~= '' then
		to = args.displayed_to
	elseif args.to then
		to = args.to
	end

    --Début du header
    local text = '' --TODO
    classement( parentFrame, page, args )
    if args.header_type == 'empty' then
        if args.sommaire then
            return text .. '<div id="ws-summary" style="margin-top:1em">\n' .. args.sommaire .. '</div>'
        else
            return text
        end
    end

    text = text .. '<div id="headertemplate" class="ws-noexport"><div class="'
    if args.type == 'journal' then
        text = text .. 'headertemplate-journal'
    else
        text = text .. 'headertemplate'
    end
    text = text .. '">'

    --Auteur
    if args.auteur and args.auteur ~= '' then
        text = text .. '<div class="headertemplate-author">' .. args.auteur .. '</div>'
    end

    --Titre
    local titre = page.baseText
    if args.type == 'collection' then
        if args.current then
            titre = args.current
        end
        if args.recueil and args.recueil ~= '' then
            -- Commenté pour tester avec uniquement le nom du recueil, le titre lui est déjà
            -- dans le navigateur et fréquemment en début de la page.
            -- titre = titre .. '&#32;— <i>' .. args.recueil .. '</i>'
             titre = '<i>' .. args.recueil .. '</i>'
        end
        if args.publication and args.publication ~= '' then
            titre = titre .. ' <span style="font-size:90%;">(' .. args.publication .. ')</span>'
        end
    elseif args.type == 'journal' then
        if estSommaire then
            titre = args.titre
        elseif args.current then
            titre = args.current
        end
    else
        if args.titre then
            titre = args.titre
        end
        if args.publication and args.publication ~= '' then
            titre = titre .. ' <span style="font-size:90%;">(' .. args.publication .. ')</span>'
        end
    end
    if estSommaire and args['sous_titre'] and args['sous_titre'] ~= '' then
       titre = titre .. ' <br/><small>' .. args['sous_titre'] .. '</small>'
    end
    text = text .. '<div class="headertemplate-title">' .. titre .. '</div>'

    --References
    text = text .. '<div class="headertemplate-reference">'
    if args.traducteur and args.traducteur ~= '' then
        text = text .. 'Traduction par ' .. args.traducteur .. '.<br />'
    end
    if estSommaire and args.illustrateur and args.illustrateur ~= '' then
        text = text .. 'Illustrations par ' .. args.illustrateur .. '.<br />'
    end

    if estSommaire and args.volume and args.volume ~= '' then
          text = text .. args.volume .. '<br />'
    end

    local infos = {} --Liste des données à afficher séparés par une virgule
    if args.type == 'collection' then
        table.insert( infos, '<i>' .. args.titre .. '</i>' )
        if args.editeur_scientifique and args.editeur_scientifique ~= '' then
            table.insert( infos, 'Texte établi par ' .. args.editeur_scientifique )
        end
        if args.editeur and args.editeur ~= '' then
            table.insert( infos, args.editeur )
        end
        if args.annee and args.annee ~= '' then
            table.insert( infos, args.annee )
        end
        if not estSommaire then
            if args.volume and args.volume ~= '' then
                table.insert( infos, args.volume )
            end
        end
    elseif args.type == 'journal' then
        if estSommaire then
            table.insert( infos, args.annee )
        else
            table.insert( infos, '<i>' .. args.titre .. '</i>' )
            if args.volume and args.volume ~= '' then
                table.insert( infos, args.volume )
            end
            if args.annee and args.annee ~= '' then
                table.insert( infos, args.annee )
            end
        end
    else
        if args.editeur_scientifique and args.editeur_scientifique ~= '' then
            table.insert( infos, 'Texte établi par ' .. args.editeur_scientifique )
        end
        if args.editeur and args.editeur ~= '' then
            table.insert( infos, args.editeur )
        end
        if args.annee and args.annee ~= '' then
            table.insert( infos, args.annee )
        end
    end
    local line = ''
    if infos ~= {} then
        line = table.concat( infos, ',&nbsp;' )
    end

    --Parenthèse
    if not estSommaire and from ~= '' then
        local temp = ''
        if args.volume and args.volume ~= '' and args.type ~= 'collection' and args.type ~= 'journal' then
            temp = args.volume .. ',&nbsp;'
        end
        if from ~= to or from ~= '-' then
            temp = temp .. pagination( from, to )
        end

        if temp ~= '' then
            line = line .. ' (' .. temp .. ')'
        end
    end

    if line ~= '' then
        line = line .. '.'
    end
    text = text .. line .. '</div></div></div>' --Fin du header

    text = text .. '<div id="subheader" class="ws-noexport" style="margin-bottom:1.5em">'
    if estSommaire then
        local texteEntier = mw.title.new( page.prefixedText .. '/Texte entier' )
        if texteEntier and texteEntier.exists then
            text = text .. '<div style="text-align:center;">[[' .. texteEntier.fullText .. '|Texte sur une seule page]]</div>'
        end
    end

    if (not estSommaire or (args.header_type and args.header_type =='toc')) and ((args.prev and args.prev ~= '') or (args.next and args.next ~= '')) then
        local maxwidth = 50
        if args.current and args.current ~= '' then
            maxwidth = 33
        end
        text = text .. '<div class="footertemplate ws-noexport">'
        text = text .. '<div style="width: 100%; padding-left:0px; padding-right:0px; background-color:transparent;" class="ws-noexport">'
        if args.prev and args.prev ~= '' then
            text = text .. '<div style="text-align:left; float:left; max-width:' .. maxwidth .. '%;"><span id="headerprevious"><span style="color:#808080">&#x25C4;&nbsp;&nbsp;</span>' .. args.prev .. '</span></div>'
        end
        if args.next and args.next~= '' then
            text = text .. '<div style="text-align:right; float:right; max-width:' .. maxwidth .. '%;"><span id="headernext">' .. args.next .. '<span style="color:#808080">&nbsp;&nbsp;&#x25BA;</span></span></div>'
        end
        text = text .. '<div style="text-align:center; margin-left: 25%; margin-right: 25%;">'
        if type ~= 'collection' and args.current and args.current ~= '' then
            text = text .. args.current
        end
        text = text .. '</div></div><div style="clear:both;"></div></div>'
    end
    text = text .. '</div>' --LF Ici nécessaire pour l’épigraphe

    -- Inclusion de l'épigraphe et du sommaire
    if headerType == 'toc' then
        if args.epigraphe and args.epigraphe ~= '' then
            text = text .. args.epigraphe .. '\n'
        end
        text = text .. '<div id="ws-summary" style="margin-top:1em">\n' .. args.sommaire .. '</div>'
    elseif headerType == 'sommaire' then
        text = text .. '<div id="ws-summary">'
    end

    -- Métadonnées, see http://ocoins.info/ for coins.
    local coins = {}
    local uriCoins = 'ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3A'
    coins['rft.genre'] = 'unknown'
    coins['rfr_id'] = tostring( page:fullUrl( nil, "canonical" ) )
    text = text .. '<div id="ws-data" class="ws-noexport" style="display:none; speak:none;">'
    if args.type then
        text = text .. outputMicroformatRow( 'type', args.type )
    end
    if args.type and args.type == 'journal' then
        uriCoins = uriCoins .. 'journal'
        if estSommaire then
            coins['rft.genre'] = 'publication'
            coins['rft.jtitle'] = cleanCoinsParameter( titre )
        else
            coins['rft.genre'] = 'article'
            coins['rft.atitle'] = cleanCoinsParameter( titre )
            if args.titre then
                coins['rft.jtitle'] = cleanCoinsParameter( args.titre )
                text = text .. outputMicroformatRow( 'periodical', cleanCoinsParameter( args.titre ) )
            end
        end
    else
        uriCoins = uriCoins .. 'book'
        if estSommaire then
            coins['rft.btitle'] = cleanCoinsParameter( titre )
        else
            coins['rft.atitle'] = cleanCoinsParameter( titre )
        end
        if args.type and args.type == 'book' then
            if estSommaire then
                coins['rft.genre'] = 'book'
            else
                coins['rft.genre'] = 'bookitem'
            end
        end
    end
    text = text .. outputMicroformatRow( 'title', titre )
    if args.auteur and args.auteur ~= '' then
        text = text .. outputMicroformatRow( 'author', args.auteur )
        coins['rft.au'] = cleanCoinsParameter( args.auteur )
    end
    if args.traducteur and args.traducteur ~= '' then
        text = text .. outputMicroformatRow( 'translator', args.traducteur )
    end
    if args.illustrateur and args.illustrateur ~= '' then
        text = text .. outputMicroformatRow( 'illustrator', args.illustrateur )
    end
    if args.school and args.school ~= '' then
        text = text .. outputMicroformatRow( 'school', args.school )
    end
    if args.editeur and args.editeur ~= '' then
        text = text .. outputMicroformatRow( 'publisher', args.editeur )
        coins['rft.pub'] = cleanCoinsParameter( args.editeur )
    end
    if args.annee and args.annee ~= '' then
        text = text .. outputMicroformatRow( 'year', args.annee )
        coins['rft.date'] = args.annee
    end
    if args.lieu and args.lieu ~= '' then
        text = text .. outputMicroformatRow( 'place', args.lieu )
        coins['rft.place'] = args.lieu
    end
    if args.avancement and args.avancement ~= '' then
        text = text .. outputMicroformatRow( 'progress', args.avancement )
    end
    if args.volume and args.volume ~= '' then
        text = text .. outputMicroformatRow( 'volume', args.volume )
    end
    if args.current and args.current ~= '' then
        text = text .. outputMicroformatRow( 'chapter', args.current )
    end
    if args.index then
        text = text .. outputMicroformatRow( 'scan', args.index )
        if args.image and mw.ustring.match(args.image, '^%d+$') ~= nil then
            text = text .. outputMicroformatRow( 'cover', args.index .. '/' .. args.image )
        end
    end
    if from ~= '' and to ~= '' then
        if from == to then
            text = text .. outputMicroformatRow( 'pages', from )
        else
            text = text .. outputMicroformatRow( 'pages', from .. '-' .. to )
        end
        coins['rft.spage'] = from
        coins['rft.epage'] = to
    end
    return text .. '<span class="Z3988" title="' .. uriCoins .. '&' .. mw.uri.buildQueryString( coins ) .. '">&nbsp;</span></div>'
end

function classement( frame, page, args )
    local classement = require 'Module:Classement'
    local key = ''
    if args.type and args.type == 'journal' then
        key = classement.getSortKey( {args= {page.text}} )
    elseif args.type and (args.type == 'dictionary' or args.type == 'collection') then
        key = classement.getSortKey( {args= {page.subpageText}} )
    elseif not page.isSubpage then
        key = classement.getSortKey( {args= {page.text}} )
    end
    if key ~= '' then
        --Evite le parse des paramètres passés à la page.
        local child = frame:newChild{ title = page.text, args = {} }
        child:preprocess( '{{DEFAULTSORT:' .. key .. '}}\n' )
    end
end

function pagination( from, to )
    if from ~= '' and to ~= '' then
        if from == to then
            return '<abbr title="page">p.</abbr>&nbsp;' .. from
        else
            return '<abbr title="pages">pp.</abbr>&nbsp;' .. from .. '-' .. to
        end
    end
end

function outputMicroformatRow( name, value )
    return '<span class="ws-' .. name .. '">' .. value .. '</span> '
end


local p = {}
 
function p.headerTemplate( frame )
    return headerTemplate( frame )
end
 
return p