Info Istruzioni per l'uso
Questo è un modulo scritto in Lua. Le istruzioni che seguono sono contenute nella sottopagina Modulo:Interprogetto/man (modifica · cronologia)
Sandbox: Modulo:Interprogetto/sandbox (modifica · cronologia) · Sottopagine: lista · Test: Modulo:Interprogetto/test (modifica · cronologia · esegui)

Modulo Lua per svolgere le funzioni di {{Interprogetto}}.

Ha una sottopagina di configurazione: Modulo:Interprogetto/Configurazione.

Errore Lua in package.lua alla linea 80: module 'Module:HtmlBuilder' not found.


--Modulo per implementare le funzionalità di template:Interprogetto
local p = {} -- per l'esportazione delle funzioni del modulo

local HtmlBuilder = require('Module:HtmlBuilder') -- richiesto per la costruzione del markup html

local args -- variabile che contiene gli argomenti passati al template
local root -- radice del markup html
local log= '' -- per debug

--Tabella di corrispondenza tra valore e file da richiamare
local prefix_links ={
    wiksource =      {1, 's:', 'Wikisource', false },
    s =              {2, 's:', 'Wikisource', false },
    testo =          {3, 's:', 'Wikisource', false },
    oldwikisource =  {4, 'oldwikisource:', 'Wikisource', false },
    wikiquote =      {5, 'q:', 'Wikiquote', false },
    q =              {6, 'q:', 'Wikiquote', false },
    wikibooks =      {7, 'wikibooks:', 'Wikibooks', false },
    b =              {8, 'b:', 'Wikibooks', false },
    ricetta =        {9, 'b:Libro di cucina/Ricette/', 'Ricetta<br />(Wikibooks)', false },
    wiktionary =     {10, 'wiktionary:', 'Wikizionario', false},
    wikt =           {11, 'wikt:', 'Wikizionario', false},
    v =              {12, 'v:', 'Wikiversità', false},
    wikinews =       {13, 'wikinews:', 'Wikinotizie', false},
    commons =        {14, 'commons:', 'Commons', true},
    meta =           {15, 'meta:', 'Meta-Wiki', true},
    m =              {16, 'm:', 'Meta-Wiki', true},
    wikispecies =    {17, 'wikispecies:', 'Wikispecies', true},
    incubator =      {18, 'incubator:', 'Incubator', true},
    n =              {19, 'n:', 'Wikinotizie', false},
    voy =            {20, 'voy:', 'Wikivoyage', false}
}
--TODO collegamenti che usano Interprogetto/CollegamentoUseLang

local function sort_by_priority(t1, t2)
    if t1[1] < t2[1] then
        return true
    end
end

function return_link(priority, prefix, label, lang)
    if lang then
		return '* [[' .. prefix .. v .. '|' .. label .. ']]'
    end
end

local function RenderLeftBar()
    -- Crea la barra di sinistra con i link interprogetto
    if args.notizia then return end
    -- costruisce le righe per la barra di sinistra
    local left_rows = { }
    for k,v in pairs(args) do
        if prefix_links[k] then
            table.insert(left_rows, return_link(unpack(prefix_links[k])))
        end
    end
    table.sort(left_rows, sort_by_priority)
    local leftbar = HtmlBuilder.create()
    for k, row in pairs(left_rows) do
        leftbar.wikitext(row[2])
        leftbar.newline()
    end
    --  Apertura del tag div id="interProject" (vedi [[Mediawiki:Monobook.js]] o [[Mediawiki:Vector.js]])
    root
        .tag('div')
        .attr('id', 'interProject')
        .cssText('display: none; clear: both; border-top: 2px dotted #AAAAAA; margin-top: 2em')
            .tag('div')
            .attr('title', 'Collegamenti verso gli altri progetti Wikimedia')
            .node(leftbar)

end

local function RenderLinkInText()
	if args.nolink then return end
end

local function _interprogetto()
    --radice del markup ritornato
    root = HtmlBuilder.create()
    RenderLeftBar()
    RenderLinkInText()
    return  tostring(root)
end

function p.interprogetto(frame)
    local origArgs
    -- Se chiamata mediante  #invoke, usa gli argomenti passati al template invocante.
    -- Altrimenti a scopo di test assume che gli argomenti siano passati direttamente
    if frame == mw.getCurrentFrame() then
        origArgs = frame:getParent().args
    else
        origArgs = frame
    end

    -- Carico i parametri
    args = {}
    current_page = mw.title.getCurrentTitle().text
    for k, v in pairs(origArgs) do
        -- controlla se è un parametro posizionale e in questo caso la memorizza come
        -- chiave con valore pari al nome della pagina corrente
        local kn = tonumber(k)
        if kn then
            args[v] = current_page
        else
            args[k]=v
        end
    end
    return _interprogetto()
end

return p