Zum Inhalt springen

Modul:Citation: Unterschied zwischen den Versionen

Umstellungen
Keine Bearbeitungszusammenfassung
(Umstellungen)
Zeile 2: Zeile 2:
local scrollGallery = {
local scrollGallery = {
suite  = 'Citation',
suite  = 'Citation',
serial = '2020-03-21',
serial = '2020-03-22',
}
}


-- module import
-- module import
local li = require( 'Module:LinkISBN' )
local li = require( 'Module:LinkISBN' )
local uc = require( 'Module:UrlCheck' )
local yn = require( 'Module:Yesno' )
local yn = require( 'Module:Yesno' )


-- module variable
-- module variable
local ci = {}
local ci = {}
local types = {
book      = { 'book', 'Buch' },
map        = { 'map', 'Karte' },
collection = { 'collection', 'Sammelwerk' },
journal    = { 'journal', 'Zeitschrift' },
newspaper  = { 'newspaper', 'Zeitung' }
}


local params = {
local params = {
type      = { 'type', 'Typ' },
author    = { 'Autor', COinS = 'rft.au' },
author    = { 'Autor', COinS = 'rft.au' },
editor    = { 'Herausgeber' },
editor    = { 'Herausgeber' },
title      = { 'Titel', COinS = 'rft.title' },
title      = { 'Titel', COinS = 'rft.title' },
chapter    = { 'Kapitel', types = 'book', COinS = 'rft.atitle' },
chapter    = { 'Kapitel', types = 'book', COinS = 'rft.atitle' },
type      = { 'type', 'Typ' },
genre      = { 'Genre', COinS = 'rft.genre', internal = true },
collection = { 'Sammelwerk', types = 'collection' },
collection = { 'Sammelwerk', types = 'collection' },
journal    = { 'Zeitschrift', types = 'journal', COinS = 'rft.jtitle' },
journal    = { 'Zeitschrift', types = 'journal', COinS = 'rft.jtitle' },
Zeile 39: Zeile 47:
extent    = { 'Umfang', 'Seitenanzahl', types = { 'book', 'collection', 'map' } },
extent    = { 'Umfang', 'Seitenanzahl', types = { 'book', 'collection', 'map' } },
series    = { 'Serie', 'Reihe', types = { 'book', 'collection', 'map' }, COinS = 'rft.series' },
series    = { 'Serie', 'Reihe', types = { 'book', 'collection', 'map' }, COinS = 'rft.series' },
series2    = { 'Serie2', 'Serie 2', 'Reihe2', 'Reihe 2', types = { 'book', 'collection', 'map' } },
series2    = { 'Serie2', 'Reihe2', types = { 'book', 'collection', 'map' } },
series3    = { 'Serie3', 'Serie 3', 'Reihe3', 'Reihe 3', types = { 'book', 'collection', 'map' } },
series3    = { 'Serie3', 'Reihe3', types = { 'book', 'collection', 'map' } },
isbn      = { 'ISBN', types = { 'book', 'collection', 'map', 'journal' }, COinS = 'rft.isbn' },
isbn      = { 'ISBN', types = { 'book', 'collection', 'map', 'journal' }, COinS = 'rft.isbn' },
dnb        = { 'DNB', types = { 'book', 'collection', 'map' } },
dnb        = { 'DNB', types = { 'book', 'collection', 'map' } },
Zeile 55: Zeile 63:
auEditor = '%s (Hrsg.)',
auEditor = '%s (Hrsg.)',
auAuthorEditor = '%s ; %s',
auAuthorEditor = '%s ; %s',
tiTitle = "''%s''. ",
tiAll = "%s. ",
tiVolume = '%s; Bd. %s',
tiTitle = "''%s''",
tiVolume = "''%s''; Bd. %s",
tiScale = 'Maßstab: %s. ',
tiScale = 'Maßstab: %s. ',
tiIn = 'In: ',
tiIn = 'In: ',
Zeile 77: Zeile 86:
local texts = {
local texts = {
noTitel      = '<span class="error">Fehlender Titel</span>',
noTitel      = '<span class="error">Fehlender Titel</span>',
noURL        = '<span class="error">Fehlerhafte URL</span>[[Category:Literatur: Fehlerhafte URL]] ',
unknownParam  = '<span class="error">Fehlerhafter Parameter: %s</span>[[Category:Literatur: fehlerhafte Parameter]] ',
unknownParam  = '<span class="error">Fehlerhafter Parameter: %s</span>[[Category:Literatur: fehlerhafte Parameter]] ',
unknownParams = '<span class="error">Fehlerhafte Parameter: %s</span>[[Category:Literatur: fehlerhafte Parameter]] ',
unknownParams = '<span class="error">Fehlerhafte Parameter: %s</span>[[Category:Literatur: fehlerhafte Parameter]] ',
unknownTitle  = '[[Category:Literatur: fehlender Titel]]',
unknownTitle  = '[[Category:Literatur: fehlender Titel]]',
wrongType    = '<span class="error">Fehlerhafter Typ</span>[[Category:Literatur: fehlerhafter Typ]] '
}
}


Zeile 98: Zeile 109:


return false
return false
end
-- returns a single value from frame argument table
local function getArgValue( param, args )
value = '', k, v
if params[ param ] then
for k, v in ipairs( params[ param ] ) do
if args[ v ] and args[ v ] ~= '' then
value = args[ v ]
break
end
end
end
return value
end
end


Zeile 119: Zeile 144:
local complete = {}
local complete = {}
local wrongParams = {}
local wrongParams = {}
local aType = getArgValue( 'type', frameArgs )
-- convert type values if translated
for key, value in pairs( types ) do
if inArray( value, aType ) then
aType = key
break
end
end


for key, value in pairs( params ) do
for key, value in pairs( params ) do
if not value.internal then
if not value.types or inArray( value.types, aType ) 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
args[ key ] = args[ key ] or
cleanupParameters( frameArgs[ value2 ] )
cleanupParameters( frameArgs[ value2 ] )
end
args[ key ] = args[ key ] or ''
else
complete[ key ] = key
args[ key ] = cleanupParameters(  frameArgs[ key ] ) or ''
end
end
args[ key ] = args[ key ] or ''
end
end
end
end
Zeile 157: Zeile 185:
if author ~= '' and editor ~= '' then
if author ~= '' and editor ~= '' then
author = mw.ustring.format( formatters.auAuthorEditor, author, editor )
author = mw.ustring.format( formatters.auAuthorEditor, author, editor )
elseif author == '' and editor ~= '' then
author = editor
end
end
if author ~= '' then
if author ~= '' then
Zeile 166: Zeile 196:


local function makeTitle( title, volume, url, scale )
local function makeTitle( title, volume, url, scale )
if title == '' then
title = texts.noTitle
table.insert( errorMsgs, texts.unknownTitle )
end
if url and url ~= '' then
if url and url ~= '' then
title = '[' .. url .. ' ' .. title .. ']'
if uc.isUrl( url ) > 2 then
table.insert( errorMsgs, texts.noURL )
else
title = '[' .. url .. ' ' .. title .. ']'
end
end
end
if volume and volume ~= '' then
if volume and volume ~= '' then
title = mw.ustring.format( formatters.tiVolume, title, volume )
title = mw.ustring.format( formatters.tiVolume, title, volume )
else
title = mw.ustring.format( formatters.tiTitle, title, volume )
end
end
title = mw.ustring.format( formatters.tiTitle, title )
title = mw.ustring.format( formatters.tiAll, title )
if scale and scale ~= '' then
if scale and scale ~= '' then
title = title .. mw.ustring.format( formatters.tiScale, scale )
title = title .. mw.ustring.format( formatters.tiScale, scale )
Zeile 224: Zeile 264:
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
elseif args.dnb ~= '' and tonumber( args.dnb ) then
table.insert( additions, mw.ustring.format( formatters.dbDnb, args.dnb, args.dnb ) )
table.insert( additions, mw.ustring.format( formatters.dbDnb, args.dnb, args.dnb ) )
elseif args.oclc ~= '' then
elseif args.oclc ~= '' and tonumber( args.oclc ) then
table.insert( additions, mw.ustring.format( formatters.dbOclc, args.oclc, args.oclc ) )
table.insert( additions, mw.ustring.format( formatters.dbOclc, args.oclc, args.oclc ) )
end
end
Zeile 287: Zeile 327:
return author .. title .. formatters.tiIn .. editor .. collection
return author .. title .. formatters.tiIn .. editor .. collection
.. makePublished( args )
.. makePublished( args )
end
local function makeJournal( args )
end
local function makeNewspaper( args )
end
end


local function getPageNumbers( pages )
local function getPageNumbers( pages )
if not pages then
return ''
end
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
Zeile 330: Zeile 379:
end
end


local function makeCitation( frameArgs, checkit )
local function makeCitation( frameArgs )
local args, citation
local args, citation
if checkit then
args = checkParams( frameArgs )
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.pages = getPageNumbers( args.pages )
args.columns = getPageNumbers( args.columns )
args.columns = getPageNumbers( args.columns )
Zeile 348: Zeile 389:
elseif args.type == 'collection' then
elseif args.type == 'collection' then
citation = makeCollection( args )
citation = makeCollection( args )
elseif args.type == 'journal' then
citation = makeJournal( args )
elseif args.type == 'newspaper' then
citation = makeNewspaper( args )
else
citation = texts.wrongType
end
end
return table.concat( errorMsgs, '' )
return table.concat( errorMsgs, '' )
Zeile 356: Zeile 403:
function ci.book( frame )
function ci.book( frame )
local args = frame:getParent().args, ok
local args = frame:getParent().args, ok
-- local args = frame
args.type = 'book'
args.type = 'book'
return makeCitation( args, true )
return makeCitation( args )
end
end


Zeile 364: Zeile 410:
local args = frame:getParent().args
local args = frame:getParent().args
args.type = 'map'
args.type = 'map'
return makeCitation( args, true )
return makeCitation( args )
end
end


function ci.collection( frame )
function ci.collection( frame )
local args = frame:getParent().args
local args = frame:getParent().args
-- local args = frame
args.type = 'collection'
args.type = 'collection'
return makeCitation( args, true )
return makeCitation( args )
end
end


Zeile 377: Zeile 422:
local args = frame:getParent().args
local args = frame:getParent().args
args.type = 'journal'
args.type = 'journal'
return makeCitation( args, true )
return makeCitation( args )
end
end


Zeile 383: Zeile 428:
local args = frame:getParent().args
local args = frame:getParent().args
args.type = 'newspaper'
args.type = 'newspaper'
return makeCitation( args, true )
return makeCitation( args )
end
end


function ci.citation( frame )
function ci.citation( frame )
local args = frame:getParent().args
local args = frame:getParent().args
args = checkParams( args )
-- local args = frame


if args.type == '' then
aType = getArgValue( 'type', args )
if args.scale ~= '' then
if not aType or aType == '' or not inArray( types, aType ) then
args.type = 'map'
if getArgValue( 'scale', args ) ~= '' then
elseif args.collection ~= '' then
aType = 'map'
args.type = 'collection'
elseif getArgValue( 'collection', args ) ~= '' then
elseif args.journal ~= '' then
aType = 'collection'
args.type = 'journal'
elseif getArgValue( 'journal', args ) ~= '' then
elseif args.newspaper ~= '' then
aType = 'journal'
args.type = 'newspaper'
elseif getArgValue( 'newspaper', args ) ~= '' then
elseif args.editor ~= '' then
aType = 'newspaper'
args.type = 'collection'
elseif getArgValue( 'editor', args ) ~= '' then
aType = 'collection'
else
else
args.type = 'book'
aType = 'book'
end
end
args.type = aType
end
end
return makeCitation( args, false )
return makeCitation( args )
end
end


return ci
return ci
Anonymer Benutzer