Modulo:Citazione: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Moroboshi (discussione | contributi)
opzione per non esaminare i parametri unnamed
Moroboshi (discussione | contributi)
miglioro il controllo dei doi e semplifico estrazione doi inattivo (da en.wiki)
Riga 453:
end
return table.concat({ "[", URL, " ", safe_for_url( label ), "]", error_str });
end
 
--[[ ===============================================================================
Ritorna la parte di una stringa data che rappresenta l'anno. Se non riesce ritorna
la stringa vuota
===============================================================================]]
local function select_year( str )
-- Is the input a simple number?
local num = tonumber( str );
if num ~= nil and num > 0 and num < 2100 and num == math.floor(num) then
return str;
else
-- Use formatDate to interpret more complicated formats
local lang = mw.getContentLanguage();
local good, result;
good, result = pcall( lang.formatDate, lang, 'Y', str )
if good then
return result;
else
-- Can't make sense of this input, return blank.
return "";
end
end
end
 
Riga 487 ⟶ 464:
local text;
if is_set(inactive) then
local inactive_year = inactive:match("%d%d%d%d") or ''
--text = "[[" .. handler.link .. "|" .. handler.label .. "]]:" .. id;
table.insert( z.error_categories, "Pagine con DOI inattivo dal " .. select_year(inactive) );
if is_set(inactive_year) then
table.insert( z.error_categories, "Pagine con DOI inattivo dal " .. select_year(inactive)inactive_year );
else
table.insert( z.error_categories, "Pagine con DOI inattivo" ); -- when inactive doesn't contain a recognizable year
end
inactive = " (" .. cfg.messages['inactive'] .. " " .. inactive .. ")"
else
text = link_id({link = handler.link, label = handler.label,
pattern=handler.pattern,id=id,separator=handler.separator, encode=handler.encode})
inactive = ""
end
text = link_id({link = handler.link, label = handler.label,
if ( string.sub(id,1,3) ~= "10." ) then
pattern=handler.pattern,id=id,separator=handler.separator, encode=handler.encode}) .. (inactive or '')
if nil == id:match("^10%.[^%s–]-/[^%s–]-[^%.,]$") then -- doi must begin with '10.', must contain a fwd slash, must not contain spaces or endashes, and must not end with period or comma
cat = set_error( 'bad_doi' );
end
return text .. inactive .. cat
end