Modulo:Citazione: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
compatibilità con IsLatin (vedi discussione)
aggiorno funzione link_id e imposto la preposizione "su" anche quando Periodical è prelevato dall'url (vedi discussioni)
Riga 83:
 
--[[ ===============================================================================
Ritorna true/nofalse a seconda che la stringa sia esclusivamente in caratteri latini
===============================================================================]]
local function is_latin( str )
Riga 382:
 
--[[ ===============================================================================
Formatta un wikilink interno o un link esterno a un documento
- options.code_id: codice per il link (tra prefisso e suffisso)esterno
- options.id: etichetta del link esterno o id del documento
- options.encode: se true o nil l'url viene codificato (en:Percent-encoding)
- options.link: link alla voce wiki sul codice documento
- options.label: etichetta del link alla voce wiki sul codice documento
- optionoptions.separator: separatore tra codice e link (di default ununo nospazio breaking spaceunificatore)
- options.pattern: pattern del link in cui "$1" è l'id normale e "$2" l'id nell'url esterno
- options.prefix: prefisso dell'url
- options.suffis: suffisso dell'url (opzionale)
===============================================================================]]
local function external_link_idlink_id(options)
local url_string = options.code_id or options.id;
if options.encode == true or options.encode == nil then
url_string = mw.uri.encode( url_string );
end
returnfor w in mw.ustring.formatgmatch( '[[%s|%s]]%s[%s%s%soptions.pattern, %s]',$1' ) do
options.link,pattern = mw.ustring.gsub( options.labelpattern, options'^(%[[^%[]%S+)$1(.separator-%])', or'%1$2%2' "&nbsp);",
options.prefix,pattern url_string,= mw.ustring.gsub( options.suffixpattern, or ""'([^%[]%[[^%[]%S+)$1(.-%])', '%1$2%2' );
end
mw.text.nowiki(options.id)
return mw.ustring.format( '[[%s|%s]]%s[[%s%s%s|%s]]',
);
end
 
--[[ ===============================================================================
Formatta un wikilink interno
- options.id: id del documento
- options.encode: se true o nil l'url viene codificato (en:Percent-encoding)
- options.link: link alla voce wiki sul codice documento
- options.label: etichetta del link alla voce wiki sul codice documento
- option.separator: separatore tra codice e link (di default un no breaking space)
- options.prefix: prefisso del link
- options.suffis: suffisso del link (opzionale)
===============================================================================]]
local function internal_link_id(options)
return mw.ustring.format( '[[%s|%s]]%s[[%s%s%s|%s]]',
options.link, options.label, options.separator or " ",
substitute( options.prefixpattern, {mw.text.nowiki(options.id), options.suffixurl_string} or "",)
mw.text.nowiki(options.id)
);
end
Line 509 ⟶ 493:
inactive = " (" .. cfg.messages['inactive'] .. " " .. inactive .. ")"
else
text = external_link_idlink_id({link = handler.link, label = handler.label,
prefixpattern=handler.prefixpattern,id=id,separator=handler.separator, encode=handler.encode})
inactive = ""
end
Line 526 ⟶ 510:
local handler = cfg.id_handlers['OL'];
if ( code == "A" ) then
return external_link_idlink_id({link=handler.link, label=handler.label,
prefixpattern="[http://openlibrary.org/authors/OL$1 $1]",id=id, separator=handler.separator,
encode = handler.encode})
elseif ( code == "M" ) then
return external_link_idlink_id({link=handler.link, label=handler.label,
prefixpattern="[http://openlibrary.org/books/OL$1 $1]",id=id, separator=handler.separator,
encode = handler.encode})
elseif ( code == "W" ) then
return external_link_idlink_id({link=handler.link, label=handler.label,
prefixpattern= "[http://openlibrary.org/works/OL$1 $1]",id=id, separator=handler.separator,
encode = handler.encode})
else
return external_link_idlink_id({link=handler.link, label=handler.label,
prefixpattern= "[http://openlibrary.org/OL$1 $1]",id=id, separator=handler.separator,
encode = handler.encode}) ..
' ' .. set_error( 'bad_ol' );
Line 555 ⟶ 539:
end
if cd1 and cd2 then
return external_link_idlink_id({link=handler.link, label=handler.label,
prefixpattern='[http://opac.sbn.it/bid/$1 $1]', id = id, code_id=cd1 .. cd2,
encode =handler.encode})
else
return external_link_idlink_id({link=handler.link, label=handler.label,
prefixpattern='[http://opac.sbn.it/bid/$1 $1]', id = id,
encode =handler.encode}) .. ' ' .. set_error('bad_sbn')
end
Line 618 ⟶ 602:
-- dans tous les cas on renvoie l'adresse, on catégorise juste pour vérifier ce qui ne va pas
return external_link_idlink_id( {
link=handler.link,
label=handler.label,
prefixpattern=handler.prefixpattern,
id=txt,
code_id=bnf_id,
Line 866 ⟶ 850:
local handler = setmetatable( { ['id'] = v }, fallback(k) );
 
if handler.modek == 'externalDOI' then
table.insert( new_list, {handler.label, external_link_id( handler ) } );
elseif handler.mode == 'internal' then
table.insert( new_list, {handler.label, internal_link_id( handler ) } );
elseif handler.mode ~= 'manual' then
error( cfg.messages['unknown_ID_mode'] );
elseif k == 'DOI' then
table.insert( new_list, {handler.label, doi( v, options.DoiBroken ) } );
elseif k == 'OL' then
Line 885 ⟶ 863:
ISBN = 'ISBN non esistente'
else
ISBN = internal_link_idlink_id( handler );
if not check_isbn( v ) and not is_set(options.IgnoreISBN) then
ISBN = ISBN .. set_error( 'bad_isbn', {}, false, "<sup>", "</sup>" );
Line 892 ⟶ 870:
table.insert( new_list, {handler.label, ISBN } );
else
table.insert( new_list, {handler.label, external_link_idlink_id( handler ) } );
error( cfg.messages['unknown_manual_ID'] );
end
end
Line 1 128 ⟶ 1 106:
TransTitle = '';
Series = '';
end
 
------------------------------------------------------------------------------
-- Se compare uno dei parametri legati a una pubblicazione periodica (opera, rivista, ec...)
-- e non è definito capitolo, ma solo titolo sposto titolo a capitolo
------------------------------------------------------------------------------
if is_set(Periodical) and not is_set(Chapter) and is_set(Title) then
Chapter = Title;
ChapterLink = TitleLink;
TransChapter = TransTitle;
Title = '';
TitleLink = '';
TransTitle = '';
end
 
Line 1 146 ⟶ 1 111:
-- Se opera/sito non è specificata, nel caso dei siti usa il dominio dell'URL
------------------------------------------------------------------------------
local auto_Periodical = false
if config.CitationClass == "web" and not is_set(Periodical) and not is_set(PublisherName) and is_set(URL) then
Periodical = mw.ustring.match(URL, "//([^/#%?]*)") or ''
Line 1 156 ⟶ 1 122:
Periodical = nil
end
auto_Periodical = true
end
 
------------------------------------------------------------------------------
-- Se compare uno dei parametri legati a una pubblicazione periodica (opera, rivista, ec...)
-- e non è definito capitolo, ma solo titolo sposto titolo a capitolo
------------------------------------------------------------------------------
if is_set(Periodical) and not is_set(Chapter) and is_set(Title) then
Chapter = Title;
ChapterLink = TitleLink;
TransChapter = TransTitle;
Title = '';
TitleLink = '';
TransTitle = '';
end
 
Line 1 579 ⟶ 1 559:
fragment_citation = Fragment.new({Authors, Chapter}, sepc)
if Chapter ~= "" or Editors ~= "" then
if A:ORIGIN('Periodical') == 'sito' or auto_Periodical then -- antepone "su" anzichè "in" per i siti web
fragment_citation:last("su")
else