Module:Citation/CS1: Difference between revisions
Adds a variety of error tracking and handling
m>Dragons flight (error handling for archiveurl / url) |
m>Dragons flight (Adds a variety of error tracking and handling) |
||
Line 1: | Line 1: | ||
local z = {} | local z = {} | ||
Line 21: | Line 15: | ||
["'"] = ''', | ["'"] = ''', | ||
['['] = '[', | ['['] = '[', | ||
[']'] = ']', | [']'] = ']', | ||
['{'] = '{', | ['{'] = '{', | ||
['|'] = '|', | ['|'] = '|', | ||
['}'] = '}' } ); | ['}'] = '}' } ); | ||
Line 108: | Line 102: | ||
end | end | ||
function doi(id, inactive | function doi(id, inactive) | ||
local cat = "" | local cat = "" | ||
local error_categories = {}; | |||
local text; | local text; | ||
if ( inactive ~= nil ) then | if ( inactive ~= nil ) then | ||
text = "[[Digital object identifier|doi]]:" .. id; | text = "[[Digital object identifier|doi]]:" .. id; | ||
table.insert( error_categories, "Pages with DOIs inactive since " .. selectyear(inactive) ); | |||
inactive = " (inactive " .. inactive .. ")" | inactive = " (inactive " .. inactive .. ")" | ||
else | else | ||
Line 120: | Line 116: | ||
end | end | ||
if ( string.sub(id,1,3) ~= "10." ) then | if ( string.sub(id,1,3) ~= "10." ) then | ||
table.insert( error_categories, "Pages with DOI errors" ); | |||
cat = ' <span class="error">Bad DOI (expected "10." prefix) in code number</span>' | |||
end | end | ||
return text .. inactive .. cat, error_categories | |||
return text .. inactive .. cat | |||
end | end | ||
Line 235: | Line 231: | ||
function openlibrary(id) | function openlibrary(id) | ||
local | local error_categories = {}; | ||
local prefix = "" | local prefix = "" | ||
local code = id:sub(-1,-1) | local code = id:sub(-1,-1) | ||
Line 246: | Line 242: | ||
else | else | ||
prefix = "http://openlibrary.org/OL" | prefix = "http://openlibrary.org/OL" | ||
table.insert( error_categories, "Pages with OL errors" ); | |||
end | end | ||
local text = externallinkid({link="Open Library",label="OL",prefix=prefix,id=id}) | local text = externallinkid({link="Open Library",label="OL",prefix=prefix,id=id}) | ||
if #error_categories ~= 0 then | |||
text = text .. ' <span class="error">Bad OL specified</span>'; | |||
end | |||
return text, error_categories | |||
end | end | ||
Line 360: | Line 359: | ||
function citation0( config, args) | function citation0( config, args) | ||
local error_categories = {}; | |||
--------------------------------------------------- Get parameters | --------------------------------------------------- Get parameters | ||
Line 495: | Line 495: | ||
local TranscriptURL = args["transcript-url"] or args.transcripturl | local TranscriptURL = args["transcript-url"] or args.transcripturl | ||
local sepc = args.separator | local sepc = args.separator | ||
local no_tracking_cats = args["template doc demo"] or args["nocat"] or args["notracking"] or args["no-tracking"]; | |||
if ( config.CitationClass == "journal" ) then | if ( config.CitationClass == "journal" ) then | ||
Line 678: | Line 680: | ||
-- Captures the value for Date prior to adding parens or other textual transformations | -- Captures the value for Date prior to adding parens or other textual transformations | ||
local DateIn = Date | local DateIn = Date | ||
if ( config.CitationClass == "web" ) then | |||
if ( URL == nil or URL == '' ) and | |||
( ChapterURL == nil or ChapterURL == '' ) and | |||
( ArchiveURL == nil or ArchiveURL == '' ) and | |||
( ConferenceURL == nil or ConferenceURL == '' ) and | |||
( TranscriptURL == nil or TranscriptURL == '' ) then | |||
table.insert( error_categories, 'Pages using web citations with no URL' ); | |||
if Title == nil or Title == "" then | |||
Authors = Authors .. "<!-- No URL on cite web here -->"; | |||
else | |||
Title = Title .. "<!-- No URL on cite web here -->"; | |||
end | |||
end | |||
end | |||
if ( Chapter == nil or Chapter == "" ) and | |||
( Title == nil or Title == "" ) and | |||
( Periodcial == nil or Periodical == "" ) and | |||
( Conference == nil or Conference == "" ) then | |||
table.insert( error_categories, 'Pages with citations lacking titles' ); | |||
Authors = Authors .. "<!-- No citation title here -->"; | |||
end | |||
if ( Format ~= nil and Format ~="" ) then | if ( Format ~= nil and Format ~="" ) then | ||
Line 839: | Line 863: | ||
BIBCODE = sepc .. " " .. externallinkid({label="Bibcode",link="Bibcode",prefix="http://adsabs.harvard.edu/abs/",id=BIBCODE,separator=":"}) else BIBCODE = "" end | BIBCODE = sepc .. " " .. externallinkid({label="Bibcode",link="Bibcode",prefix="http://adsabs.harvard.edu/abs/",id=BIBCODE,separator=":"}) else BIBCODE = "" end | ||
if ( DOI ~= nil and DOI ~= "" ) then | if ( DOI ~= nil and DOI ~= "" ) then | ||
local DOI_string, DOI_error; | |||
DOI_string, DOI_error = doi(DOI, DoiBroken); | |||
DOI = sepc .. " " .. DOI_string | |||
for _, v in ipairs( DOI_error ) do | |||
table.insert( error_categories, v ); | |||
end | |||
else | |||
DOI = "" | |||
end | |||
if ( ID ~= nil and ID ~="") then ID = sepc .." ".. ID else ID="" end | if ( ID ~= nil and ID ~="") then ID = sepc .." ".. ID else ID="" end | ||
if ( ISBN ~= nil and ISBN ~= "") then | if ( ISBN ~= nil and ISBN ~= "") then | ||
Line 856: | Line 888: | ||
OCLC = sepc .." " .. externallinkid({label="OCLC",link="OCLC",prefix="//www.worldcat.org/oclc/",id=OCLC}) else OCLC = "" end | OCLC = sepc .." " .. externallinkid({label="OCLC",link="OCLC",prefix="//www.worldcat.org/oclc/",id=OCLC}) else OCLC = "" end | ||
if ( OL ~= nil and OL ~="") then | if ( OL ~= nil and OL ~="") then | ||
OL = sepc .." " .. | local OL_string, OL_error; | ||
OL_string, OL_error = openlibrary(OL); | |||
OL = sepc .. " " .. OL_string | |||
for _, v in ipairs( OL_error ) do | |||
table.insert( error_categories, v ); | |||
end | |||
else | |||
OL = ""; | |||
end | |||
if ( OSTI ~= nil and OSTI ~="") then | if ( OSTI ~= nil and OSTI ~="") then | ||
OSTI = sepc .." " .. externallinkid({label="OSTI",link="Office of Scientific and Technical Information",prefix="http://www.osti.gov/energycitations/product.biblio.jsp?osti_id=",id=OSTI}) else OSTI = "" end | OSTI = sepc .." " .. externallinkid({label="OSTI",link="Office of Scientific and Technical Information",prefix="http://www.osti.gov/energycitations/product.biblio.jsp?osti_id=",id=OSTI}) else OSTI = "" end | ||
Line 869: | Line 909: | ||
if ( URL ~= nil and URL ~="") then | if ( URL ~= nil and URL ~="") then | ||
URL = " " .. url(URL) | URL = " " .. url(URL) | ||
table.insert( error_categories, "Pages with citations having bare URLs" ); | |||
if config.CitationClass == "web" then | |||
URL = URL .. " <span class='error'>No <code>title=</code> specified</span>" | |||
else | |||
URL = URL .. "<!-- Bare URL here -->" | |||
end | |||
else | else | ||
URL = "" | URL = "" | ||
Line 890: | Line 936: | ||
ArchiveDate = " " .. ArchiveDate | ArchiveDate = " " .. ArchiveDate | ||
else | else | ||
ArchiveDate = "<span class='error'>If you specify <code>archiveurl=</code>, you must also specify <code>archivedate=</code></span> " | ArchiveDate = " <span class='error'>If you specify <code>archiveurl=</code>, you must also specify <code>archivedate=</code></span> " | ||
table.insert( error_categories, 'Pages with archiveurl citation errors' ); | |||
end | end | ||
local arch_text = " archived" | local arch_text = " archived" | ||
Line 902: | Line 949: | ||
Archived = sepc .. arch_text .. " from <span class='error'>If you specify <code>archiveurl=</code>" .. | Archived = sepc .. arch_text .. " from <span class='error'>If you specify <code>archiveurl=</code>" .. | ||
", you must also specify <code>url=</code></span> on" .. ArchiveDate | ", you must also specify <code>url=</code></span> on" .. ArchiveDate | ||
table.insert( error_categories, 'Pages with archiveurl citation errors' ); | |||
end | end | ||
end | end | ||
Line 963: | Line 1,011: | ||
local tcommon | local tcommon | ||
if ( config.CitationClass == "journal" ) then | if ( config.CitationClass == "journal" ) then | ||
tcommon = safejoin( {Title, TitleNote, Format, TitleType, Conference, Periodical, Series, Language, Edition, Publisher, Agency, Others, Volume, Issue, Position }, sepc ); | tcommon = safejoin( {Title, TitleNote, Format, TitleType, Conference, Periodical, Series, Language, Edition, Publisher, Agency, Others, Volume, Issue, Position}, sepc ); | ||
elseif ( config.CitationClass == "citation" ) or (config.CitationClass == "encyclopaedia" ) then | elseif ( config.CitationClass == "citation" ) or (config.CitationClass == "encyclopaedia" ) then | ||
tcommon = safejoin( {Title, TitleNote, Format, TitleType, Conference, Periodical, Series, Language, Volume, Issue, Edition, Publisher, Agency, Others, Position}, sepc ); | tcommon = safejoin( {Title, TitleNote, Format, TitleType, Conference, Periodical, Series, Language, Volume, Issue, Edition, Publisher, Agency, Others, Position}, sepc ); | ||
Line 985: | Line 1,033: | ||
local pgtext = Page .. Pages .. At | local pgtext = Page .. Pages .. At | ||
if page_error then | if page_error then | ||
pgtext = pgtext .. ' | table.insert( error_categories, 'Pages with citations using conflicting page specifications' ); | ||
pgtext = pgtext .. '<!-- Bad page specification here -->'; | |||
end | end | ||
Line 1,082: | Line 1,131: | ||
end | end | ||
if string.len(text) < 2 then | if string.len(text:gsub("%b<>", "")) <= 2 then | ||
table.insert( error_categories, 'Pages with empty citations' ); | |||
text = '<span class="error">Citation is empty</span>'; | text = '<span class="error">Citation is empty</span>'; | ||
end | end | ||
Line 1,092: | Line 1,142: | ||
-- Note: Using display: none on then COinS span breaks some clients. | -- Note: Using display: none on then COinS span breaks some clients. | ||
local OCinS = createTag({name="span", contents=empty_span, params={class="Z3988",title=OCinStitle }}) | local OCinS = createTag({name="span", contents=empty_span, params={class="Z3988",title=OCinStitle }}) | ||
text = text .. OCinS; | |||
if no_tracking_cats ~= nil and no_tracking_cats ~= '' then | |||
error_categories = {}; | |||
end | |||
for _, v in pairs( error_categories ) do | |||
text = text .. '[[Category:' .. v ..']]'; | |||
end | |||
return text | |||
end | end | ||