Modul:Citation: Unterschied zwischen den Versionen
(neu angelegt) |
(+cleanup +COinS) |
||
| Zeile 16: | Zeile 16: | ||
editor = { 'Herausgeber' }, | editor = { 'Herausgeber' }, | ||
title = { 'Titel', COinS = 'rft.title' }, | title = { 'Titel', COinS = 'rft.title' }, | ||
chapter = { ' | chapter = { 'Kapitel', types = 'book', COinS = 'rft.atitle' }, | ||
type = { 'type', 'Typ' }, | type = { 'type', 'Typ' }, | ||
genre = { 'Genre', COinS = 'rft.genre', internal = true }, | genre = { 'Genre', COinS = 'rft.genre', internal = true }, | ||
| Zeile 71: | Zeile 71: | ||
addLanguage = ' (%s)', | addLanguage = ' (%s)', | ||
addComment = ' %s', | addComment = ' %s', | ||
dbDnb = '<abbr title="Deutsche Nationalbibliothek">DNB</abbr> [http://d-nb.info/%s %s]', | |||
dbOclc = '<abbr title="Online Computer Library Center (WorldCat)">OCLC</abbr> [https://worldcat.org/oclc/%s %s]', | |||
} | } | ||
| Zeile 98: | Zeile 100: | ||
end | end | ||
-- check for possible arguments against | local function cleanupParameters( value ) | ||
local function checkParams( frameArgs | if not value or value == '' then | ||
return value | |||
end | |||
value = value:gsub( '[\009\010\013]', ' ' ) -- horizontal tab, line feed, carriage return | |||
value = value:gsub( '[%z%c]', '' ) -- control characters | |||
value = value:gsub( ' ', ' ' ); | |||
value = value:gsub( '\226\128\138', ' ' ); -- hair space | |||
value = mw.ustring.gsub( value, '[\226\128\141\226\128\139\194\173]', '' ); -- zero-width joiner, zero-width space, soft hyphen | |||
value = mw.ustring.gsub( value, '<br%s*/*>', '' ) | |||
value = mw.ustring.gsub( value, '</*p%s*/*>', '' ) | |||
return mw.ustring.gsub( value, '</*span%s*/*>', '' ) | |||
end | |||
-- check for possible arguments against params table | |||
local function checkParams( frameArgs ) | |||
local args = {}, key, key2, ok, value, value2 | local args = {}, key, key2, ok, value, value2 | ||
local complete = {} | local complete = {} | ||
local wrongParams = {} | local wrongParams = {} | ||
for key, value in pairs( | for key, value in pairs( params ) do | ||
if not value.internal then | if not value.internal then | ||
if type( value ) == 'table' then | if type( value ) == 'table' then | ||
for key2, value2 in ipairs( value ) do | for key2, value2 in ipairs( value ) do | ||
complete[ value2 ] = key | complete[ value2 ] = key | ||
args[ key ] = args[ key ] or frameArgs[ value2 ] | args[ key ] = args[ key ] or | ||
cleanupParameters( frameArgs[ value2 ] ) | |||
end | end | ||
args[ key ] = args[ key ] or '' | args[ key ] = args[ key ] or '' | ||
else | else | ||
complete[ key ] = key | complete[ key ] = key | ||
args[ key ] = frameArgs[ key ] or '' | args[ key ] = cleanupParameters( frameArgs[ key ] ) or '' | ||
end | end | ||
end | end | ||
| Zeile 203: | Zeile 220: | ||
table.insert( additions, | table.insert( additions, | ||
li._linkISBNSet( { isbn = args.isbn, noerror = args.noError } ) ) | li._linkISBNSet( { isbn = args.isbn, noerror = args.noError } ) ) | ||
elseif args.dnb ~= '' then | |||
table.insert( additions, mw.ustring.format( formatters.dbDnb, args.dnb, args.dnb ) ) | |||
elseif args.oclc ~= '' then | |||
table.insert( additions, mw.ustring.format( formatters.dbOclc, args.oclc, args.oclc ) ) | |||
end | end | ||
if args.pages ~= '' then | if args.pages ~= '' then | ||
| Zeile 266: | Zeile 287: | ||
pages = ( '' .. pages ):gsub( '–', '-' ); -- replace endashes with hyphens | pages = ( '' .. pages ):gsub( '–', '-' ); -- replace endashes with hyphens | ||
return pages:gsub( '&%w+;', '-' ); -- replace html entities with hyphens | return pages:gsub( '&%w+;', '-' ); -- replace html entities with hyphens | ||
end | |||
local function makeCOinS( args ) | |||
local rft = {}, key, value | |||
for key, value in pairs( params ) do | |||
if value.COinS and value.COinS:find( 'rft.' ) and args[ key ] and args[ key ] ~= '' then | |||
table.insert( rft, value.COinS .. '=' .. mw.uri.encode( args[ key ] ) ) | |||
end | |||
end | |||
if next( rft ) then | |||
if args.type == 'book' or args.type == 'map' or args.type == 'collection' then | |||
table.insert( rft, 1, 'rft.genre=book' ) | |||
table.insert( rft, 1, 'rft.rft_val_fmt=' .. mw.uri.encode( 'info:ofi/fmt:kev:mtx:book' ) ) | |||
if args.type == 'collection' then | |||
table.insert( rft, 'rft.atitle=' .. mw.uri.encode( args.title ) ) | |||
table.insert( rft, 'rft.btitle=' .. mw.uri.encode( args.collection ) ) | |||
else | |||
table.insert( rft, 'rft.btitle=' .. mw.uri.encode( args.title ) ) | |||
end | |||
else | |||
table.insert( rft, 1, 'rft.genre=journal' ) | |||
table.insert( rft, 1, 'rft.rft_val_fmt=info:ofi/fmt:kev:mtx:journal' ) | |||
if args.type == 'journal' then | |||
table.insert( rft, 'rft.jtitle=' .. mw.uri.encode( args.journal ) ) | |||
else | |||
table.insert( rft, 'rft.jtitle=' .. mw.uri.encode( args.newspaper ) ) | |||
end | |||
table.insert( rft, 'rft.atitle=' .. mw.uri.encode( args.title ) ) | |||
end | |||
table.insert( rft, 1, 'ctx_ver=Z39.88-2004' ) | |||
rft = table.concat( rft, '&' ) | |||
return '<span class="Z3988" title="' .. rft .. '"></span>' | |||
end | |||
end | end | ||
| Zeile 271: | Zeile 327: | ||
local args, citation | local args, citation | ||
if checkit then | if checkit then | ||
args = checkParams( frameArgs | args = checkParams( frameArgs ) | ||
else | else | ||
args = frameArgs | args = frameArgs | ||
| Zeile 287: | Zeile 343: | ||
citation = makeCollection( args ) | citation = makeCollection( args ) | ||
end | end | ||
return table.concat( errorMsgs, '' ) .. citation | return table.concat( errorMsgs, '' ) | ||
.. '<cite class="citation ' .. args.type .. '">' | |||
.. citation .. '</cite>' .. makeCOinS( args ) | |||
end | end | ||
function ci.book( frame ) | function ci.book( frame ) | ||
local args = frame:getParent().args, ok | |||
-- local args = frame | |||
args.type = 'book' | args.type = 'book' | ||
return makeCitation( args, true ) | return makeCitation( args, true ) | ||
| Zeile 304: | Zeile 362: | ||
function ci.collection( frame ) | function ci.collection( frame ) | ||
local args = frame:getParent().args | |||
-- local args = frame | |||
args.type = 'collection' | args.type = 'collection' | ||
return makeCitation( args, true ) | return makeCitation( args, true ) | ||
| Zeile 324: | Zeile 382: | ||
function ci.citation( frame ) | function ci.citation( frame ) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
args = checkParams( args | args = checkParams( args ) | ||
if args.type == '' then | if args.type == '' then | ||
Version vom 21. März 2020, 21:59 Uhr
Die Dokumentation für dieses Modul kann unter Modul:Citation/doc erstellt werden
-- documentation
local scrollGallery = {
suite = 'Citation',
serial = '2020-03-21',
}
-- module import
local li = require( 'Module:LinkISBN' )
local yn = require( 'Module:Yesno' )
-- module variable
local ci = {}
local params = {
author = { 'Autor', COinS = 'rft.au' },
editor = { 'Herausgeber' },
title = { 'Titel', COinS = 'rft.title' },
chapter = { 'Kapitel', types = 'book', COinS = 'rft.atitle' },
type = { 'type', 'Typ' },
genre = { 'Genre', COinS = 'rft.genre', internal = true },
collection = { 'Sammelwerk', types = 'collection' },
journal = { 'Zeitschrift', types = 'journal', COinS = 'rft.jtitle' },
newspaper = { 'Zeitung', types = 'newspaper', COinS = 'rft.jtitle' },
abbr = { 'Abk', types = { 'collection', 'journal', 'newspaper' } },
url = { 'Online', 'URL' },
articleUrl = { 'Onlineaufsatz', types = { 'collection', 'journal', 'newspaper' } },
jstor = { 'JSTOR', types = { 'journal', 'newspaper' } },
kBytes = { 'kBytes' },
accessDate = { 'Zugriff' },
scale = { 'Maßstab', types = 'map' },
place = { 'Ort', COinS = 'rft.place' },
publisher = { 'Verlag', types = { 'book', 'map', 'collection' }, COinS = 'rft.pub' },
date = { 'Datum', 'Jahr', COinS = 'rft.date' },
edition = { 'Auflage', types = { 'book', 'map', 'collection' }, COinS = 'rft.edition' },
volume = { 'Band', COinS = 'rft.volume' },
issue = { 'Ausgabe', 'Nummer', types = { 'journal', 'newspaper' }, COinS = 'rft.issue' },
pages = { 'Seite', 'Seiten', types = { 'book', 'collection', 'journal', 'newspaper' }, COinS = 'rft.pages' },
columns = { 'Spalten', types = { 'book', 'collection', 'journal', 'newspaper' }, COinS = 'rft.pages' },
extent = { 'Umfang', 'Seitenanzahl', types = { 'book', 'collection', 'map' } },
series = { 'Serie', 'Reihe', types = { 'book', 'collection', 'map' }, COinS = 'rft.series' },
series2 = { 'Serie2', 'Serie 2', 'Reihe2', 'Reihe 2', types = { 'book', 'collection', 'map' } },
series3 = { 'Serie3', 'Serie 3', 'Reihe3', 'Reihe 3', types = { 'book', 'collection', 'map' } },
isbn = { 'ISBN', types = { 'book', 'collection', 'map', 'journal' }, COinS = 'rft.isbn' },
dnb = { 'DNB', types = { 'book', 'collection', 'map' } },
oclc = { 'OCLC', types = { 'book', 'collection', 'map' }, COinS_id = 'info:oclcnum' },
issn = { 'ISSN', types = { 'journal', 'newspaper' }, COinS = 'rft.issn' },
doi = { 'DOI', COinS_id = 'info:doi' },
language = { 'Sprache' },
comment = { 'Kommentar' },
noError = { 'noError', 'noerror', 'keinFefler', 'kein Fehler' }
}
local formatters = {
auAuthor = '%s: ',
auEditor = '%s (Hrsg.)',
auAuthorEditor = '%s ; %s',
tiTitle = "''%s''. ",
tiVolume = '%s; Bd. %s',
tiScale = 'Maßstab: %s. ',
tiIn = 'In: ',
puAll = '%s.',
puPlaceDate = '%s, %s',
puPlacePub = '%s: %s',
puDateEdition = '%s (%d. Auflage)',
addSeries = '(%s)',
addPages = 'S. %s',
addColumns = 'Sp. %s',
addDelimiter1 = ', ',
addDelimiter2 = '; ',
addDoi = '<abbr title="Digital Object Identifier">doi</abbr>:%s',
addLanguage = ' (%s)',
addComment = ' %s',
dbDnb = '<abbr title="Deutsche Nationalbibliothek">DNB</abbr> [http://d-nb.info/%s %s]',
dbOclc = '<abbr title="Online Computer Library Center (WorldCat)">OCLC</abbr> [https://worldcat.org/oclc/%s %s]',
}
local texts = {
noTitel = '<span class="error">Fehlender Titel</span>',
unknownParam = '<span class="error">Fehlerhafter Parameter: %s</span>[[Category:Literatur: fehlerhafte Parameter]] ',
unknownParams = '<span class="error">Fehlerhafte Parameter: %s</span>[[Category:Literatur: fehlerhafte Parameter]] ',
unknownTitle = '[[Category:Literatur: fehlender Titel]]',
}
local errorMsgs = {}
-- check if table contains the value
local function inArray( tab, val )
if type( tab ) == 'string' then
return tab == val
end
local index, value
for index, value in ipairs( tab ) do
if value == val then
return true
end
end
return false
end
local function cleanupParameters( value )
if not value or value == '' then
return value
end
value = value:gsub( '[\009\010\013]', ' ' ) -- horizontal tab, line feed, carriage return
value = value:gsub( '[%z%c]', '' ) -- control characters
value = value:gsub( ' ', ' ' );
value = value:gsub( '\226\128\138', ' ' ); -- hair space
value = mw.ustring.gsub( value, '[\226\128\141\226\128\139\194\173]', '' ); -- zero-width joiner, zero-width space, soft hyphen
value = mw.ustring.gsub( value, '<br%s*/*>', '' )
value = mw.ustring.gsub( value, '</*p%s*/*>', '' )
return mw.ustring.gsub( value, '</*span%s*/*>', '' )
end
-- check for possible arguments against params table
local function checkParams( frameArgs )
local args = {}, key, key2, ok, value, value2
local complete = {}
local wrongParams = {}
for key, value in pairs( params ) do
if not value.internal then
if type( value ) == 'table' then
for key2, value2 in ipairs( value ) do
complete[ value2 ] = key
args[ key ] = args[ key ] or
cleanupParameters( frameArgs[ value2 ] )
end
args[ key ] = args[ key ] or ''
else
complete[ key ] = key
args[ key ] = cleanupParameters( frameArgs[ key ] ) or ''
end
end
end
for key, value in pairs( frameArgs ) do
if not complete[ key ] then
table.insert( wrongParams, key )
end
end
if #wrongParams == 1 then
table.insert( errorMsgs,
mw.ustring.format( texts.unknownParam, table.concat( wrongParams, ', ' ) ) )
elseif #wrongParams > 0 then
table.insert( errorMsgs,
mw.ustring.format( texts.unknownParams, table.concat( wrongParams, ', ' ) ) )
end
return args
end
local function makeAuthor( author, editor )
if editor ~= '' then
editor = mw.ustring.format( formatters.auEditor, editor )
end
if author ~= '' and editor ~= '' then
author = mw.ustring.format( formatters.auAuthorEditor, author, editor )
end
if author ~= '' then
return mw.ustring.format( formatters.auAuthor, author )
else
return ''
end
end
local function makeTitle( title, volume, url, scale )
if url and url ~= '' then
title = '[' .. url .. ' ' .. title .. ']'
end
if volume and volume ~= '' then
title = mw.ustring.format( formatters.tiVolume, title, volume )
end
title = mw.ustring.format( formatters.tiTitle, title )
if scale and scale ~= '' then
title = title .. mw.ustring.format( formatters.tiScale, scale )
end
return title
end
local function makeDoiLink( doi )
doi = mw.ustring.gsub( doi, 'https?://doi.org/', '' )
return '[' .. mw.uri.encode( 'https://doi.org/' .. doi )
.. '<nowiki>' .. doi .. '</nowiki>]'
end
local function makePublished( args )
args.edition = tonumber( args.edition )
args.noError = yn( args.noError, false )
if args.noError then
args.noError = 'true'
else
args.noError = 'false'
end
if args.date ~= '' and args.edition then
args.date = mw.ustring.format( formatters.puDateEdition, args.date, args.edition )
end
if args.place ~= '' and args.publisher ~= '' then
args.place = mw.ustring.format( formatters.puPlacePub, args.place, args.publisher )
end
if args.place == '' then
args.place = args.date
args.date = ''
end
if args.place ~= '' and args.date ~= '' then
args.place = mw.ustring.format( formatters.puPlaceDate, args.place, args.date )
end
local additions = { args.place }
if args.series ~= '' then
table.insert( additions, mw.ustring.format( formatters.addSeries, args.series ) )
end
if args.series2 ~= '' then
table.insert( additions, mw.ustring.format( formatters.addSeries, args.series2 ) )
end
if args.series3 ~= '' then
table.insert( additions, mw.ustring.format( formatters.addSeries, args.series3 ) )
end
if args.isbn ~= '' then
table.insert( additions,
li._linkISBNSet( { isbn = args.isbn, noerror = args.noError } ) )
elseif args.dnb ~= '' then
table.insert( additions, mw.ustring.format( formatters.dbDnb, args.dnb, args.dnb ) )
elseif args.oclc ~= '' then
table.insert( additions, mw.ustring.format( formatters.dbOclc, args.oclc, args.oclc ) )
end
if args.pages ~= '' then
table.insert( additions,
mw.ustring.format( formatters.addPages, args.pages:gsub( '-', '–' ) ) )
end
if args.columns ~= '' then
table.insert( additions,
mw.ustring.format( formatters.addColumns, args.columns:gsub( '-', '–' ) ) )
end
additions = { table.concat( additions, formatters.addDelimiter1 ) }
if args.extent ~= '' then
table.insert( additions, args.extent )
end
if args.doi ~= '' then
table.insert( additions,
mw.ustring.format( formatters.addDoi, makeDoiLink( args.doi ) ) )
end
additions = table.concat( additions, formatters.addDelimiter2 )
if args.language ~= '' then
additions = additions .. mw.ustring.format( formatters.addLanguage, args.language )
end
if additions ~= '' then
additions = mw.ustring.format( formatters.puAll, additions )
end
if args.comment ~= '' then
additions = additions .. mw.ustring.format( formatters.addComment, args.comment )
end
return additions
end
local function makeBook( args )
if args.type ~= 'map' then
args.scale = ''
end
local author, title
if args.type == 'map' or args.type == 'book' then
author = makeAuthor( args.author, args.editor )
title = makeTitle( args.title, args.volume, args.url, args.scale )
else
author = makeAuthor( '', args.editor )
title = makeTitle( args.collection, args.volume, args.url, args.scale )
end
return author .. title .. makePublished( args )
end
local function makeCollection( args )
local author, title
author = makeAuthor( args.author, '' )
title = makeTitle( args.title, args.volume, args.articleUrl, '' )
args.author = ''
args.title = args.collection
return author .. title .. formatters.tiIn .. makeBook( args )
end
local function getPageNumbers( pages )
pages = ( '' .. pages ):gsub( '–', '-' ); -- replace endashes with hyphens
return pages:gsub( '&%w+;', '-' ); -- replace html entities with hyphens
end
local function makeCOinS( args )
local rft = {}, key, value
for key, value in pairs( params ) do
if value.COinS and value.COinS:find( 'rft.' ) and args[ key ] and args[ key ] ~= '' then
table.insert( rft, value.COinS .. '=' .. mw.uri.encode( args[ key ] ) )
end
end
if next( rft ) then
if args.type == 'book' or args.type == 'map' or args.type == 'collection' then
table.insert( rft, 1, 'rft.genre=book' )
table.insert( rft, 1, 'rft.rft_val_fmt=' .. mw.uri.encode( 'info:ofi/fmt:kev:mtx:book' ) )
if args.type == 'collection' then
table.insert( rft, 'rft.atitle=' .. mw.uri.encode( args.title ) )
table.insert( rft, 'rft.btitle=' .. mw.uri.encode( args.collection ) )
else
table.insert( rft, 'rft.btitle=' .. mw.uri.encode( args.title ) )
end
else
table.insert( rft, 1, 'rft.genre=journal' )
table.insert( rft, 1, 'rft.rft_val_fmt=info:ofi/fmt:kev:mtx:journal' )
if args.type == 'journal' then
table.insert( rft, 'rft.jtitle=' .. mw.uri.encode( args.journal ) )
else
table.insert( rft, 'rft.jtitle=' .. mw.uri.encode( args.newspaper ) )
end
table.insert( rft, 'rft.atitle=' .. mw.uri.encode( args.title ) )
end
table.insert( rft, 1, 'ctx_ver=Z39.88-2004' )
rft = table.concat( rft, '&' )
return '<span class="Z3988" title="' .. rft .. '"></span>'
end
end
local function makeCitation( frameArgs, checkit )
local args, citation
if checkit then
args = checkParams( frameArgs )
else
args = frameArgs
end
if args.title == '' then
args.title = texts.noTitle
table.insert( errorMsgs, texts.unknownTitle )
end
args.pages = getPageNumbers( args.pages )
args.columns = getPageNumbers( args.columns )
if args.type == 'map' or args.type == 'book' then
citation = makeBook( args )
elseif args.type == 'collection' then
citation = makeCollection( args )
end
return table.concat( errorMsgs, '' )
.. '<cite class="citation ' .. args.type .. '">'
.. citation .. '</cite>' .. makeCOinS( args )
end
function ci.book( frame )
local args = frame:getParent().args, ok
-- local args = frame
args.type = 'book'
return makeCitation( args, true )
end
function ci.map( frame )
local args = frame:getParent().args
args.type = 'map'
return makeCitation( args, true )
end
function ci.collection( frame )
local args = frame:getParent().args
-- local args = frame
args.type = 'collection'
return makeCitation( args, true )
end
function ci.journal( frame )
local args = frame:getParent().args
args.type = 'journal'
return makeCitation( args, true )
end
function ci.newspaper( frame )
local args = frame:getParent().args
args.type = 'newspaper'
return makeCitation( args, true )
end
function ci.citation( frame )
local args = frame:getParent().args
args = checkParams( args )
if args.type == '' then
if args.scale ~= '' then
args.type = 'map'
elseif args.collection ~= '' then
args.type = 'collection'
elseif args.journal ~= '' then
args.type = 'journal'
elseif args.newspaper ~= '' then
args.type = 'newspaper'
elseif args.editor ~= '' then
args.type = 'collection'
else
args.type = 'book'
end
end
return makeCitation( args, false )
end
return ci