Modul:Citation: Unterschied zwischen den Versionen
KKeine Bearbeitungszusammenfassung |
KKeine Bearbeitungszusammenfassung |
||
| Zeile 542: | Zeile 542: | ||
result[ 1 ] = mw.ustring.gsub( result[ 1 ], '^%l', mw.ustring.upper ) | result[ 1 ] = mw.ustring.gsub( result[ 1 ], '^%l', mw.ustring.upper ) | ||
end | end | ||
result = | result = table.concat( result, ci.formatters.addDelimiter1 ) | ||
return makeLanguageComment( args, result ) | return author .. makeLanguageComment( args, result ) | ||
end | end | ||
Version vom 27. März 2020, 09:17 Uhr
Die Dokumentation für dieses Modul kann unter Modul:Citation/doc erstellt werden
-- documentation
local citation = {
suite = 'Citation',
serial = '2020-03-27',
}
-- module import
local cu = require( 'Module:Citation/utilities' )
local cc = require( 'Module:Citation/COinS' )
local ci = require( 'Module:Citation/i18n' )
local cx = require( 'Module:Check isxn' )
local li = require( 'Module:LinkISBN' )
local uc = require( 'Module:UrlCheck' )
local yn = require( 'Module:Yesno' )
-- module variable
local ct = {}
-- global variable
-- detcted date format y, y-m, y-m-d
local dateFormat = ''
-- check for valid arguments against params table
local function getValidArgs( frameArgs )
local args = {}, key, key2, ok, value, value2
local complete = {}
local wrongParams = {}
local aType = frameArgs.type
for key, value in pairs( ci.params ) do
if not value.types or cu.inArray( value.types, aType ) then
for key2, value2 in ipairs( value ) do
complete[ value2 ] = key
args[ key ] = args[ key ] or
cu.cleanupParameters( frameArgs[ value2 ], value.cleanup )
end
args[ key ] = args[ key ] or ''
end
end
-- no missing items
for key, value in pairs( ci.params ) do
if not args[ key ] then
args[ key ] = ''
end
end
for key, value in pairs( frameArgs ) do
if not complete[ key ] then
table.insert( wrongParams, key )
end
end
if #wrongParams == 1 then
cu.addErrorMsg( mw.ustring.format( ci.texts.unknownParam, table.concat( wrongParams, ', ' ) ) )
elseif #wrongParams > 0 then
cu.addErrorMsg( mw.ustring.format( ci.texts.unknownParams, table.concat( wrongParams, ', ' ) ) )
end
return args
end
-- check parameter values
local function checkValues( args )
local i, key, value
local wrong = {}
local aType = args.type
if aType == 'web' and not cu.isSet( args.title ) and not cu.isSet( args.url ) then
title = ci.texts.noTitle
cu.addErrorMsg( ci.texts.noTitleUrl )
elseif not cu.isSet( args.title ) then
title = ci.texts.noTitle
cu.addErrorMsg( ci.texts.unknownTitle )
end
args.pages = cu.cleanupPageNumbers( args.pages )
args.columns = cu.cleanupPageNumbers( args.columns )
if cu.isSet( args.KBytes ) and cu.isSet( args.MBytes ) then
args.MBytes = ''
cu.addErrorMsg( ci.texts.KBytesMBytes )
end
args.ignoreError = yn( args.ignoreError, false )
if args.ignoreError then
args.ignoreError = 'true'
else
args.ignoreError = 'false'
end
if cu.isSet( 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 cu.isSet( args.date ) then
i = tonumber( args.date )
if i >= 1000 and i < 2100 then
dateFormat = 'Y'
else
args.date = ''
cu.addErrorMsg( ci.texts.wrongDate )
end
end
end
end
for key, value in ipairs( { 'accessDate', 'archiveDate' } ) do
if cu.isSet( args[ value ] ) and
not args[ value ]:match( '^20%d%d%-[01]?%d%-[0123]?%d$' ) then
args[ value ] = ''
cu.addErrorMsg( ci.texts.wrongDate )
end
end
for key, value in ipairs( { 'url', 'articleUrl', 'archiveUrl' } ) do
if cu.isSet( args[ value ] ) and uc.isUrl( args[ value ] ) > 2 then
args[ value ] = ''
cu.addErrorMsg( ci.texts.noURL )
end
end
-- copying for historical reasons
if aType == 'journal' then
args.siteUrl = args.url
end
if aType == 'journal' then
args.url = args.articleUrl
end
args.urlStatus = cu.getKey( args.urlStatus, ci.urlStatusTable )
if not cu.isSet( args.urlStatus ) and cu.isSet( args.archiveUrl ) then
args.urlStatus = 'dead'
elseif not cu.isSet( args.urlStatus ) then
args.urlStatus = 'live'
end
if args.urlStatus == 'dead' then
args.originalUrl = args.url
args.url = args.archiveUrl
args.archiveUrl = ''
elseif args.urlStatus == 'usurped' then
args.url = args.archiveUrl
args.archiveUrl = ''
end
for key, value in ipairs( { 'dnb', 'oclc', 'jstor', 'KBytes' } ) do
if cu.isSet( args[ value ] ) and not args[ value ]:match( '^%d+$' ) then
args[ value ] = ''
table.insert( wrong, value )
end
end
if cu.isSet( args.doi ) and not mw.ustring.match( args.doi, '^10%.%d+/.+$' ) then
args.doi = ''
table.insert( wrong, 'doi' )
end
if cu.isSet( args.edition ) then
args.edition = args.edition:match( '%d+' ) or ''
if args.edition == '1' then
args.edition = ''
end
end
if cu.isSet( args.type ) and args.type ~= 'map' then
args.scale = ''
end
if #wrong == 1 then
cu.addErrorMsg( mw.ustring.format( ci.texts.wrongValue, wrong[ 1 ] ) )
elseif #wrong > 1 then
cu.addErrorMsg( mw.ustring.format( ci.texts.wrongValues, table.concat( wrong, ', ' ) ) )
end
end
local function makeIssnLink( issn, ignoreError )
local text = ''
if ignoreError ~= 'true' then
text = ci.texts.wrongIssn
end
return ci.formatters.dbIssn:gsub( 'xx1xx', issn )
.. cx.check_issn( { args = { [ 1 ] = issn, error = text } } )
end
-- make author part
local function makeAuthor( author, editor )
if cu.isSet( editor ) then
editor = mw.ustring.format( ci.formatters.auEditor, editor )
end
if cu.isSet( author ) and cu.isSet( editor ) then
author = mw.ustring.format( ci.formatters.auAuthorEditor, author, editor )
elseif not cu.isSet( author ) and cu.isSet( editor ) then
author = editor
end
if cu.isSet( author ) then
return mw.ustring.format( ci.formatters.auAuthor, author )
else
return ''
end
end
-- make title part
local function makeTitle( title, volume, url, scale )
if not cu.isSet( title ) then
title = ci.texts.noTitle
cu.addErrorMsg( ci.texts.unknownTitle )
end
if cu.isSet( url ) then
title = title:gsub( '[%[%]]', '' )
title = '[' .. url .. ' ' .. title .. ']'
end
if cu.isSet( volume ) then
title = mw.ustring.format( ci.formatters.tiVolume, title, volume )
else
title = mw.ustring.format( ci.formatters.tiTitle, title )
end
title = mw.ustring.format( ci.formatters.tiAll, title )
if cu.isSet( scale ) then
title = title .. mw.ustring.format( ci.formatters.tiScale, scale )
end
return title
end
-- make publisher part for books
local function makePublisher( args, tab )
local theDate = ''
if cu.isSet( args.date ) then
if cu.isSet( dateFormat ) and dateFormat ~= 'Y' then
dateFormat = 'M Y'
end
theDate = cu.getDate( args.date, dateFormat, ci.texts.wrongDate )
end
local published = ''
if cu.isSet( theDate ) and cu.isSet( args.edition ) then
theDate = mw.ustring.format( ci.formatters.puDateEdition, theDate, args.edition )
end
if cu.isSet( args.place ) and cu.isSet( args.publisher ) then
published = mw.ustring.format( ci.formatters.puPlacePub, args.place, args.publisher )
elseif cu.isSet( args.place ) then
published = args.place
elseif cu.isSet( args.publisher ) then
published = args.publisher
end
if not cu.isSet( published ) then
published = theDate
elseif cu.isSet( theDate ) then
published = mw.ustring.format( ci.formatters.puPlaceDate, published, theDate )
end
cu.insertItem( tab, published )
end
-- make series part
local function makeSeries( args, tab )
local key, value
for key, value in ipairs( { 'series', 'series2', 'series3' } ) do
cu.insertItem( tab, args[ value ], ci.formatters.tiSeries )
end
end
local function makeIsbn( args, tab )
if cu.isSet( args.isbn ) then
table.insert( tab,
li._linkISBNSet( { isbn = args.isbn, ignoreError = args.ignoreError } ) )
elseif cu.isSet( args.dnb ) then
table.insert( tab, mw.ustring.format( ci.formatters.dbDnb, args.dnb, args.dnb ) )
elseif cu.isSet( args.oclc ) then
table.insert( tab, mw.ustring.format( ci.formatters.dbOclc, args.oclc, args.oclc ) )
end
if cu.isSet( args.issn ) then
table.insert( tab, makeIssnLink( args.issn, args.ignoreError ) )
end
if cu.isSet( args.eissn ) then
table.insert( tab, makeIssnLink( args.eissn, args.ignoreError ) )
end
end
local function makePages( args, tab )
if cu.isSet( args.pages ) then
table.insert( tab,
mw.ustring.format( ci.formatters.addPages, args.pages:gsub( '-', '–' ) ) )
end
if cu.isSet( args.columns ) then
table.insert( tab,
mw.ustring.format( ci.formatters.addColumns, args.columns:gsub( '-', '–' ) ) )
end
end
local function makeDoi( args, tab )
if cu.isSet( args.extent ) then
if args.extent:match( '^%d+$' ) then
args.extent = mw.ustring.format( ci.formatters.addExtent, args.extent )
end
table.insert( tab, args.extent )
end
if cu.isSet( args.doi ) then
table.insert( tab,
mw.ustring.format( ci.formatters.dbDoi, cu.makeDoiLink( args.doi ) ) )
end
if cu.isSet( args.jstor ) then
table.insert( tab,
mw.ustring.format( ci.formatters.dbJstor, args.jstor, args.jstor ) )
end
end
local function makeWebInfo( args, tab )
local kb, index, value
if cu.isSet( args.url ) or cu.isSet( args.articleUrl ) or cu.isSet( args.archiveUrl ) then
if cu.isSet( args.accessDate ) then
args.accessDate = cu.getDate( args.accessDate, 'j. F Y', ci.texts.wrongDate )
if cu.isSet( args.accessDate ) then
table.insert( tab,
mw.ustring.format( ci.formatters.wbAccess, args.accessDate ) )
end
end
if cu.isSet( args.format ) then
table.insert( tab, args.format:upper() )
else
for index, value in ipairs( { 'PDF', 'DOC', 'DOCX', 'RTF', 'ODT',
'PPT', 'PPTX', 'XLS', 'XLSX' } ) do
if cu.hasExtension( args.url, value ) then
table.insert( tab, value )
break
end
if cu.hasExtension( args.archiveUrl, value ) then
table.insert( tab, value )
break
end
end
end
if cu.isSet( args.KBytes ) then
kb = tonumber( args.KBytes ) or 0
if kb >= 1024 then
table.insert( tab,
mw.ustring.format( ci.formatters.wbMBytes,
tostring( cu.round( kb / 1024, 3 ) ):gsub( '%.', ci.texts.decimalPoint ) ) )
else
table.insert( tab,
mw.ustring.format( ci.formatters.wbKBytes, args.KBytes ) )
end
elseif cu.isSet( args.MBytes ) then
table.insert( tab,
mw.ustring.format( ci.formatters.wbMBytes, args.MBytes ) )
end
end
end
local function makeArchived( args )
local archived = ci.formatters.arArchived
local original = ci.formatters.arOriginal
if cu.isSet( args.archiveUrl ) then
archived = '[' .. args.archiveUrl .. ' ' .. archived .. ']'
end
if cu.isSet( args.originalUrl ) then
original = '[' .. args.originalUrl .. ' ' .. original .. ']'
end
local day = '', result
if cu.isSet( args.archiveDate ) then
day = cu.getDate( args.date, 'l, j. F Y', ci.texts.wrongDate )
end
if day ~= '' then
result = mw.ustring.format( ci.formatters.arArchiveDate, archived, original, day )
else
if cu.isSet( args.archiveDate ) then
cu.addErrorMsg( ci.texts.wrongDate )
end
result = mw.ustring.format( ci.formatters.arArchive, archived, original )
end
return result
end
local function makeLanguageComment( args, result )
if cu.isSet( args.language ) then
result = result .. mw.ustring.format( ci.formatters.addLanguage, args.language )
end
if result ~= '' then
result = mw.ustring.format( ci.formatters.puAll, result )
end
if cu.isSet( args.archiveUrl ) or cu.isSet( args.originalUrl )
or args.urlStatus == 'usurped' then
result = result .. makeArchived( args )
end
if cu.isSet( args.comment ) then
result = result .. mw.ustring.format( ci.formatters.addComment, args.comment )
end
return result
end
local function makePublished( args )
result = {}
makePublisher( args, result )
makeSeries( args, result )
makeIsbn( args, result )
if cu.isSet( args.chapter ) then
table.insert( result, mw.ustring.format( ci.formatters.tiChapter, args.chapter ) )
end
makePages( args, result )
if #result > 0 then
result = { table.concat( result, ci.formatters.addDelimiter1 ) }
end
makeDoi( args, result )
makeWebInfo( args, result )
result = table.concat( result, ci.formatters.addDelimiter2 )
return makeLanguageComment( args, result )
end
local function makeBook( args )
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, collection, editor, title
author = makeAuthor( args.author, '' )
title = makeTitle( args.title, args.volume, args.url, '' )
editor = makeAuthor( '', args.editor )
collection = makeTitle( args.collection, args.volume, args.siteUrl, '' )
return author .. title .. ci.formatters.tiIn .. editor .. collection
.. makePublished( args )
end
local function makeJournalTitle( args )
if args.type == 'journal' then
title = args.journal
elseif args.type == 'newspaper' then
title = args.newspaper
else
title = args.website
end
if not cu.isSet( title ) then
if args.type ~= 'web' then
title = ci.texts.noTitle
cu.addErrorMsg( ci.texts.unknownPeriodical )
end
else
title = mw.ustring.format( ci.formatters.tiTitle, title )
if cu.isSet( args.siteUrl ) then
title = title:gsub( '[%[%]]', '' )
title = '[' .. args.siteUrl .. ' ' .. title .. ']'
end
if cu.isSet( args.place ) then
title = title .. mw.ustring.format( ci.formatters.prPlace, args.place )
end
if cu.isSet( args.abbr ) then
title = title .. mw.ustring.format( ci.formatters.prAbbr, args.abbr )
end
title = ci.formatters.tiIn .. title
end
return title
end
local function makeJournalInfo( args, tab )
local year = ''
if cu.isSet( args.date ) then
year = cu.getDate( args.date, dateFormat, ci.texts.wrongDate )
end
local volume = ''
if cu.isSet( args.volume ) then
volume = mw.ustring.format( ci.formatters.prVolume, args.volume )
if cu.isSet( args.issue ) then
volume = mw.ustring.format( ci.formatters.prVolIssue, volume, args.issue )
end
if year ~= '' then
volume = mw.ustring.format( ci.formatters.prVolYear, volume, year )
end
else
if cu.isSet( args.issue ) then
volume = mw.ustring.format( ci.formatters.prIssue, args.issue )
if year ~= '' then
volume = mw.ustring.format( ci.formatters.prVolYear, volume, year )
end
else
volume = year
end
end
if volume ~= '' then
table.insert( tab, volume )
end
end
local function makeNewspaperInfo( args, tab )
if cu.isSet( args.publisher ) then
table.insert( tab, args.publisher )
end
if cu.isSet( args.volume ) then
table.insert( tab,
mw.ustring.format( ci.formatters.nsVolume, args.volume ) )
end
if cu.isSet( args.issue ) then
table.insert( tab,
mw.ustring.format( ci.formatters.prIssue, args.issue ) )
end
local day = ''
if cu.isSet( args.date ) then
if dateFormat == 'j. F Y' then
-- following result can be ''
day = cu.getDate( args.date, 'l, j. F Y', ci.texts.wrongDate )
else
cu.addErrorMsg( ci.texts.wrongDate )
end
end
if day ~= '' then
table.insert( tab, day )
end
end
local function makePeriodical( args )
local author = makeAuthor( args.author, '' )
.. makeTitle( args.title, '', args.url, '' )
local result = {}
local jTitle = makeJournalTitle( args )
if cu.isSet( jTitle ) then
table.insert( result, jTitle )
end
makeIsbn( args, result )
if args.type == 'journal' then
makeJournalInfo( args, result )
else -- newspaper and web
makeNewspaperInfo( args, result )
end
makePages( args, result )
makeDoi( args, result )
makeWebInfo( args, result )
if #result > 0 then
result[ 1 ] = mw.ustring.gsub( result[ 1 ], '^%l', mw.ustring.upper )
end
result = table.concat( result, ci.formatters.addDelimiter1 )
return author .. makeLanguageComment( args, result )
end
local function makeCitation( frameArgs )
local args, citation
args = getValidArgs( frameArgs )
checkValues( args )
if args.type == 'map' or args.type == 'book' then
citation = makeBook( args )
elseif args.type == 'collection' then
citation = makeCollection( args )
elseif args.type == 'journal' or args.type == 'newspaper'
or args.type == 'web' then
citation = makePeriodical( args )
else
args.type = 'book'
citation = ci.texts.wrongType .. makeBook( args )
end
citation = cu.finalCleanup( citation )
cc.prepareForCOinS( args )
return cu.getErrorMsgs()
.. '<cite style="font-style: normal;" class="citation ' .. args.type
.. ' printNoLink">' .. citation .. '</cite>'
.. cc.makeCOinS( args, ci.params )
end
function ct.citation( frame )
local fType = frame.args.type
local args = frame:getParent().args
if cu.isSet( fType ) then
args.type = fType
else
args.type = cu.getKey( cu.getArgValue( ci.params, 'type', args ), ci.refTypes )
end
if not cu.isSet( args.type ) then
if cu.getArgValue( ci.params, 'scale', args ) ~= '' then
args.type = 'map'
elseif cu.getArgValue( ci.params, 'collection', args ) ~= '' then
args.type = 'collection'
elseif cu.getArgValue( ci.params, 'journal', args ) ~= '' then
args.type = 'journal'
elseif cu.getArgValue( ci.params, 'newspaper', args ) ~= '' then
args.type = 'newspaper'
elseif cu.getArgValue( ci.params, 'website', args ) ~= '' then
args.type = 'web'
else
args.type = 'book'
end
end
return makeCitation( args )
end
return ct