Modulo:Interprogetto: differenze tra le versioni

Da Wikisource.
Contenuto cancellato Contenuto aggiunto
nolink
m fix
(Una versione intermedia di uno stesso utente non è mostrata)
Riga 38: Riga 38:
local oldArgs = frame:getParent().args
local oldArgs = frame:getParent().args
local args = {}
local args = {}
local addBoxes = (oldArgs[1] ~= 'nolink')
local addBoxes = (oldArgs[1] == nil or mw.text.trim(oldArgs[1]) ~= 'nolink')
local label
local label
if oldArgs.etichetta and mw.text.trim(oldArgs.etichetta) ~= '' then
if oldArgs.etichetta and mw.text.trim(oldArgs.etichetta) ~= '' then

Versione delle 15:58, 10 giu 2014

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

local fmtLink = '* [[%s|%s]]'
local fmtBox = '[[File:%s|link=:%s:|Collabora a %s]] %s'

local cachedProj = {}
local projects = {
	[{'commons', 'Commons'}] = {'c',       'Commons',           'Commons-logo.svg|18px', "'''Commons''' contiene file multimediali su '''[[c:%s|%s]]'''."},
	[{'CommonsAutore'}] =      {'c',       'Commons',           'Commons-logo.svg|18px', "Immagini e/o file multimediali su '''[[c:%s|Commons]]'''"},
	[{'b', 'WikiBooks'}] =     {'b',       'Wikibooks',       'Wikibooks-logo.svg|22px', "'''Wikibooks''' contiene testi o manuali su '''[[:b:%s|%s]]'''."},
	[{'m', 'Meta'}] =          {'m',       'Meta-Wiki',       'Wikimedia-logo.svg|18px', "'''Meta-Wiki''' contiene informazioni su '''[[m:%s|%s]]'''."},
	[{'n', 'WikiNews'}] =      {'n',       'Wikinotizie',      'Wikinews-logo.svg|25px', "'''Wikinotizie''' contiene notizie di attualità su '''[[:n:%s|%s]]'''."},
	[{'nAutore'}] =            {'n',       'Wikinotizie',      'Wikinews-logo.svg|18px', "Notizie di attualità su '''[[:n:%s|Wikinotizie]]'''"},
	[{'q', 'WikiQuote'}] =     {'q',       'Wikiquote',       'Wikiquote-logo.svg|18px', "'''Wikiquote''' contiene citazioni di o su '''[[:q:%s|%s]]'''."},
	[{'qAutore'}] =            {'q',       'Wikiquote',       'Wikiquote-logo.svg|18px', "Citazioni su '''[[:q:%s|Wikiquote]]'''"},
	[{'v', 'WikiVersity'}] =   {'v',       'Wikiversità',   'Wikiversity-logo.svg|18px', "'''Wikiversità''' contiene lezioni su '''[[:v:%s|%s]]'''."},
	[{'w', 'WikiPedia'}] =     {'w',       'Wikipedia',       'Wikipedia-logo.svg|18px', "'''Wikipedia''' ha una voce di approfondimento su '''[[w:%s|%s]]'''."},
	[{'wAutore'}] =            {'w',       'Wikipedia',       'Wikipedia-logo.svg|18px', "Voce enciclopedica su '''[[w:%s|Wikipedia]]'''"},
	[{'wikt', 'WikTionary'}] = {'wikt',    'Wikizionario',  'Wiktionary small.svg|18px', "'''Wikizionario''' contiene il lemma «[[wikt:%s|'''%s''']]»."},
	[{'wikispecies'}] =        {'species', 'Wikispecies', 'WikiSpecies notext.svg|21px', "'''Wikispecies''' contiene informazioni su '''[[species:%s|%s]]'''."},
	[{'oldwikisource'}] =      {'oldwikisource', 'Wikisource'}
}
for keys, val in pairs(projects) do
	for _, key in pairs(keys) do
		cachedProj[key] = val
	end
end

local function createLink(arg1, arg2)
	return string.format(fmtLink, arg1 or '', arg2 or '')
end

local function createBox(val, params)
	return string.format(fmtBox, val[3], val[1], val[2], string.format(val[4], unpack(params)))
end

local p = {}

function p.box(frame)
	local oldArgs = frame:getParent().args
	local args = {}
	local addBoxes = (oldArgs[1] == nil or mw.text.trim(oldArgs[1]) ~= 'nolink')
	local label
	if oldArgs.etichetta and mw.text.trim(oldArgs.etichetta) ~= '' then
		label = oldArgs.etichetta
	else
		label = mw.title.getCurrentTitle().text
	end
	for key, val in pairs(oldArgs) do
		if val and mw.text.trim(val) ~= '' then
			if type(key) == 'number' then
				if cachedProj[val] and (oldArgs[val] == nil or mw.text.trim(oldArgs[val]) == '') then
					args[val] = label
				end
			else
				args[key] = val
			end
		end
	end
	local links = {}
	local boxes = {}
	for key, value in pairs(cachedProj) do
		if args[key] then
			table.insert(links, createLink(value[1] .. ':' .. args[key], value[2]))
			if addBoxes and #value > 3 then
				table.insert(boxes, createBox(value, {args[key], label}))
			end
		end
	end

	local res = ''
	if #links > 0 then
		local interProject = mw.html.create('div')
			:attr('id', 'interProject')
			:css({
				['display'] = 'none',
				['clear'] = 'both',
				['border-top'] = '2px dotted #AAAAAA',
				['margin-top'] = '2em'
			})
			:tag('div')
			:attr('title', 'Collegamenti verso gli altri progetti Wikimedia')
			:wikitext('\n' .. table.concat(links, '\n') .. '\n')
			:allDone()
		res = res .. tostring(interProject)
	end

	if #boxes > 0 then
		local boxesContainer = mw.html.create('div')
			:addClass('noprint ws-noexport')
			:wikitext('\n' .. table.concat(boxes, '\n\n') .. '\n')
			:allDone()
		res = res .. tostring(boxesContainer)
	end

	return res
end

return p