Modulo:Citazione: Differenze 'mbrà revisiune

Contenuto cancellato Contenuto aggiunto
Provo ad aggiornare per vedere se il "cita_da_modulo" funzionasse sul Collegamenti esterni
Tag: Annullate
Repristine 'a revisione 138788 da S4b1nuz E.656 ('Ngazzaminde)
Tag: Annulle
Linea 3:
 
--[[ ===============================================================================
Variabile in cui vengono memorizzate le condizioni di errore registrate durante l'esecuzioneesecusione
delle funzioni del modulo.
===============================================================================]]
Linea 11:
message_tail = {}; -- messaggi di errore da visualizzare in coda alla citazione
}
 
--[[ ===============================================================================
Carica la tabella di configurazione, correggendo il nome se caricato da sandbox
-- nota: non ancora attiva per qualche motivo non funziona
===============================================================================]]
local function load_configuration_table(name)
local frame = mw.getCurrentFrame()
local real_name = name
if nil ~= string.find (frame:getTitle(), 'sandbox', 1, true) then
real_name = real_name .. '/sandbox'
end
return mw.loadData(real_name)
end
 
--[[ ===============================================================================
Caricamente delle tabelle di configurazione del modulo.
===============================================================================]]
local cfg = mw.loadData( 'ModuleModulo:Citazione/Configurazione');
--local cfg = load_configuration_table('Module:Citazione/Configurazione')
 
--[[ ===============================================================================
Lista di tutti i parametri riconosciuti.
===============================================================================]]
local whitelist = mw.loadData( 'ModuleModulo:Citazione/Whitelist' );
--local whitelist = load_configuration_table('Module:Citazione/Whitelist')
 
--[[ ===============================================================================
Linée 468 ⟶ 453:
end
return table.concat({ "[", URL, " ", safe_for_url( label ), "]", error_str });
end
 
--[[ ===============================================================================
Aggiunta collegamenti multipli, per ora usati solo dal modulo Collegamenti esterni
===============================================================================]]
local function append_links(value, links)
if type(links) == 'table' then
for _, t in ipairs(links) do
t[2] = is_latin( t[2] ) and wrap( 'italic-title', t[2] ) or t[2]
value = value .. ' / ' .. external_link( t[1], t[2] )
end
end
return value
end
 
Linée 517 ⟶ 489:
if ( code == "A" ) then
return link_id({link=handler.link, label=handler.label,
pattern="[[openlibraryhttp://openlibrary.org/authors/OL$1| $1]]",id=id, separator=handler.separator,
encode = handler.encode})
elseif ( code == "M" ) then
return link_id({link=handler.link, label=handler.label,
pattern="[[openlibraryhttp://openlibrary.org/books/OL$1| $1]]",id=id, separator=handler.separator,
encode = handler.encode})
elseif ( code == "W" ) then
return link_id({link=handler.link, label=handler.label,
pattern= "[[openlibraryhttp://openlibrary.org/works/OL$1| $1]]",id=id, separator=handler.separator,
encode = handler.encode})
else
return link_id({link=handler.link, label=handler.label,
pattern= "[[openlibraryhttp://openlibrary.org/OL$1| $1]]",id=id, separator=handler.separator,
encode = handler.encode}) ..
' ' .. set_error( 'bad_ol' );
Linée 670 ⟶ 642:
 
--[[ ===============================================================================
RiconosceRitorna leuna datedata e controlla se è nel formato ISO yyyy-mm-dd e le riformatta in dmy.questo Sicaso assicurala
riformatta come dd mmmm yyyy
che 01 e 1 siano resi come 1º qualora indichino il giorno.
===============================================================================]]
local function get_date(str)
if is_set(str) then
local _, _, try_year, try_month, try_day = string.matchfind(str, '^(%d%d%d%d)-(%d%d)-(%d%d)$')
if try_day then
local Month = cfg.months[tonumber(try_month)]
if Month then
try_day =if try_day == '"01'" andthen 'try_day="1º'°" or tonumber(try_day)end
return string.format("%s %s %s", try_day, Month, try_year )
end
end
try_day, try_month, try_year = string.match(str, '^(%d%d?) (%a+) (%d%d%d%d)$')
if try_day then
try_day = (try_day == '1' or try_day == '01') and '1º' or tonumber(try_day)
return string.format("%s %s %s", try_day, try_month, try_year)
end
end
Linée 705 ⟶ 672:
date = month .. " " .. year
if is_set(day) then
if day == "01" or day=="1" then day="1º°" end
date = day .. " " .. date
end
Linée 722 ⟶ 689:
local start = mw.ustring.sub(str, 1, 2)
if in_array( start, {'08', '8 ', '8-', '8/', '11'} ) then
return " l'"
elseif mw.ustring.find(str, '^pre ') then -- per i valori "pre x/x/x" inseriti da ArchiveBot
return ' in data '
end
return str ~= '' and " il " or ''
end
 
Linée 898 ⟶ 863:
===============================================================================]]
local function get_format(format, url)
 
if format:lower() == 'html' then
local try_format = format
return ''
elseifif not is_set(formattry_format) then
formattry_format = mw.ustring.match(url, "^.*%.(.+)$" ) or ''
if not cfg.external_link_type[formattry_format:lower()] then
formattry_format = mw.ustring.match(formattry_format, "^(.+)#.+$") or ''
if not cfg.external_link_type[formattry_format:lower()] then
return ''
end
Linée 911 ⟶ 876:
 
-- Se il formato esterno è tra quelli previsti imita lo stile dei template {{PDF}} o {{doc}}
local f = cfg.external_link_type[formattry_format:lower()]
if f then
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) } );
return mw.ustring.format(' (%s)', formattry_format)
end
end
Linée 968 ⟶ 933:
local Illustrator = A['Illustrator'];
local Translator = A['Translator'];
local Institution = A['Institution'];
 
if is_set(OriginalTitle) and not is_set(TransTitle) then
TransTitle = Title
Title = OriginalTitle
end
 
Linée 989 ⟶ 954:
Position = PPPrefix .. Position
elseif PositionOrigin ~= "posizione" then
table.insert(if zconfig.error_categories,CitationClass 'Voci== con"libro" modulo citazione e parametro ' ..and PositionOrigin=="pagine" )then
if PositionOrigin == "pagine"tonumber(Position) then
Position = PPrefix .. Position
if config.CitationClass == "libro" then
ifelseif tonumberstring.find(Position, '^%d') then
Position = PPrefixPPPrefix .. Position
end
elseif string.find(Position, '^%d') then
elseif (config.CitationClass=="conferenza" or config.CitationClass== "pubblicazione") and PositionOrigin=="pagine" then
Position = PPPrefix .. Position
if tonumber(Position) then
end
Position = PPrefix .. Position
elseif config.CitationClass=="conferenza" or config.CitationClass== "pubblicazione" then
else
Position = (tonumber(Position) and PPrefix or PPPrefix) .. Position
Position = PPPrefix .. Position
end
elseif PositionOrigin == "pagina" then
Linée 1 072 ⟶ 1 038:
end
else
-- formatta Volume e Issue considerando numeri anche le stringhe del tipo n-n o n/n
if is_set(Volume) then
if tonumber(Volume:gsub('[-/]', ''), 10) or A:ORIGIN('Volume') == "vol" then
Volume = "vol.&nbsp;" .. Volume
end
end
if is_set(Issue) then
if tonumber(Issue:gsub('[-/]', ''), 10) then
Issue = "n.º&nbsp;" .. Issue
end
end
Linée 1 091 ⟶ 1 056:
local Via = A['Via'];
-- local Agency = A['Agency'];
local DeadURL = A['DeadURL'];
local Language = A['Language'];
local Format = A['Format'];
Linée 1 102 ⟶ 1 067:
local sepc = Style.sep
local sepcspace = sepc .. " "
local PostScript = first_set(A['PostScript'], Style['postscript']);
local no_tracking_cats = A['NoTracking'];
local use_lowercase = ( sepc ~= '.' );
Linée 1 109 ⟶ 1 074:
local ID_list = extract_ids( args );
if ( isPubblicazione ) then
if not is_set(URL) and not is_set(TitleLinkID_list['PMC']) then
local Embargo = A['Embargo'];
if is_set(ID_list['PMC']) then
localif is_set(Embargo) = A['Embargo'];then
local lang = mw.getContentLanguage();
if is_set(Embargo) then
local langgood1, =result1, mw.getContentLanguage()good2, result2;
local good1, result1 = pcall( lang.formatDate, good2lang, result2'U', Embargo );
good1good2, result1result2 = pcall( lang.formatDate, lang, 'U', Embargo );
good2, result2 = pcall( lang.formatDate, lang, 'U' );
 
if good1 and good2 and tonumber( result1 ) < tonumber( result2 ) then
URL = "httpshttp://www.ncbi.nlm.nih.gov/pmc/articles/PMC" .. ID_list['PMC'];
URLorigin = cfg.id_handlers['PMC'].parameters[1];
end
else
URL = "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC" .. ID_list['PMC'];
URLorigin = cfg.id_handlers['PMC'].parameters[1];
end
else
elseif is_set(ID_list['DOI']) then
URL = "httpshttp://oadoiwww.orgncbi.nlm.nih.gov/pmc/articles/PMC" .. ID_list['DOIPMC'];
URLorigin = cfg.id_handlers['DOIPMC'].parameters[1];
end
end
Linée 1 149 ⟶ 1 109:
TransTitle = '';
Series = '';
end
 
------------------------------------------------------------------------------
-- Se url è in realtà un url archiviato, lo tratta come tale
-- (per ora riconosce solo Internet Archive)
------------------------------------------------------------------------------
local formatoIA = '^https?://web%.archive%.org/w?e?b?/?%d+/'
if is_set(URL) and is_set(Title) and URL:match(formatoIA) and not is_set(ArchiveURL) then
ArchiveURL = URL
URL = URL:gsub(formatoIA,'')
if not URL:match('://') then
URL = 'http://' .. URL
end
end
 
Linée 1 168 ⟶ 1 115:
------------------------------------------------------------------------------
local auto_Periodical = false
if in_array(config.CitationClass, {'== "web'})" and not is_set(Periodical) and not is_set(PublisherName) and is_set(URL) then
Periodical = mw.ustring.match(URL, "//([^/#%?]*)") or ''
-- tolgo anche eventuale www.
Linée 1 180 ⟶ 1 127:
auto_Periodical = true
end
------------------------------------------------------------------------------
-- Per cambiare posizione a collane o serie di libri nella citazione,
-- rispetto a nomi di rivistaed evitare di precederle con un "in"
-- TODO per il momento commentato (da rivedere per chiarire collana/opera)
------------------------------------------------------------------------------
-- local Book_series = ''
-- if is_set(Periodical) and (A:ORIGIN('Periodical') == "opera" or A:ORIGIN('Periodical') == "collana") then
-- Book_series = "collana " .. wrap( 'italic-title', Periodical );
-- Periodical = '';
-- end
 
------------------------------------------------------------------------------
Linée 1 202 ⟶ 1 139:
TitleLink = '';
TransTitle = '';
end
 
---------------------------------------------------------------
-- Compone la stringa del linguaggio
---------------------------------------------------------------
local Language_code = ""
local first_language = ""
if is_set(Language) then
if Language:sub(1,1) == "(" then
Language_code = Language
else
local frame_lingue = {return_error='true'}
for lingua in mw.text.gsplit(Language, ',', true) do
lingua = mw.text.trim(lingua)
if lingua ~= '' then
frame_lingue[#frame_lingue+1] = lingua
end
end
if #frame_lingue > 1 or (#frame_lingue==1 and frame_lingue[1]:lower()~="it" and frame_lingue[1]:lower()~="it-it") then
first_language = frame_lingue[1]:lower();
local lg_error;
Language_code, lg_error = require("Modulo:Linguaggi").lingue(frame_lingue)
if lg_error and #lg_error > 0 then
local error_string = mw.text.listToText(lg_error, ", ", " e " )
table.insert( z.message_tail, { set_error('unknown_language', {error_string}, true) } );
end
end
end
end
if is_set(Edition) then
if A:ORIGIN('Edition') == "ed" or tonumber(Edition) then
Edition = Edition .. "ª&nbsp;ed."
end
end
 
------------------------------------------------------------------------------
-- Aggiunge il wikilink a Wikisource
------------------------------------------------------------------------------
if is_set(A['Source']) and not in_array(config.CitationClass, { "web", "video", "tv", "audio" } ) then
local source = A['Source']
-- se s=1 usa lo stesso valore di titolo/capitolo
if source == "1" then
source = Title .. (is_set(Chapter) and ("/" .. Chapter) or "")
end
source = "s:" .. (is_set(first_language) and (first_language .. ":") or "") .. source
if is_set(Chapter) then ChapterLink = source
else TitleLink = source end
end
 
Linée 1 266 ⟶ 1 156:
-- If the coauthor field is also used, prevent adding ''et al.''
if is_set(Coauthors) then
table.insert( z.error_categories, 'Voci con modulo citazione e parametro ' .. A:ORIGIN('Coauthors') )
control.coauthors = true
elseif is_set(Etal) then
Linée 1 347 ⟶ 1 236:
not is_set(ArchiveURL) and
not is_set(ConferenceURL) then
-- ControllaTest seif Citacite web vieneis chiamatocalled senzawithout giving a URL
if in_array( config.CitationClass, {'== "web'}" ) then
table.insert( z.message_tail, { set_error( 'cite_web_url', {}, true ) } );
end
Linée 1 439 ⟶ 1 328:
end
elseif is_set(URL) then
Chapter = external_link( URL, Chapter ) .. TransError .. Format;
Chapter = append_links(Chapter, args.altrilink)
Chapter = Chapter .. Format;
URL = "";
Format = "";
Linée 1 470 ⟶ 1 357:
Title = "[[" .. TitleLink .. "|" .. Title .. "]]"
elseif is_set(URL) then
Title = external_link( URL, Title ) .. TransError .. Format
Title = append_links(Title, args.altrilink)
Title = Title .. Format
URL = "";
Format = "";
Linée 1 489 ⟶ 1 374:
elseif is_set(ConferenceURL) then
Conference = external_link( ConferenceURL, nil, ConferenceURLorigin );
end
 
---------------------------------------------------------------
-- Compone la stringa del linguaggio
---------------------------------------------------------------
local Language_code = ""
if is_set(Language) then
if Language:sub(1,1) == "(" then
Language_code = Language
else
local frame_lingue = {return_error='true', usacodice='sì'}
for lingua in mw.ustring.gmatch(Language, "%S+") do
frame_lingue[#frame_lingue+1] = lingua
end
if #frame_lingue > 1 or (#frame_lingue==1 and frame_lingue[1]:lower()~="it") then
local lg_error
Language_code, lg_error = require("Modulo:Linguaggi").lingue(frame_lingue)
if lg_error and #lg_error > 0 then
local error_string = mw.text.listToText(lg_error, ", ", " e " )
table.insert( z.message_tail, { set_error('unknown_language', {error_string}, true) } );
end
end
end
end
 
if is_set(Edition) then
if A:ORIGIN('Edition') == "ed" or tonumber(Edition) then
Edition = Edition .. "ª&nbsp;ed."
end
end
 
Linée 1 521 ⟶ 1 435:
local Archived
if is_set(ArchiveURL) then
local decodeArchiveDate = require('Modulo:Webarchive').decodeArchiveDate
local ArchiveURLDate = decodeArchiveDate(ArchiveURL)
local ArchiveError, ArchiveOutput = ''
if not is_set(ArchiveDate) then
ArchiveDate = ArchiveURLDate or set_error('archive_missing_date');
if not ArchiveURLDate then
ArchiveError = set_error('archive_missing_date', {}, false, ' ')
end
elseif ArchiveURLDate and ArchiveURLDate ~= ArchiveDate then
ArchiveError = set_error('date_mismatch', {ArchiveURLDate}, false, ' ')
end
ArchiveURL2 = A['ArchiveURL2']
ArchiveOutput = ArchiveDate .. ArchiveError
local ArchiveURL2 = A['ArchiveURL2']
local ArchiveDate2 = get_date(A['ArchiveDate2'])
if is_set(ArchiveURL2) then
ArchiveDate2 = A['ArchiveDate2']
local ArchiveURLDate2 = decodeArchiveDate(ArchiveURL2)
local ArchiveError2, ArchiveOutput2 = ''
if not is_set(ArchiveDate2) then
ArchiveDate2 = ArchiveURLDate2 or set_error('archive_missing_date2');
if not ArchiveURLDate2 then
ArchiveError2 = set_error('archive_missing_date2', {}, false, ' ')
end
elseif ArchiveURLDate2 and ArchiveURLDate2 ~= ArchiveDate2 then
ArchiveError2 = set_error('date2_mismatch', {ArchiveURLDate2}, false, ' ')
end
ArchiveOutput2 = ArchiveDate2 .. ArchiveError2
ArchiveURL2 = substitute(cfg.messages['archived-second-copy'],
{ external_link( ArchiveURL2, cfg.messages['archived2']), ArchiveOutput2, article_date(ArchiveDate2) } );
end
if not DeadURL then
Archived = substitute( cfg.messages['archived-not-dead'],
{ external_link( ArchiveURL, cfg.messages['archived'] ), ArchiveOutputArchiveDate, article_date(ArchiveDate), ArchiveURL2} );
if not is_set(OriginalURL) then
Archived = Archived .. " " .. set_error('archive_missing_url', {}, false, ' ');
end
elseif is_set(OriginalURL) then
Archived = substitute( cfg.messages['archived-dead'],
{ OriginalURL, ArchiveOutputArchiveDate, article_date(ArchiveDate), ArchiveURL2 } );
else
Archived = substitute( cfg.messages['archived-missing'],
{ set_error('archive_missing_url'), ArchiveOutputArchiveDate, article_date(ArchiveDate), ArchiveURL2 } );
end
if is_set(ArchiveURL2) then
Archived = Archived .. ". " .. substitute(cfg.messages['archived-second-copy'],
{ external_link( ArchiveURL2, cfg.messages['archived2']), ArchiveDate2, article_date(ArchiveDate2) } );
end
else
Linée 1 585 ⟶ 1 484:
-- Several of the above rely upon detecting this as nil, so do it last.
if is_set(Periodical) then Periodical = wrap( 'italic-title', Periodical ) end
if config.CitationClass=="news" and is_set(Place) then
if is_set(Periodical) then
Periodical = table.concat({Periodical, ' (', Place, ')'})
Place = ""
elseif is_set(Title) then
Title = table.concat({Title, ' (', Place, ')'})
Place = ""
end
end
 
-- set translator / illustrator
Linée 1 643 ⟶ 1 551:
end
end
fragment_citation:appends( { Conference, Periodical, Translator, Illustrator, Others, Series, -- Book_series,
Volume, Issue, Edition, Institution, Place, PublisherName, Station, Date, Position } )
local fragment_ID_list = Fragment.new(ID_list, sepc):append(ID):start(",")
local fragment_URL = Fragment.new(URL):start(",")
local fragment_AccessDatefragment_AccessInfo = Fragment.new({AccessDate, Via, Archived}, " "):start('".'")
local fragment_Archived = Fragment.new(Archived):start(' ')
local fragment_Via = Fragment.new(Via):start(".")
local fragment_Quote = Fragment.new({Quote}):start(".")
fragment_citation:appends({fragment_ID_list, fragment_URL, fragment_AccessDate, fragment_Archived, fragment_Viafragment_AccessInfo, fragment_Quote})
if PostScript == 'nessuno' then
fragment_citation:last("nothing")
Linée 1 659 ⟶ 1 565:
fragment_citation:start(" ")
local text = Language_code .. tostring(fragment_citation)
-- aggiungo l'icona per cita video/audio
if config.CitationClass == "video" then text = cfg.messages['icon_video'] .. ' ' .. text end
if config.CitationClass == "audio" then text = cfg.messages['icon_audio'] .. ' ' .. text end
 
-- Now enclose the whole thing in a <span/> element
Linée 1 767 ⟶ 1 673:
else
if #suggestions == 0 then
suggestions = mw.loadData( 'Modulo:Citazione/Suggerimenti' );
--suggestions = load_configuration_table( 'Modulo:Citazione/Suggerimenti');
end
if suggestions[ k:lower() ] ~= nil then
Linée 1 795 ⟶ 1 700:
end
 
-- Funzione per generare direttamente una citazione web da un altro modulo
function z.cita_da_modulocitaweb(classe, args)
return citation0( {CitationClass = 'web'}, args )
-- mi assicuro che le code messaggi di errore siano vuote per evitare problemi in caso
-- per citazioni multiple dall'interno dello stesso modulo
z.error_categories = {}; -- lista delle categorie di errore
z.error_ids = {}; -- lista dei codici di errore
z.message_tail = {}; -- messaggi di errore da visualizzare in coda alla citazione
return citation0( {CitationClass = classe}, args )
end