Vai al contenuto

Modulo:Header template

Da Wikisource.

La documentazione per questo modulo può essere creata in Modulo:Header template/man

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
            titre = titre .. '&#32;— <i>' .. args.recueil .. '</i>'
        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
        line = line .. ' ('
        if args.volume and args.volume ~= '' and args.type ~= 'collection' and args.type ~= 'journal' then
            line = line .. args.volume .. ',&nbsp;'
        end
        line = line .. pagination( from, to ) .. ')'
    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 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
    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 '] = titre
        else
            coins['rft.genre'] = 'article'
            coins['rft.atitle'] = titre
            if args.titre then
                coins['rft.jtitle'] = args.titre
                text = text .. outputMicroformatRow( 'periodical', args.titre )
            end
        end
    else
        uriCoins = uriCoins .. 'book'
        if estSommaire then
            coins['rft.btitle '] = titre
        else
            coins['rft.atitle '] = 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'] = 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'] = 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( 'image', 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
    text=text..'<span class="Z3988" title="' .. uriCoins .. '&' .. mw.uri.buildQueryString( coins ) .. '">&nbsp;</span></div>'
    text=text..'<div class="testi">'
    return text
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' 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