Modulo:Citazione/sandbox: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
correggo |
|||
(87 versioni intermedie di 7 utenti non mostrate) | |||
Riga 3:
--[[ ===============================================================================
Variabile in cui vengono memorizzate le condizioni di errore registrate durante l'
delle funzioni del modulo.
===============================================================================]]
Riga 13:
--[[ ===============================================================================
-- 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
--[[ ===============================================================================
Caricamento delle tabelle di configurazione del modulo.
===============================================================================]]
local cfg = mw.loadData('Module:Citazione/Configurazione/sandbox')
--local cfg = load_configuration_table('Module:Citazione/Configurazione')
--[[ ===============================================================================
Lista di tutti i parametri riconosciuti.
===============================================================================]]
local whitelist = mw.loadData(
--local whitelist = load_configuration_table('Module:Citazione/Whitelist')
--[[ ===============================================================================
Riga 83 ⟶ 98:
--[[ ===============================================================================
Ritorna true/false a seconda che la stringa
===============================================================================]]
local function
return require('Modulo:
end
Riga 453 ⟶ 468:
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_italicizable( t[2] ) and wrap( 'italic-title', t[2] ) or t[2]
value = value .. ' / ' .. external_link( t[1], t[2] )
end
end
return value
end
Riga 489 ⟶ 517:
if ( code == "A" ) then
return link_id({link=handler.link, label=handler.label,
pattern="[
encode = handler.encode})
elseif ( code == "M" ) then
return link_id({link=handler.link, label=handler.label,
pattern="[
encode = handler.encode})
elseif ( code == "W" ) then
return link_id({link=handler.link, label=handler.label,
pattern= "[
encode = handler.encode})
else
return link_id({link=handler.link, label=handler.label,
pattern= "[
encode = handler.encode}) ..
' ' .. set_error( 'bad_ol' );
Riga 642 ⟶ 670:
--[[ ===============================================================================
che 01 e 1 siano resi come 1º qualora indichino il giorno.
===============================================================================]]
local function get_date(str)
if is_set(str) then
local
if try_day then
local Month = cfg.months[tonumber(try_month)]
if Month then
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
Riga 672 ⟶ 705:
date = month .. " " .. year
if is_set(day) then
if day == "01" or day=="1" then day="1
date = day .. " " .. date
end
Riga 689 ⟶ 722:
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
Riga 764 ⟶ 799:
Estrae una lista di nomi (autori o editori) dalla lista argomenti
===============================================================================]]
local function extract_names(args, list_name, parent_name)
local names = {};
local i = 1;
local last;
local parameters = {
first = cfg.aliases[list_name .. '-First'],
last = cfg.aliases[list_name .. '-Last'],
link = cfg.aliases[list_name .. '-Link'],
}
if parent_name then
for k, t in pairs(parameters) do
local new_values = {}
for _, v in ipairs(t) do
table.insert( new_values, substitute(v, parent_name) )
end
parameters[k] = new_values
end
end
while true do
last = select_one( args,
if not is_set(last) then
local first = select_one( args,
if not is_set(first) then
break;
Riga 779 ⟶ 829:
last = first,
first = '',
link = select_one( args,
}
end
Riga 785 ⟶ 835:
names[i] = {
last = last,
first = select_one( args,
link = select_one( args,
};
end
Riga 863 ⟶ 913:
===============================================================================]]
local function get_format(format, url)
if format:lower() == 'html' then
return ''
if not cfg.external_link_type[
if not cfg.external_link_type[
return ''
end
Riga 876 ⟶ 926:
-- Se il formato esterno è tra quelli previsti imita lo stile dei template {{PDF}} o {{doc}}
local f = cfg.external_link_type[
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',
return mw.ustring.format(' (%s)',
end
end
Riga 904 ⟶ 954:
local Others = A['Others'];
local Editors = A['Editors'];
local e = extract_names( args, 'EditorList' );
Riga 933 ⟶ 982:
local Illustrator = A['Illustrator'];
local Translator = A['Translator'];
local Institution = A['Institution'];
if is_set(OriginalTitle) and not is_set(TransTitle) then
TransTitle =
end
Riga 954 ⟶ 1 003:
Position = PPPrefix .. Position
elseif PositionOrigin ~= "posizione" then
if config.CitationClass == "libro" then
Position =
elseif string.find(Position, '^%d') then
Position = PPPrefix .. Position
end
elseif config.CitationClass=="conferenza" or config.CitationClass== "pubblicazione" then
Position = (tonumber(Position) and PPrefix or PPPrefix) .. Position
end
elseif PositionOrigin == "pagina" then
Riga 1 038 ⟶ 1 086:
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. " .. Volume
end
end
if is_set(Issue) and A:ORIGIN('Periodical') ~= "collana" then
if tonumber(Issue:gsub('[-/]', ''), 10) then
Issue = "n
end
end
Riga 1 056 ⟶ 1 105:
local Via = A['Via'];
-- local Agency = A['Agency'];
local DeadURL = A['DeadURL'];
local Language = A['Language'];
local Format = A['Format'];
Riga 1 067 ⟶ 1 116:
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 ~= '.' );
Riga 1 074 ⟶ 1 123:
local ID_list = extract_ids( args );
if ( isPubblicazione ) then
if not is_set(URL) and not is_set(
if is_set(ID_list['PMC']) then
if is_set(Embargo) then
local
local good1, result1, good2, result2;
good1, result1 = pcall( lang.formatDate, lang, 'U', Embargo ); good2, result2 = pcall( lang.formatDate, lang, 'U' );
if good1 and good2 and tonumber( result1 ) < tonumber( result2 ) then
URL = "
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
elseif is_set(ID_list['DOI']) then
URL = "
URLorigin = cfg.id_handlers['
end
end
Riga 1 109 ⟶ 1 163:
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
Riga 1 115 ⟶ 1 182:
------------------------------------------------------------------------------
local auto_Periodical = false
if in_array(config.CitationClass,
Periodical = mw.ustring.match(URL, "//([^/#%?]*)") or ''
-- tolgo anche eventuale www.
Riga 1 122 ⟶ 1 189:
end
-- evito ripetizione se il dominio è stato usato come titolo o editore
if is_set(Periodical)
if mw.ustring.lower(Title Periodical =
end
if mw.ustring.lower(PublisherName) == mw.ustring.lower(Periodical) then
PublisherName = ''
end
end
auto_Periodical = true
end
------------------------------------------------------------------------------
-- Per cambiare posizione alle collane nella citazione rispetto ai nomi
-- di rivista ed evitare che siano precedute da un "in"
------------------------------------------------------------------------------
local EditorialCollection = ''
if is_set(Periodical) and A:ORIGIN('Periodical') == "collana" then
EditorialCollection = "(collana " .. Periodical;
if is_set(Issue) then
EditorialCollection = EditorialCollection .. ', ' .. Issue;
Issue = '';
end
EditorialCollection = EditorialCollection .. ')';
Periodical = '';
end
Riga 1 139 ⟶ 1 225:
TitleLink = '';
TransTitle = '';
end
---------------------------------------------------------------
-- Compone la stringa della lingua
---------------------------------------------------------------
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:Lingue").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 .. "ª 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
Riga 1 156 ⟶ 1 289:
-- 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
Riga 1 171 ⟶ 1 305:
-- Recupero e formatto lista curatori
------------------------------------------------------------------------------
local
local CuratoriEtal = A['Etalcuratori']
control.coauthors = false
if is_set(Editors) then
msg_editors = 'editors'
else
local EditorCount
Editors, EditorCount = list_people(control, e)
if is_set(Editors) then
end
end
------------------------------------------------------------------------------
--
------------------------------------------------------------------------------
local msg_chapter_editors
local Contributors, ChapterEditors = "", ""
if is_set(Chapter) then
local ChapterEditorCount
control.etal = false
Contributors = list_people(control,
extract_names( args, 'ContributorList', A:ORIGIN('Chapter') ))
ChapterEditors, ChapterEditorCount = list_people(control,
extract_names( args, 'ChapterEditorList', A:ORIGIN('Chapter') ))
if is_set(ChapterEditors) then
msg_chapter_editors = ChapterEditorCount <= 1 and 'editor' or 'editors'
end
end
Riga 1 236 ⟶ 1 377:
not is_set(ArchiveURL) and
not is_set(ConferenceURL) then
--
if in_array(
table.insert( z.message_tail, { set_error( 'cite_web_url', {}, true ) } );
end
Riga 1 316 ⟶ 1 457:
end
end
Chapter =
if is_set(TransChapter) then Chapter = Chapter .. " " .. TransChapter end
if is_set(Chapter) then
Riga 1 328 ⟶ 1 469:
end
elseif is_set(URL) then
Chapter = external_link( URL, Chapter ) .. TransError
Chapter = append_links(Chapter, args.altrilink)
Chapter = Chapter .. Format;
URL = "";
Format = "";
Riga 1 351 ⟶ 1 494:
end
end
Title =
if is_set(TransTitle) then Title = Title .. " " .. TransTitle end
if is_set(Title) then
Riga 1 357 ⟶ 1 500:
Title = "[[" .. TitleLink .. "|" .. Title .. "]]"
elseif is_set(URL) then
Title = external_link( URL, Title ) .. TransError
Title = append_links(Title, args.altrilink)
Title = Title .. Format
URL = "";
Format = "";
Riga 1 374 ⟶ 1 519:
elseif is_set(ConferenceURL) then
Conference = external_link( ConferenceURL, nil, ConferenceURLorigin );
end
Riga 1 447 ⟶ 1 551:
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 =
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
ArchiveOutput = ArchiveDate .. ArchiveError
local ArchiveURL2 = A['ArchiveURL2']
local ArchiveDate2 = get_date(A['ArchiveDate2'])
if is_set(ArchiveURL2) then
local ArchiveURLDate2 = decodeArchiveDate(ArchiveURL2)
local ArchiveError2, ArchiveOutput2 = ''
if not is_set(ArchiveDate2) then
ArchiveDate2 =
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'] ),
if not is_set(OriginalURL) then
Archived = Archived
end
elseif is_set(OriginalURL) then
Archived = substitute( cfg.messages['archived-dead'],
{ OriginalURL,
else
Archived = substitute( cfg.messages['archived-missing'],
{ set_error('archive_missing_url'),
end
else
Riga 1 487 ⟶ 1 606:
elseif is_set(PublisherName) then
PublisherName = PublisherName .. " " .. OrigDate
elseif is_set(
Place = Place .. " " .. OrigDate
else
Riga 1 496 ⟶ 1 615:
-- 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
-- set translator / illustrator
Riga 1 540 ⟶ 1 650:
fragment_citation:append(fragment_Title)
else
if is_set(
fragment_citation = Fragment.new({
else
if is_set(
ChapterEditors = wrap(msg_chapter_editors, ChapterEditors)
end
if is_set(Chapter) and not (is_set(Contributors) or is_set(ChapterEditors)) then
if
Contributors, Authors = Authors, ""
elseif is_set(Editors) and args["anteposizione-curatore"] ~= "no" then
ChapterEditors, Editors = wrap(msg_editors, Editors), ""
end
end
fragment_citation
end
if is_set(Chapter) then
-- antepone "su" anzichè "in" per i siti web
if A:ORIGIN('Periodical') == 'sito' or auto_Periodical then
fragment_citation:last("su")
else
fragment_citation:last("in")
end
end
if is_set(Editors) and (is_set(Authors) or args["anteposizione-curatore"] == "no" and not is_set(Chapter)) then
Editors = 'a cura di ' .. Editors
fragment_citation:appends({Authors, fragment_Title, Editors})
else
if is_set(Editors) then
Editors = wrap(msg_editors, Editors)
end
fragment_citation:appends({is_set(Authors) and Authors or Editors, fragment_Title})
end
end
fragment_citation:appends( { Conference, Periodical, Translator, Illustrator, Others, Series, Volume, Issue,
local fragment_ID_list = Fragment.new(ID_list, sepc):append(ID):start(",")
local fragment_URL = Fragment.new(URL):start(",")
local
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, EditorialCollection, fragment_URL,
if PostScript == 'nessuno' then
fragment_citation:last("nothing")
Riga 1 575 ⟶ 1 698:
fragment_citation:last("..")
end
fragment_citation:appends({fragment_Quote})
fragment_citation:start(" ")
local text = Language_code .. tostring(fragment_citation)
-- aggiungo l'icona per
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
Riga 1 685 ⟶ 1 809:
else
if #suggestions == 0 then
suggestions = mw.loadData(
--suggestions = load_configuration_table( 'Modulo:Citazione/Suggerimenti');
end
if suggestions[ k:lower() ] ~= nil then
Riga 1 712 ⟶ 1 837:
end
-- Funzione per generare direttamente una citazione
function z.
-- 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
|