Modulo:Citazione/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Riga 9:
error_categories = {}; -- lista delle categorie di errore
error_ids = {}; -- lista dei codici di errore
message_tail = {}; -- messagimessaggi di errore da visualizzare in coda alla citazione
}
 
Riga 15:
Caricamente delle tabelle di configurazione del modulo.
===============================================================================]]
local cfg = mw.loadData( 'Modulo:Citazione/Configurazione/sandbox' );
 
--[[ ===============================================================================
Riga 759:
local function anchor_id( options )
return "CITEREF" .. table.concat( options );
end
 
--- Get the values from a simple list of arguments
-- @param args Tne argument table e.g. { language1=, language2=, }
--- Note that it does not care about { language= }
-- @param list_name The internal list name e.g. 'LanguageList'
-- @return The table of values
local function extract_simple_list( args, list_name )
local list = {};
local i = 1;
list_name = cfg.aliases[ list_name ]; -- LanguageList → language#
while true do
local k = mw.ustring.gsub( list_name, '#', i ) --language# → language1
local v = args[ k ]
if not is_set( v ) then
break
end
list[ i ] = v;
i = i + 1;
end
return list
end
 
Riga 878 ⟶ 857:
 
return new_list;
end
 
--[[ ===============================================================================
Genera la stringa per il formato, se format non è definita tenta di ricavarlo dall'url
===============================================================================]]
local function get_format(format, url)
 
local try_format = format
if not is_set( v try_format) then
local try_format = mw.ustring.match( (is_set(ChapterURL) and ChapterURL) or URLurl, "^.*%.(.+)$" ) or ''
if not cfg.external_link_type[try_format:lower()] then
try_format = mw.ustring.match(try_format, "^(.+)#.+$") or ''
local if f =not cfg.external_link_type[Formattry_format:lower()] then
return list''
end
end
end
 
-- Se il formato esterno è tra quelli previsti imita lo stile dei template {{PDF}} o {{doc}}
local f = cfg.external_link_type[try_format:lower()]
if f then
Format =return mw.ustring.format(' (<span style="font-weight: bolder; font-size:80%%"><abbr title="%s">%s</abbr></span>)', f.text, f.label)
else
table.insert( z.message_tail, { set_error('unknown_format', Formattry_format, true) } );
Format =return mw.ustring.format(' (%s)', Formattry_format)
end
end
 
Riga 1 052 ⟶ 1 057:
-- local Agency = A['Agency'];
local DeadURL = A['DeadURL']
local Language = A['Language']; -- space-separated languages (for historical reasons)
local Languages = extract_simple_list( args, 'LanguageList' ); -- table of languages
local Format = A['Format'];
local Ref = A['Ref'];
Riga 1 257 ⟶ 1 261:
end
 
-- genera la stringa per il formato
-- Se il formato file non è specificato, prova a ricavarlo dalla fine dell'URL
ifFormat = get_format(Format, (is_set(URL) orand is_set(ChapterURL)URL) andor notChapterURL is_set(Format) then
local try_format = mw.ustring.match( (is_set(ChapterURL) and ChapterURL) or URL, "^.*%.(.+)$" ) or ''
if cfg.external_link_type[try_format:lower()] then
Format = try_format
end
end
 
-- Se il formato esterno è tra quelli previsti imita lo stile dei template {{PDF}} o {{doc}}
if is_set(Format) then
local f = cfg.external_link_type[Format:lower()]
if f then
Format = mw.ustring.format(' (<span style="font-weight: bolder; font-size:80%%"><abbr title="%s">%s</abbr></span>)', f.text, f.label)
else
table.insert( z.message_tail, { set_error('unknown_format', Format, true) } );
Format = mw.ustring.format(' (%s)', Format)
end
else
Format = ""
end
 
-- In maniera predefinita l'URL non è dichiarato morto
Riga 1 394 ⟶ 1 380:
---------------------------------------------------------------
local Language_code = ""
if is_set(Language) or is_set(Languages) then
if Language:sub(1,1) == "(" then
Language_code = Language
Riga 1 400 ⟶ 1 386:
local frame_lingue = {return_error='true', usacodice='sì'}
for lingua in mw.ustring.gmatch(Language, "%S+") do
frame_lingue[#frame_lingue+1] = lingua
end
for _, lingua in pairs( Languages ) do
frame_lingue[#frame_lingue+1] = lingua
end
Riga 1 735 ⟶ 1 718:
rows[#rows+1] = "|}"
return table.concat(rows, '\n')
end
 
-- per formati esterni da altri template
function z.format(frame)
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame, {frameOnly = true})
return get_format(args[1])
end