Modulo:Notizia per Wikivoyage

Da Wikinotizie, le notizie a contenuto aperto

Utilizzato da {{Notizia per Wikivoyage}}.


--[=[

Gestisce
- categorizzazione
- e visualizzazione dell'icona del titolo
per le notizie elencate in [[Wikinotizie:Notizie turistiche/Wikivoyage]]
e conseguentemente in [[voy:Wikinotizie:Notizie turistiche/Wikivoyage]]

** test **
= p.getWikicode(
    mw.getCurrentFrame()
    :newChild{ args = {
        anno   = '2013',
        mese   = '10',
        giorno = nil
    } }
)

]=]

local p = {}

-- durata di visualizzazione dell'articolo
local showMonths = 6

local dateErrorMsg, timelyNewsMsg, expiredNewsMsg

local function setMessages( frame )

    dateErrorMsg = [=[
<div class="error">
ATTENZIONE: Parametri del template ]=]
    .. frame:expandTemplate{
        title = 'tl',
        args = { 'Notizia per Wikivoyage' }
    }
    .. [=[ errati o mancanti.
</div>
[[Categoria:Template "Notizia per Wikivoyage" con errori]]
]=]

	timelyNewsMsg = frame:extensionTag(
		'indicator',
		'[[File:Wikivoyage-Logo-v3-en.svg|44px|Questa notizia contiene informazioni turistiche|link=Wikinotizie:Notizie turistiche]]',
		{ name = 'wikivoyage' }
	) .. '\n[[Categoria:Notizie per Wikivoyage]]'

    expiredNewsMsg = '[[Categoria:Notizie per Wikivoyage scadute]]'

end

local function dateError( year, month, day )

    if
    not year
    or not month
    or year < 2013
    or year > tonumber( os.date( '%Y' ) )
    or month < 1
    or month > 12
    or day < 1
    or day > 31
    then return true
    end

end

function p.getWikicode( frame )

    local year  = tonumber( frame.args.anno )
    local month = tonumber( frame.args.mese )
    local day   = tonumber( frame.args.giorno ) or 15

    setMessages( frame )

    if dateError( year, month, day )
    then return dateErrorMsg
    end

    local currentDate = os.time()
    local articleDate = os.time{
        year  = year,
        month = month,
        day   = day
    }

    if os.difftime( currentDate, articleDate ) < 86400 * 31 * ( .5 + showMonths )
    then return timelyNewsMsg
    else return expiredNewsMsg
    end

end

function p.getMesiVisualizzazione()

    return showMonths

end

return p