Modul:Citation/COinS: Unterschied zwischen den Versionen

Aus skandinavien-wiki.net
Keine Bearbeitungszusammenfassung
K (43 Versionen von wikivoyage:Modul:Citation/COinS importiert)
 
(38 dazwischenliegende Versionen von einem anderen Benutzer werden nicht angezeigt)
Zeile 1: Zeile 1:
-- documentation
-- documentation
local citation = {
local citationCOinS = {
suite  = 'Citation',
suite  = 'Citation',
sub    = 'COinS',  
sub    = 'COinS',  
serial = '2020-03-27',
serial = '2022-10-21'
}
}


-- module variable
-- module variable and administration
local cc = {}
local cc = {
moduleInterface = citationCOinS
}


-- module import
-- module import
-- require( 'strict' )
local ci = require( 'Module:Citation/i18n' )
local cu = require( 'Module:Citation/utilities' )
local cu = require( 'Module:Citation/utilities' )


function cc.prepareForCOinS( args )
function cc.prepareForCOinS( args )
local key, value
local function pagesMatch( s )
local function pagesMatch( s )
if not cu.isSet( s ) then
if not cu.isSet( s ) then
Zeile 20: Zeile 22:
end
end


s = s:match( '%d+%s*%-%s*%d+' ) or s:match( '%d+' ) or
s = s:match( '%a*%d+%s*%-%s*%a*%d+' ) or s:match( '%a*%d+' ) or
-- Roman numerals
-- Roman numerals
s:match( '[Cc]*[LlXxVvIi]+%s*%-%s*[Cc]*[LlXxVvIi]+' ) or
s:match( '[Cc]*[LlXxVvIi]+%s*%-%s*[Cc]*[LlXxVvIi]+' ) or
Zeile 37: Zeile 39:
end
end
if s == '' then
if s == '' then
cu.addErrorMsg( texts.wrongPages )
cu.addErrorMsg( ci.texts.wrongPages )
end
end
return s
return s
Zeile 43: Zeile 45:


for key, value in pairs( args ) do
for key, value in pairs( args ) do
args[ key ] = mw.ustring.gsub( args[ key ], ' ', ' ' )
if ci.params[ key ] then
args[ key ] = mw.ustring.gsub( args[ key ], '&%w+;', '' ) -- remove entities
args[ key ] = cu.coinsCleanup( args[ key ] )  
end
end
end


Zeile 52: Zeile 55:
args.pages = args.columns
args.pages = args.columns
end
end
args.extent = args.extent:match( '%d+' )


-- only first author
-- only first author
args.author = cu.getFirst( args.author or '', ';' )
args.author = cu.getFirst( args.author or '', ';' )
local count
local s, count
_,count = args.author:gsub( ',', ',' )
s, count = args.author:gsub( ',', ',' )
if count > 1 then
if count > 1 then
args.author = cu.getFirst( args.author, ',' )
args.author = cu.getFirst( args.author, ',' )
Zeile 66: Zeile 70:
args.isbn = cu.getFirst( args.isbn or '', ',' )
args.isbn = cu.getFirst( args.isbn or '', ',' )
args.isbn = args.isbn:match( '[%d%-Xx]+' )
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
end


function cc.makeCOinS( args, params )
function cc.makeCOinS( args )
local rft = {}, key, value
local rft = {}


local function insertCOinS( key, value )
local function insertCOinS( key, value )
if cu.isSet( value ) then
if cu.isSet( value ) then
table.insert( rft, key .. '=' .. mw.uri.encode( '' .. value ) )
table.insert( rft, key .. '=' .. mw.uri.encode( '' .. value, 'PATH' ) )
end
end
end
end
-- make COinS (ContextObjects in Spans, OpenURL) format
-- https://groups.niso.org/apps/group_public/download.php/14833/z39_88_2004_r2010.pdf
-- https://www.oclc.org/developer/develop/web-services/worldcat-knowledge-base-api/openurl-resource.en.html


-- handle titles
-- handle titles
if args.type == 'book' or args.type == 'map' or args.type == 'collection' then
-- maps handled like books
table.insert( rft, 'rft_val_fmt=' .. mw.uri.encode( 'info:ofi/fmt:kev:mtx:book' ) )
if args.type == 'book' or args.type == 'map' or args.type == 'bookitem' then
insertCOinS( 'rft.title', args.title )
table.insert( rft, 'rft_val_fmt='
if args.type == 'collection' then
.. mw.uri.encode( 'info:ofi/fmt:kev:mtx:book', 'PATH' ) )
if args.type == 'bookitem' then
table.insert( rft, 'rft.genre=bookitem' )
table.insert( rft, 'rft.genre=bookitem' )
insertCOinS( 'rft.atitle', args.title )
insertCOinS( 'rft.atitle', args.title )
Zeile 93: Zeile 98:
insertCOinS( 'rft.btitle', args.title )
insertCOinS( 'rft.btitle', args.title )
end
end
-- newspaper is now handled like a journal to improve data import
elseif args.type == 'journal' or args.type == 'newspaper' then
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_val_fmt='
table.insert( rft, 'rft.genre=journal' )
.. mw.uri.encode( 'info:ofi/fmt:kev:mtx:journal', 'PATH' ) )
insertCOinS( 'rft.title', args.title )
table.insert( rft, 'rft.genre=article' )
insertCOinS( 'rft.atitle', args.title )
insertCOinS( 'rft.atitle', args.title )
if args.type == 'journal' then
insertCOinS( 'rft.jtitle', args.type == 'journal' and args.journal or args.newspaper )
insertCOinS( 'rft.jtitle', args.journal )
 
else
-- handle web
insertCOinS( 'rft.jtitle', args.newspaper )
-- DCMI: Dublin Core™ Metadata
end
-- https://www.dublincore.org/specifications/dublin-core/dces/
-- else -- 'newspaper'
else
-- table.insert( rft, 'rft_val_fmt=' .. mw.uri.encode( 'info:ofi/fmt:kev:mtx:dc' ) )
table.insert( rft, 'rft_val_fmt='
-- insertCOinS( 'rft.type', 'newspaperArticle' )
.. mw.uri.encode( 'info:ofi/fmt:kev:mtx:dc', 'PATH' ) )
-- 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.type', 'webpage' )
insertCOinS( 'rft.creator', args.author )
insertCOinS( 'rft.title', args.title )
insertCOinS( 'rft.title', args.title )
insertCOinS( 'rft.source', args.website )
insertCOinS( 'rft.source', args.website )
Zeile 121: Zeile 122:


if #rft > 2 then
if #rft > 2 then
for key, value in pairs( params ) do
local prefix
if cu.isSet( args[ key ] ) then
local rftUrl = ( cu.isSet( args.url ) and not args.url:find( 'doi.org/', 1, true ) )
if value.COinS and value.COinS ~= 'rft.jtitle' and value.COinS ~= 'rft.title' then
and args.url or ''
insertCOinS( value.COinS, args[ key ] )
for key, value in pairs( ci.params ) do
elseif value.COinS_id and args[ key ] then
if cu.isSet( args[ key ] ) and value.COinS then
table.insert( rft, 'rft_id=' ..
if key == 'date' and args.dateFormat == 'R' then
mw.uri.encode( value.COinS_id .. '/' .. args[ key ] ) )
insertCOinS( value.COinS, string.sub( args[ key ], 1, 4 ) )
elseif value.COinS ~= 'rft.jtitle' and value.COinS ~= 'rft.title' then
prefix = value.COinS:sub( 1, 3 )
if prefix == 'rft' then
insertCOinS( value.COinS, args[ key ] )
elseif prefix == 'inf' then
table.insert( rft, 'rft_id=' ..
mw.uri.encode( value.COinS .. '/' .. args[ key ], 'PATH' ) )
elseif prefix == 'url' and rftUrl == '' then
rftUrl = value.url:format( args[ key ] )
elseif prefix == 'jst' then
if not cu.isSet( args.doi ) then
table.insert( rft, 'rft_id=' ..
mw.uri.encode( 'info:doi/' .. value.doi:format( args[ key ] ), 'PATH' ) )
end
if rftUrl == '' then
rftUrl = value.url:format( args[ key ] )
end
end
end
end
end
end
end
if rftUrl ~= '' then
if rftUrl:match( '^//' ) then
rftUrl = 'https:' .. rftUrl
end
table.insert( rft, 'rft_id=' .. mw.uri.encode( rftUrl, 'PATH' ) )
end
end


table.insert( rft, 1, 'rfr_id='
.. mw.uri.encode( 'info/sid:/' .. ci.project.name, 'PATH' ) )
table.insert( rft, 1, 'ctx_ver=Z39.88-2004' )
table.insert( rft, 1, 'ctx_ver=Z39.88-2004' )
rft = table.concat( rft, '&' )
return tostring( mw.html.create( 'span' )
return '<span title="' .. rft .. '" class="Z3988"></span>'
:addClass( 'Z3988' )
:attr( 'title', table.concat( rft, '&' ) )
)
end
end
return ''
return ''

Aktuelle Version vom 11. Februar 2023, 20:58 Uhr

Die Dokumentation für dieses Modul kann unter Modul:Citation/COinS/doc erstellt werden

-- documentation
local citationCOinS = {
	suite  = 'Citation',
	sub    = 'COinS', 
	serial = '2022-10-21'
}

-- module variable and administration
local cc = {
	moduleInterface = citationCOinS
}

-- module import
-- require( 'strict' )
local ci = require( 'Module:Citation/i18n' )
local cu = require( 'Module:Citation/utilities' )

function cc.prepareForCOinS( args )
	local function pagesMatch( s )
		if not cu.isSet( s ) then
			return ''
		end

		s = s:match( '%a*%d+%s*%-%s*%a*%d+' ) or s:match( '%a*%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( ci.texts.wrongPages )
		end
		return s
	end

	for key, value in pairs( args ) do
		if ci.params[ key ] then
			args[ key ] = cu.coinsCleanup( args[ key ] ) 
		end
	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
	args.extent = args.extent:match( '%d+' )

	-- only first author
	args.author = cu.getFirst( args.author or '', ';' )
	local s, count
	s, 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]+' )
end

function cc.makeCOinS( args )
	local rft = {}

	local function insertCOinS( key, value )
		if cu.isSet( value ) then
			table.insert( rft, key .. '=' .. mw.uri.encode( '' .. value, 'PATH' ) )
		end
	end

	-- make COinS (ContextObjects in Spans, OpenURL) format
	-- https://groups.niso.org/apps/group_public/download.php/14833/z39_88_2004_r2010.pdf
	-- https://www.oclc.org/developer/develop/web-services/worldcat-knowledge-base-api/openurl-resource.en.html

	-- handle titles
	-- maps handled like books
	if args.type == 'book' or args.type == 'map' or args.type == 'bookitem' then
		table.insert( rft, 'rft_val_fmt='
			.. mw.uri.encode( 'info:ofi/fmt:kev:mtx:book', 'PATH' ) )
		if args.type == 'bookitem' 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

	-- newspaper is now handled like a journal to improve data import
	elseif args.type == 'journal' or args.type == 'newspaper' then
		table.insert( rft, 'rft_val_fmt='
			.. mw.uri.encode( 'info:ofi/fmt:kev:mtx:journal', 'PATH' ) )
		table.insert( rft, 'rft.genre=article' )
		insertCOinS( 'rft.atitle', args.title )
		insertCOinS( 'rft.jtitle', args.type == 'journal' and args.journal or args.newspaper )

	-- handle web
	-- DCMI: Dublin Core™ Metadata
	-- https://www.dublincore.org/specifications/dublin-core/dces/
	else
		table.insert( rft, 'rft_val_fmt='
			.. mw.uri.encode( 'info:ofi/fmt:kev:mtx:dc', 'PATH' ) )
		insertCOinS( 'rft.type', 'webpage' )
		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
		local prefix
		local rftUrl = ( cu.isSet( args.url ) and not args.url:find( 'doi.org/', 1, true ) )
			and args.url or ''
		for key, value in pairs( ci.params ) do
			if cu.isSet( args[ key ] ) and value.COinS then
				if key == 'date' and args.dateFormat == 'R' then
					insertCOinS( value.COinS, string.sub( args[ key ], 1, 4 ) )
				elseif value.COinS ~= 'rft.jtitle' and value.COinS ~= 'rft.title' then
					prefix = value.COinS:sub( 1, 3 )
					if prefix == 'rft' then
						insertCOinS( value.COinS, args[ key ] )
					elseif prefix == 'inf' then
						table.insert( rft, 'rft_id=' ..
							mw.uri.encode( value.COinS .. '/' .. args[ key ], 'PATH' ) )
					elseif prefix == 'url' and rftUrl == '' then
						rftUrl = value.url:format( args[ key ] )
					elseif prefix == 'jst' then
						if not cu.isSet( args.doi ) then
							table.insert( rft, 'rft_id=' ..
								mw.uri.encode( 'info:doi/' .. value.doi:format( args[ key ] ), 'PATH' ) )
						end
						if rftUrl == '' then
							rftUrl = value.url:format( args[ key ] )
						end
					end
				end
			end
		end
		if rftUrl ~= '' then
			if rftUrl:match( '^//' ) then
				rftUrl = 'https:' .. rftUrl
			end
			table.insert( rft, 'rft_id=' .. mw.uri.encode( rftUrl, 'PATH' ) )
		end

		table.insert( rft, 1, 'rfr_id='
			.. mw.uri.encode( 'info/sid:/' .. ci.project.name, 'PATH' ) )
		table.insert( rft, 1, 'ctx_ver=Z39.88-2004' )
		return tostring( mw.html.create( 'span' )
			:addClass( 'Z3988' )
			:attr( 'title', table.concat( rft, '&' ) )
		)
	end
	return ''
end

return cc