Modul:Citation: Unterschied zwischen den Versionen
Umstellung
K (+Abruf) |
(Umstellung) |
||
| Zeile 2: | Zeile 2: | ||
local scrollGallery = { | local scrollGallery = { | ||
suite = 'Citation', | suite = 'Citation', | ||
serial = '2020-03- | serial = '2020-03-23', | ||
} | } | ||
| Zeile 14: | Zeile 14: | ||
local ci = {} | local ci = {} | ||
-- global variables | |||
local types = { | local types = { | ||
book = { 'book', 'Buch' }, | book = { 'book', 'Buch' }, | ||
| Zeile 33: | Zeile 34: | ||
abbr = { 'Abk', types = { 'collection', 'journal', 'newspaper' } }, | abbr = { 'Abk', types = { 'collection', 'journal', 'newspaper' } }, | ||
url = { 'Online', 'URL' }, | url = { 'Online', 'URL' }, | ||
articleUrl = { 'Onlineaufsatz', types = { 'collection', 'journal', 'newspaper' } }, | articleUrl = { 'Onlineaufsatz', 'Aufsatz-URL', types = { 'collection', 'journal', 'newspaper' } }, | ||
jstor = { 'JSTOR', types = { 'journal', 'newspaper' } }, | jstor = { 'JSTOR', types = { 'journal', 'newspaper' } }, | ||
KBytes = { 'KBytes', 'kBytes', 'kbytes' }, | |||
accessDate = { 'Zugriff', 'Abruf' }, | accessDate = { 'Zugriff', 'Abruf' }, | ||
scale = { 'Maßstab', types = 'map' }, | scale = { 'Maßstab', types = 'map' }, | ||
| Zeile 69: | Zeile 70: | ||
tiScale = 'Maßstab: %s. ', | tiScale = 'Maßstab: %s. ', | ||
tiIn = 'In: ', | tiIn = 'In: ', | ||
tiChapter = "Kapitel ''%s''", | |||
puAll = '%s.', | puAll = '%s.', | ||
puPlaceDate = '%s, %s', | puPlaceDate = '%s, %s', | ||
| Zeile 93: | Zeile 95: | ||
dbIssn = '[[w:Internationale Standardnummer für fortlaufende Sammelwerke|ISSN]] [http://zdb-katalog.de/list.xhtml?t=iss%3D%22xx1xx%22&key=cql xx1xx]', | dbIssn = '[[w:Internationale Standardnummer für fortlaufende Sammelwerke|ISSN]] [http://zdb-katalog.de/list.xhtml?t=iss%3D%22xx1xx%22&key=cql xx1xx]', | ||
dbJstor = '[[w:JSTOR|JSTOR]] [https://www.jstor.org/stable/%s %s]', | dbJstor = '[[w:JSTOR|JSTOR]] [https://www.jstor.org/stable/%s %s]', | ||
wbAccess = 'Internetabruf am %s', | |||
wbKBytes = 'Dateigröße %s KByte' | |||
} | } | ||
| Zeile 108: | Zeile 112: | ||
local errorMsgs = {} | local errorMsgs = {} | ||
local dateFormat = '' | |||
-- check if table contains the value | -- check if table contains the value | ||
| Zeile 139: | Zeile 144: | ||
end | end | ||
local function cleanupParameters( | -- string cleanup | ||
if not | local function cleanupParameters( s ) | ||
return | if not s or s == '' then | ||
return s | |||
end | end | ||
s = s:gsub( '[\009\010\013]', ' ' ) -- horizontal tab, line feed, carriage return | |||
s = s:gsub( '[%z%c]', '' ) -- control characters | |||
s = s:gsub( ' ', ' ' ); | |||
s = s:gsub( '\226\128\138', ' ' ); -- hair space | |||
s = mw.ustring.gsub( s, '[\226\128\141\226\128\139\194\173]', '' ); -- zero-width joiner, zero-width space, soft hyphen | |||
s = mw.ustring.gsub( s, '%.%.%.', '…' ) | |||
s = mw.ustring.gsub( s, '%.%.', '‥' ) | |||
s = mw.ustring.gsub( s, '<br%s*/*>', '' ) | |||
s = mw.ustring.gsub( s, '</*p%s*/*>', '' ) | |||
return mw.ustring.gsub( | return mw.ustring.gsub( s, '</*span%s*/*>', '' ) | ||
end | end | ||
| Zeile 177: | Zeile 183: | ||
end | end | ||
args[ key ] = args[ key ] or '' | args[ key ] = args[ key ] or '' | ||
end | |||
end | |||
-- no missing items | |||
for key, value in pairs( params ) do | |||
if not args[ key ] then | |||
args[ key ] = '' | |||
end | end | ||
end | end | ||
| Zeile 193: | Zeile 205: | ||
end | end | ||
return args | return args | ||
end | |||
local function getPageNumbers( pages ) | |||
if not pages then | |||
return '' | |||
end | |||
pages = ( '' .. pages ):gsub( '–', '-' ); -- replace endashes with hyphens | |||
return pages:gsub( '&%w+;', '-' ); -- replace html entities with hyphens | |||
end | |||
local function checkValues( args ) | |||
local i, key, value | |||
args.pages = getPageNumbers( args.pages ) | |||
args.columns = getPageNumbers( args.columns ) | |||
args.noError = yn( args.noError, false ) | |||
if args.noError then | |||
args.noError = 'true' | |||
else | |||
args.noError = 'false' | |||
end | |||
if args.date ~= '' then | |||
if args.date:match( '^[12]%d%d%d%-[01]?%d%-[0123]?%d$' ) then | |||
dateFormat = 'j. F Y' | |||
elseif args.date:match( '^[12]%d%d%d%-[01]?%d%$' ) then | |||
dateFormat = 'M Y' | |||
elseif args.date:match( '^[12]%d%d%d%' ) then | |||
dateFormat = 'Y' | |||
else | |||
args.date = args.date:match( '%d+' ) or '' | |||
if args.date ~= '' then | |||
i = tonumber( args.date ) | |||
if i >= 1000 and i < 2100 then | |||
dateFormat = 'Y' | |||
else | |||
args.date = '' | |||
table.insert( errorMsgs, texts.wrongDate ) | |||
end | |||
end | |||
end | |||
end | |||
if args.accessDate ~= '' and | |||
not args.accessDate:match( '^20%d%d%-[01]?%d%-[0123]?%d$' ) then | |||
args.accessDate = '' | |||
table.insert( errorMsgs, texts.wrongDate ) | |||
end | |||
i = 0 | |||
for key, value in ipairs( { 'url', 'articleUrl' } ) do | |||
if args[ value ] ~= '' then | |||
if uc.isUrl( args[ value ] ) > 2 then | |||
args[ value ] = '' | |||
i = i + 1 | |||
end | |||
end | |||
end | |||
if i > 0 then | |||
table.insert( errorMsgs, texts.noURL ) | |||
end | |||
for key, value in ipairs( { 'dnb', 'oclc', 'jstor', 'KBytes' } ) do | |||
if not args[ value ]:match( '^%d+$' ) then | |||
args[ value ] = '' | |||
end | |||
end | |||
args.edition = args.edition:match( '%d+' ) or '' | |||
if args.edition == '1' then | |||
args.edition = '' | |||
end | |||
if args.type ~= 'map' then | |||
args.scale = '' | |||
end | |||
end | end | ||
| Zeile 212: | Zeile 300: | ||
local function makeTitle( title, volume, url, scale ) | local function makeTitle( title, volume, url, scale ) | ||
if | if title == '' then | ||
title = texts.noTitle | title = texts.noTitle | ||
table.insert( errorMsgs, texts.unknownTitle ) | table.insert( errorMsgs, texts.unknownTitle ) | ||
end | end | ||
if | if url ~= '' then | ||
title = '[' .. url .. ' ' .. title .. ']' | |||
end | end | ||
| Zeile 242: | Zeile 326: | ||
end | end | ||
local function makeIssnLink( issn ) | local function makeIssnLink( issn, noError ) | ||
local text = '' | |||
if noError ~= 'true' then | |||
text = texts.wrongIssn | |||
end | |||
return formatters.dbIssn:gsub( 'xx1xx', issn ) | return formatters.dbIssn:gsub( 'xx1xx', issn ) | ||
.. cx.check_issn( { args = { [ 1 ] = issn, error = | .. cx.check_issn( { args = { [ 1 ] = issn, error = text } } ) | ||
end | end | ||
local function | local function makePublisher( args, tab ) | ||
local theDate = args.date | local theDate = args.date | ||
local published = '' | local published = '' | ||
if theDate ~= '' and args.edition ~= '' then | if theDate ~= '' and args.edition ~= '' then | ||
theDate = mw.ustring.format( formatters.puDateEdition, args.date, args.edition ) | theDate = mw.ustring.format( formatters.puDateEdition, args.date, args.edition ) | ||
| Zeile 287: | Zeile 354: | ||
published = mw.ustring.format( formatters.puPlaceDate, published, theDate ) | published = mw.ustring.format( formatters.puPlaceDate, published, theDate ) | ||
end | end | ||
if published ~= '' then | |||
table.insert( tab, published ) | |||
end | |||
end | |||
local function makeSeries( args, tab ) | |||
local key, value | |||
for key, value in ipairs( { 'series', 'series2', 'series3' } ) do | |||
if args[ value ] ~= '' then | |||
table.insert( tab, mw.ustring.format( formatters.addSeries, args[ value ] ) ) | |||
end | |||
end | end | ||
end | |||
local function makeIsbn( args, tab ) | |||
if args.isbn ~= '' then | if args.isbn ~= '' then | ||
table.insert( | table.insert( tab, | ||
li._linkISBNSet( { isbn = args.isbn, noerror = args.noError } ) ) | li._linkISBNSet( { isbn = args.isbn, noerror = args.noError } ) ) | ||
elseif args.dnb ~= '' then | elseif args.dnb ~= '' then | ||
table.insert( | table.insert( tab, mw.ustring.format( formatters.dbDnb, args.dnb, args.dnb ) ) | ||
elseif args.oclc ~= '' then | elseif args.oclc ~= '' then | ||
table.insert( | table.insert( tab, mw.ustring.format( formatters.dbOclc, args.oclc, args.oclc ) ) | ||
end | end | ||
if args.issn ~= '' then | if args.issn ~= '' then | ||
table.insert( | table.insert( tab, makeIssnLink( args.issn, args.noError ) ) | ||
end | end | ||
end | |||
local function makePages( args, tab ) | |||
if args.pages ~= '' then | if args.pages ~= '' then | ||
table.insert( | table.insert( tab, | ||
mw.ustring.format( formatters.addPages, args.pages:gsub( '-', '–' ) ) ) | mw.ustring.format( formatters.addPages, args.pages:gsub( '-', '–' ) ) ) | ||
end | end | ||
if args.columns ~= '' then | if args.columns ~= '' then | ||
table.insert( | table.insert( tab, | ||
mw.ustring.format( formatters.addColumns, args.columns:gsub( '-', '–' ) ) ) | mw.ustring.format( formatters.addColumns, args.columns:gsub( '-', '–' ) ) ) | ||
end | end | ||
end | |||
local function makeDoi( args, tab ) | |||
if args.extent ~= '' then | if args.extent ~= '' then | ||
table.insert( | table.insert( tab, args.extent ) | ||
end | end | ||
if args.doi ~= '' then | if args.doi ~= '' then | ||
table.insert( | table.insert( tab, | ||
mw.ustring.format( formatters.addDoi, makeDoiLink( args.doi ) ) ) | mw.ustring.format( formatters.addDoi, makeDoiLink( args.doi ) ) ) | ||
end | end | ||
if args.jstor ~= '' then | |||
table.insert( tab, | |||
mw.ustring.format( formatters.dbJstor, args.jstor, args.jstor ) ) | |||
end | |||
end | |||
local function makeWebInfo( args, tab ) | |||
if args.url ~= '' or args.articleUrl ~= '' then | |||
if args.accessDate ~= '' then | |||
args.accessDate = getDate( args.accessDate, 'j. F Y' ) | |||
if args.accessDate ~= '' then | |||
table.insert( tab, | |||
mw.ustring.format( formatters.wbAccess, args.accessDate ) ) | |||
end | |||
end | |||
if args.KBytes ~= '' then | |||
table.insert( tab, | |||
mw.ustring.format( formatters.wbKBytes, args.KBytes ) ) | |||
end | |||
end | |||
end | |||
local function makeLanguageComment( args, result ) | |||
if args.language ~= '' then | if args.language ~= '' then | ||
result = result .. mw.ustring.format( formatters.addLanguage, args.language ) | |||
end | end | ||
if | if result ~= '' then | ||
result = mw.ustring.format( formatters.puAll, result ) | |||
end | end | ||
if args.comment ~= '' then | if args.comment ~= '' then | ||
result = result .. mw.ustring.format( formatters.addComment, args.comment ) | |||
end | end | ||
return result | |||
end | |||
return | local function makePublished( args ) | ||
result = {} | |||
makePublisher( args, result ) | |||
makeSeries( args, result ) | |||
makeIsbn( args, result ) | |||
if args.chapter ~= '' then | |||
table.insert( mw.ustring.format( formatters.tiChapter, args.chapter ) ) | |||
end | |||
makePages( args, result ) | |||
if #result > 0 then | |||
result = { table.concat( result, formatters.addDelimiter1 ) } | |||
end | |||
makeDoi( args, result ) | |||
makeWebInfo( args, result ) | |||
result = table.concat( result, formatters.addDelimiter2 ) | |||
return makeLanguageComment( args, result ) | |||
end | end | ||
local function makeBook( args ) | local function makeBook( args ) | ||
local author, title | local author, title | ||
| Zeile 377: | Zeile 488: | ||
title = args.newspaper | title = args.newspaper | ||
end | end | ||
if | if title == '' then | ||
title = texts.noTitel | title = texts.noTitel | ||
table.insert( errorMsgs, texts.unknownPeriodical ) | table.insert( errorMsgs, texts.unknownPeriodical ) | ||
| Zeile 412: | Zeile 523: | ||
end | end | ||
local function | local function makeJournalInfo( args, tab ) | ||
local year = '' | |||
if args.date ~= '' then | |||
local | year = getDate( args.date, dateFormat ) | ||
if args. | |||
end | end | ||
if args. | local volume = '' | ||
if args.volume ~= '' then | |||
volume = mw.ustring.format( formatters.prVolume, args.volume ) | |||
if args.issue ~= '' then | |||
volume = mw.ustring.format( formatters.prVolIssue, volume, args.issue ) | |||
end | end | ||
if year ~= '' then | |||
if year | volume = mw.ustring.format( formatters.prVolYear, volume, year ) | ||
end | end | ||
else | |||
if args. | if args.issue ~= '' then | ||
volume = mw.ustring.format( formatters. | volume = mw.ustring.format( formatters.prIssue, args.issue ) | ||
if year ~= '' then | if year ~= '' then | ||
volume = mw.ustring.format( formatters.prVolYear, volume, year ) | volume = mw.ustring.format( formatters.prVolYear, volume, year ) | ||
end | end | ||
else | else | ||
volume = year | |||
end | end | ||
end | |||
if volume ~= '' then | |||
table.insert( tab, volume ) | |||
end | |||
end | |||
local function makeNewspaperInfo( args, tab ) | |||
if args.volume ~= '' then | |||
if args.date:match( '^[12]%d | table.insert( tab, | ||
mw.ustring.format( formatters.nsVolume, args.volume ) ) | |||
end | |||
day = '' | |||
if args.date ~= '' then | |||
if args.date:match( '^[12]%d%d%d%-[01]?%d%-[0123]?%d$' ) then | |||
day = getDate( args.date, 'l, j. F Y' ) | day = getDate( args.date, 'l, j. F Y' ) | ||
else | else | ||
table.insert( errorMsgs, texts.wrongDate ) | table.insert( errorMsgs, texts.wrongDate ) | ||
end | end | ||
end | end | ||
if args. | local issue = '' | ||
if args.issue ~= '' then | |||
mw.ustring.format( formatters. | issue = mw.ustring.format( formatters.prIssue, args.issue ) | ||
if day ~= '' then | |||
issue = mw.ustring.format( formatters.nsNrOfDay, issue, day ) | |||
end | |||
else | |||
issue = day | |||
end | end | ||
if | if issue ~= '' then | ||
table.insert( | table.insert( tab, issue ) | ||
end | end | ||
end | |||
local function makePeriodical( args ) | |||
local result = { makeAuthor( args.author, '' ) | |||
.. makeTitle( args.title, '', args.articleUrl, '' ) .. formatters.tiIn | |||
.. makeJournalTitle( args ) } | |||
if args. | makeIsbn( args, result ) | ||
if args.type == 'journal' then | |||
makeJournalInfo( args, result ) | |||
else | |||
makeNewspaperInfo( args, result ) | |||
end | end | ||
makePages( args, result ) | |||
makeDoi( args, result ) | |||
makeWebInfo( args, result ) | |||
result = table.concat( result, formatters.addDelimiter1 ) | |||
return makeLanguageComment( args, result ) | |||
end | end | ||
local function | local function prepareForCOinS( args ) | ||
if | args.date = args.date:match( '%d+' ) or '' | ||
args.pages = args.pages:match( '%d+%-%d+' ) or args.pages:match( '%d+' ) | |||
args.columns = args.columns:match( '%d+%-%d+' ) or args.columns:match( '%d+' ) | |||
-- only first author | |||
local at = args.author:find( ';' ), count | |||
if at then | |||
args.author = mw.text.trim( args.author:sub( 1, at - 1 ) ) | |||
else | |||
_,count = args.author:gsub( '@', '@' ) | |||
if count > 1 then | |||
at = args.author:find( ',' ) | |||
args.author = mw.text.trim( args.author:sub( 1, at - 1 ) ) | |||
end | |||
end | end | ||
end | end | ||
| Zeile 562: | Zeile 652: | ||
return '<span class="Z3988" title="' .. rft .. '"></span>' | return '<span class="Z3988" title="' .. rft .. '"></span>' | ||
end | end | ||
end | |||
-- remove adjoining punctuation marks | |||
local function finalCleanup( s ) | |||
s = mw.ustring.gsub( s, '%.+%.', '.' ) | |||
s = mw.ustring.gsub( s, '([!%?])(%s%.+)', '%1' ) | |||
return mw.ustring.gsub( s, '([,;:])(%s%.+)', '.' ) | |||
end | end | ||
| Zeile 567: | Zeile 664: | ||
local args, citation | local args, citation | ||
args = checkParams( frameArgs ) | args = checkParams( frameArgs ) | ||
if args.type == 'map' or args.type == 'book' then | if args.type == 'map' or args.type == 'book' then | ||
| Zeile 579: | Zeile 674: | ||
citation = texts.wrongType | citation = texts.wrongType | ||
end | end | ||
citation = finalCleanup( citation ) | |||
prepareForCOinS( args ) | |||
return table.concat( errorMsgs, ' ' ) | return table.concat( errorMsgs, ' ' ) | ||