Modul:Citation/COinS
Die Dokumentation für dieses Modul kann unter Modul:Citation/COinS/doc erstellt werden
-- documentation
local citation = {
suite = 'Citation',
sub = 'COinS',
serial = '2020-03-27',
}
-- module variable
local cc = {}
-- module import
local cu = require( 'Module:Citation/utilities' )
function cc.prepareForCOinS( args )
local key, value
local function pagesMatch( s )
if not cu.isSet( s ) then
return ''
end
s = s:match( '%d+%s*%-%s*%d+' ) or s:match( '%d+' ) or
-- Roman numerals
s:match( '[Cc]*[LlXxVvIi]+%s*%-%s*[Cc]*[LlXxVvIi]+' ) or
s:match( '[Cc]*[LlXxVvIi]+' ) or ''
s = s:gsub( ' ', '' )
if s ~= '' and not s:match( '%d+' ) then -- Roman numerals
local tab = mw.text.split( s, '-', true )
for key, value in ipairs( tab ) do
if value == '' or
not value:match( '^[Cc]*[Xx]?[Ll]?[Xx]*[Ii]?[Vv]?[Ii]*$' ) then
s = ''
break
end
end
end
if s == '' then
cu.addErrorMsg( texts.wrongPages )
end
return s
end
args.isArchived = nil
for key, value in pairs( args ) do
args[ key ] = mw.ustring.gsub( args[ key ], ' ', ' ' )
args[ key ] = mw.ustring.gsub( args[ key ], '&%w+;', '' ) -- remove entities
end
args.pages = pagesMatch( args.pages )
args.columns = pagesMatch( args.columns )
if cu.isSet( args.columns ) and not cu.isSet( args.pages ) then
args.pages = args.columns
end
-- only first author
args.author = cu.getFirst( args.author or '', ';' )
local count
_,count = args.author:gsub( ',', ',' )
if count > 1 then
args.author = cu.getFirst( args.author, ',' )
end
for key, value in ipairs( { 'author', 'editor' } ) do
args[ value ] = mw.ustring.gsub( args[ value ], '[%[%]!#$%%%*%+%?]', '' )
end
args.isbn = cu.getFirst( args.isbn or '', ',' )
args.isbn = args.isbn:match( '[%d%-Xx]+' )
if not cu.isSet( args.issn ) and cu.isSet( args.eissn ) then
args.issn = args.eissn
end
end
function cc.makeCOinS( args, params )
local rft = {}, key, value
local function insertCOinS( key, value )
if cu.isSet( value ) then
table.insert( rft, key .. '=' .. mw.uri.encode( '' .. value ) )
end
end
-- handle titles
if args.type == 'book' or args.type == 'map' or args.type == 'collection' then
table.insert( rft, 'rft_val_fmt=' .. mw.uri.encode( 'info:ofi/fmt:kev:mtx:book' ) )
insertCOinS( 'rft.title', args.title )
if args.type == 'collection' then
table.insert( rft, 'rft.genre=bookitem' )
insertCOinS( 'rft.atitle', args.title )
insertCOinS( 'rft.btitle', args.collection )
else
table.insert( rft, 'rft.genre=book' )
insertCOinS( 'rft.btitle', args.title )
end
elseif args.type == 'journal' or args.type == 'newspaper' then
table.insert( rft, 'rft_val_fmt=' .. mw.uri.encode( 'info:ofi/fmt:kev:mtx:journal' ) )
table.insert( rft, 'rft.genre=journal' )
insertCOinS( 'rft.title', args.title )
insertCOinS( 'rft.atitle', args.title )
if args.type == 'journal' then
insertCOinS( 'rft.jtitle', args.journal )
else
insertCOinS( 'rft.jtitle', args.newspaper )
end
-- else -- 'newspaper'
-- table.insert( rft, 'rft_val_fmt=' .. mw.uri.encode( 'info:ofi/fmt:kev:mtx:dc' ) )
-- insertCOinS( 'rft.type', 'newspaperArticle' )
-- insertCOinS( 'rft.title', args.title )
-- insertCOinS( 'rft.atitle', args.title )
-- insertCOinS( 'rft.source', args.newspaper )
else -- web
table.insert( rft, 'rft_val_fmt=' .. mw.uri.encode( 'info:ofi/fmt:kev:mtx:dc' ) )
insertCOinS( 'rft.type', 'webpage' )
insertCOinS( 'rft.creator', args.author )
insertCOinS( 'rft.title', args.title )
insertCOinS( 'rft.source', args.website )
insertCOinS( 'rft.identifier', args.url )
insertCOinS( 'rft.description', args.comment )
insertCOinS( 'rft.format', args.format )
end
if #rft > 2 then
for key, value in pairs( params ) do
if cu.isSet( args[ key ] ) then
if value.COinS and value.COinS ~= 'rft.jtitle' and value.COinS ~= 'rft.title' then
insertCOinS( value.COinS, args[ key ] )
elseif value.COinS_id and args[ key ] then
table.insert( rft, 'rft_id=' ..
mw.uri.encode( value.COinS_id .. '/' .. args[ key ] ) )
end
end
end
table.insert( rft, 1, 'ctx_ver=Z39.88-2004' )
rft = table.concat( rft, '&' )
return '<span title="' .. rft .. '" class="Z3988"></span>'
end
return ''
end
return cc