Importer, Bürokraten, Moderatoren (CommentStreams), Strukturierte-Diskussionen-Bots, Oberflächenadministratoren, Push-Abonnementverwalter, Oversighter, Administratoren, Kampagnenbearbeiter (Hochladeassistent)
855
Bearbeitungen
(range format) |
K (173 Versionen von wikivoyage:Modul:Citation importiert) |
||
| (43 dazwischenliegende Versionen von einem anderen Benutzer werden nicht angezeigt) | |||
| Zeile 2: | Zeile 2: | ||
local citation = { | local citation = { | ||
suite = 'Citation', | suite = 'Citation', | ||
serial = ' | serial = '2022-10-21', | ||
item = 56159597 | item = 56159597 | ||
} | } | ||
-- module import | -- module import | ||
require( ' | -- require( 'strict' ) | ||
local cu = require( 'Module:Citation/utilities' ) | local cu = require( 'Module:Citation/utilities' ) | ||
local cc = require( 'Module:Citation/COinS' ) | local cc = require( 'Module:Citation/COinS' ) | ||
| Zeile 32: | Zeile 32: | ||
complete[ value2 ] = key | complete[ value2 ] = key | ||
args[ key ] = args[ key ] or | args[ key ] = args[ key ] or | ||
cu.parameterCleanup( frameArgs[ value2 ] ) | ( key ~= 'bibcode' and cu.parameterCleanup( frameArgs[ value2 ] ) or frameArgs[ value2 ] ) | ||
end | end | ||
args[ key ] = args[ key ] or '' | args[ key ] = args[ key ] or '' | ||
| Zeile 55: | Zeile 55: | ||
end | end | ||
return args | return args | ||
end | |||
local function checkRedundantParams( args, keys ) | |||
local i = 0 | |||
for _, key in ipairs( keys ) do | |||
if cu.isSet( args[ key ] ) then | |||
i = i + 1 | |||
if i > 1 then | |||
return true | |||
end | |||
end | |||
end | |||
return false | |||
end | end | ||
| Zeile 62: | Zeile 75: | ||
local i | local i | ||
if args.type == 'web' and not cu.isSet( args.title ) and not cu.isSet( args.url ) then | if cu.isSet( args.title ) then | ||
args.title = args.title:gsub( '%s*%.+$', '' ) | |||
end | |||
-- convert book with chapter to collection | |||
if args.type == 'book' and not cu.isSet( args.collection ) and cu.isSet( args.chapter ) then | |||
args.type = 'bookitem' | |||
args.collection, args.title, args.chapter = args.title, args.chapter, '' | |||
args.siteUrl, args.url, args.chapterUrl = args.url, args.chapterUrl, '' | |||
end | |||
if ( args.type == 'web' or args.type == 'webnews' ) | |||
and not cu.isSet( args.title ) and not cu.isSet( args.url ) then | |||
args.title = ci.texts.noTitle | args.title = ci.texts.noTitle | ||
cu.addErrorMsg( ci.texts.noTitleUrl ) | cu.addErrorMsg( ci.texts.noTitleUrl ) | ||
| Zeile 134: | Zeile 159: | ||
args[ value ] = '' | args[ value ] = '' | ||
cu.addErrorMsg( ci.texts.noURL ) | cu.addErrorMsg( ci.texts.noURL ) | ||
end | |||
end | |||
if cu.isSet( args.url ) then | |||
for _, url in ipairs( ci.unwantedUrls ) do | |||
if args.url:find( url, 1, true ) then | |||
cu.addErrorMsg( ci.texts.unwantedURL ) | |||
break | |||
end | |||
end | end | ||
end | end | ||
| Zeile 149: | Zeile 182: | ||
end | end | ||
for key, value in ipairs( { 'dnb', 'oclc', 'jstor', 'KBytes' } ) do | for key, value in ipairs( { 'dnb', 'oclc', 'jstor', 'pmid', 'KBytes' } ) do | ||
if cu.isSet( args[ value ] ) and not args[ value ]:match( '^%d | if cu.isSet( args[ value ] ) and not args[ value ]:match( '^[1-9]%d*$' ) then | ||
args[ value ] = '' | args[ value ] = '' | ||
table.insert( wrong, value ) | table.insert( wrong, value ) | ||
| Zeile 156: | Zeile 189: | ||
end | end | ||
if cu.isSet( args.doi ) and not mw.ustring.match( args.doi, '^10%.%d | if cu.isSet( args.asin ) then | ||
if args.asin:match("^%d%d%d%d%d%d%d%d%d[%dX]$") then | |||
if not cu.isSet( args.isbn ) and not args.asin:find( '^63[01]' ) and | |||
cx.check_isbn( { args = { [ 1 ] = args.asin, error = 'error' } } ) ~= 'error' then | |||
args.isbn = args.asin | |||
end | |||
args.asin = '' | |||
table.insert( wrong, 'asin' ) | |||
elseif not args.asin:match("^%u[%d%u][%d%u][%d%u][%d%u][%d%u][%d%u][%d%u][%d%u][%d%u]$") then | |||
args.asin = '' | |||
table.insert( wrong, 'asin' ) | |||
end | |||
end | |||
if cu.isSet( args.ol ) then | |||
args.ol = args.ol:gsub( '^OL', '' ) | |||
if not args.ol:match( '^[1-9]%d*[AMW]$' ) then | |||
args.ol = '' | |||
table.insert( wrong, 'ol' ) | |||
end | |||
end | |||
local match, country | |||
if cu.isSet( args.urn ) then | |||
args.urn = args.urn:lower():gsub( '^urn:', '' ) | |||
match, country = args.urn:match( '^(nbn:(%l%l):[%d%l%-%.:/_]+)$' ) | |||
if not ( match and country and ci.nbnResolving[ country ] ) then | |||
args.urn = '' | |||
table.insert( wrong, 'urn' ) | |||
end | |||
end | |||
if cu.isSet( args.urn ) and ci.nbnCheckDigit[ country ] and | |||
not cu.check_UrnNbn( 'urn:' .. args.urn ) then | |||
cu.addErrorMsg( ci.texts.wrongURN ) | |||
end | |||
-- in suffix spaces or n-dashes and at the end periods or commas are not allowed | |||
if cu.isSet( args.doi ) and not mw.ustring.match( args.doi, '^10%.[1-9]%d%d%d%d?/[^%s–]-[^%.,]$' ) then | |||
args.doi = '' | args.doi = '' | ||
table.insert( wrong, 'doi' ) | table.insert( wrong, 'doi' ) | ||
end | |||
if cu.isSet( args.hdl ) and not mw.ustring.match( args.hdl, '^[1-9][%d%.]*%d/[^%s–]-[^%.,]$' ) then | |||
args.hdl = '' | |||
table.insert( wrong, 'hdl' ) | |||
end | |||
if not cu.isSet( args.url ) then | |||
for _, key in ipairs( ci.additionalTitleUrls ) do | |||
if cu.isSet( args[ key ] ) then | |||
args.url = ci.params[ key ].url:format( args[ key ] ) | |||
if key == 'urn' then | |||
args.urn = '' | |||
end | |||
break | |||
end | |||
end | |||
end | |||
-- See: https://arxiv.org/help/arxiv_identifier | |||
if cu.isSet( args.arxiv ) and not ( | |||
-- 1991-07 … 2007-03 | |||
args.arxiv:match( '^%a[%a%.%-]+/[90]%d[01]%d%d%d%d$' ) or args.arxiv:match( '^%a[%a%.%-]+/[90]%d[01]%d%d%d%d[vV]%d+$' ) or | |||
-- 2007-04 … 2014-12 | |||
args.arxiv:match( '^[01]%d[01]%d%.%d%d%d%d$' ) or args.arxiv:match( '^[01]%d[01]%d%.%d%d%d%d[vV]%d+$' ) or | |||
-- 2015-01 … | |||
args.arxiv:match( '^%d%d[01]%d%.%d%d%d%d%d$' ) or args.arxiv:match( '^%d%d[01]%d%.%d%d%d%d%d[vV]%d+$' ) ) then | |||
args.arxiv = '' | |||
table.insert( wrong, 'arXiv' ) | |||
end | |||
-- See: https://adsabs.harvard.edu/abs_doc/help_pages/data.html#bibcodes | |||
if cu.isSet( args.bibcode ) and | |||
not ( args.bibcode:len() == 19 and args.bibcode:match( '^[12]%d%d%d%a[%w&%.][%w&%.][%w&%.][%w%.]+[%a%.]$' ) ) then | |||
args.bibcode = '' | |||
table.insert( wrong, 'bibcode' .. args.bibcode:len() ) | |||
end | |||
if cu.isSet( args.bibcode ) then | |||
args.bibcode = args.bibcode:gsub( '%.', '#b#' ) -- keep bibcode periods (full stops) | |||
end | end | ||
| Zeile 176: | Zeile 285: | ||
if args.access == '' then | if args.access == '' then | ||
cu.addErrorMsg( ci.texts.accesswrong ) | cu.addErrorMsg( ci.texts.accesswrong ) | ||
elseif not cu.isSet( args.url ) and not cu.isSet( args.archiveUrl ) | elseif not cu.isSet( args.url ) and not cu.isSet( args.archiveUrl ) and | ||
and not cu.isSet( args. | not cu.isSet( args.doi ) and not cu.isSet( args.hdl ) and | ||
not cu.isSet( args.jstor ) then | |||
cu.addErrorMsg( ci.texts.accessNoUrl ) | cu.addErrorMsg( ci.texts.accessNoUrl ) | ||
end | end | ||
end | |||
if checkRedundantParams( args, { 'isbn', 'dnb', 'urn', 'oclc', 'ol', 'asin' } ) or | |||
checkRedundantParams( args, { 'doi', 'hdl', 'jstor', 'arxiv', 'bibcode' } ) then | |||
cu.addErrorMsg( ci.texts.redundantParams ) | |||
end | end | ||
| Zeile 189: | Zeile 304: | ||
end | end | ||
local function | local function formatIdentifier( tab, key, urlPart, text, add ) | ||
if cu.isSet( urlPart ) and cu.isSet( text ) then | |||
if ignoreError ~= 'true' | text = ci.params[ key ].prefix .. | ||
cu.makeLink( ci.params[ key ].url:gsub( '%%s', urlPart ), text ) .. | |||
( add or '' ) | |||
table.insert( tab, text ) | |||
end | |||
end | |||
local function addIssn( tab, issn, ignoreError ) | |||
if cu.isSet( issn ) then | |||
local add = ignoreError ~= 'true' and ci.texts.wrongIssn or '' | |||
add = cx.check_issn( { args = { [ 1 ] = issn, error = add } } ) | |||
formatIdentifier( tab, 'issn', issn, issn, add ) | |||
end | end | ||
end | end | ||
| Zeile 212: | Zeile 335: | ||
-- make title part | -- make title part | ||
local function makeTitle( title, volume, addition, url, scale, titleType ) | local function makeTitle( title, volume, addition, url, scale, titleType ) | ||
if titleType == ' | if titleType == 'bookitem' then | ||
title = cu.formatItem( title, ci.formatters.tiCollectionTitle ) | title = cu.formatItem( title, ci.formatters.tiCollectionTitle ) | ||
elseif titleType == 'journal' then | elseif titleType == 'journal' then | ||
| Zeile 283: | Zeile 406: | ||
li._linkISBNSet( { isbn = args.isbn, ignoreError = args.ignoreError } ) ) | li._linkISBNSet( { isbn = args.isbn, ignoreError = args.ignoreError } ) ) | ||
elseif cu.isSet( args.dnb ) then | elseif cu.isSet( args.dnb ) then | ||
formatIdentifier( tab, 'dnb', args.dnb, args.dnb ) | |||
elseif cu.isSet( args.urn ) then | |||
formatIdentifier( tab, 'urn', args.urn, args.urn ) | |||
elseif cu.isSet( args.oclc ) then | elseif cu.isSet( args.oclc ) then | ||
formatIdentifier( tab, 'oclc', args.oclc, args.oclc ) | |||
elseif cu.isSet( args.ol ) then | |||
local prefix = { | |||
A = 'authors/OL', | |||
M = 'books/OL', | |||
W = 'works/OL' | |||
}; | |||
formatIdentifier( tab, 'ol', prefix[ args.ol:sub( -1 ) ] .. args.ol, args.ol ) | |||
elseif cu.isSet( args.asin ) then | |||
formatIdentifier( tab, 'asin', args.asin, args.asin ) | |||
end | end | ||
addIssn( tab, args.issn, args.ignoreError ) | |||
addIssn( tab, args.eissn, args.ignoreError ) | |||
end | end | ||
local function formatPages( s ) | local function formatPages( s ) | ||
return mw.ustring.gsub( s, '-', '–' ) | |||
end | end | ||
| Zeile 312: | Zeile 441: | ||
table.insert( tab, args.extent ) | table.insert( tab, args.extent ) | ||
end | end | ||
if cu.isSet( args | for _, key in ipairs( { 'doi', 'hdl', 'jstor', 'arxiv', 'bibcode' } ) do | ||
if cu.isSet( args[ key ] ) then | |||
formatIdentifier( tab, key, args[ key ], args[ key ] ) | |||
break | |||
end | |||
end | end | ||
formatIdentifier( tab, 'pmid', args.pmid, args.pmid ) | |||
end | end | ||
| Zeile 429: | Zeile 561: | ||
cu.insertItem( result, args.series, ci.formatters.tiSeries ) | cu.insertItem( result, args.series, ci.formatters.tiSeries ) | ||
makeIsbn( args, result ) | makeIsbn( args, result ) | ||
if cu.isSet( args.chapter ) and cu.isSet( args.chapterUrl ) then | |||
args.chapter = cu.makeLink( args.chapterUrl, args.chapter ) | |||
end | |||
cu.insertItem( result, args.chapter, ci.formatters.tiChapter ) | cu.insertItem( result, args.chapter, ci.formatters.tiChapter ) | ||
makePages( args, result ) | makePages( args, result ) | ||
| Zeile 449: | Zeile 584: | ||
title = makeTitle( args.title, args.volume, args.titleAddition, args.url, | title = makeTitle( args.title, args.volume, args.titleAddition, args.url, | ||
args.scale, 'title' ) | args.scale, 'title' ) | ||
else -- | else -- bookitem | ||
author = makeAuthor( '', args.editor ) | author = makeAuthor( '', args.editor ) | ||
title = makeTitle( args.collection, args.volume, args.titleAddition, | title = makeTitle( args.collection, args.volume, args.titleAddition, | ||
args.url, '', ' | args.url, '', 'bookitem' ) | ||
end | end | ||
return author .. title .. makePublished( args ) | return author .. title .. makePublished( args ) | ||
| Zeile 462: | Zeile 597: | ||
local editor = makeAuthor( '', args.editor ) | local editor = makeAuthor( '', args.editor ) | ||
local collection = makeTitle( args.collection, args.volume, args.titleAddition, | local collection = makeTitle( args.collection, args.volume, args.titleAddition, | ||
args.siteUrl, '', ' | args.siteUrl, '', 'bookitem' ) | ||
return author .. title .. ci.formatters.tiIn .. editor .. collection | return author .. title .. ci.formatters.tiIn .. editor .. collection | ||
| Zeile 478: | Zeile 613: | ||
end | end | ||
if not cu.isSet( title ) then | if not cu.isSet( title ) then | ||
if args.type ~= 'web' then | if args.type ~= 'web' or args.type == 'webnews' then | ||
title = ci.texts.noTitle | title = ci.texts.noTitle | ||
cu.addErrorMsg( ci.texts.unknownPeriodical ) | cu.addErrorMsg( ci.texts.unknownPeriodical ) | ||
| Zeile 578: | Zeile 713: | ||
if args.type == 'map' or args.type == 'book' then | if args.type == 'map' or args.type == 'book' then | ||
citation = makeBook( args ) | citation = makeBook( args ) | ||
elseif args.type == ' | elseif args.type == 'bookitem' then | ||
citation = makeCollection( args ) | citation = makeCollection( args ) | ||
elseif args.type == 'journal' or args.type == 'newspaper' | elseif args.type == 'journal' or args.type == 'newspaper' | ||
or args.type == 'web' then | or args.type == 'web' or args.type == 'webnews' then | ||
citation = makePeriodical( args ) | citation = makePeriodical( args ) | ||
else | else | ||
| Zeile 591: | Zeile 726: | ||
if cu.isSet( args.access ) then | if cu.isSet( args.access ) then | ||
citation = citation | citation = citation | ||
.. ' <span | .. ' <span class="voy-cite-access">' | ||
.. ci.accessTypes[ args.access ].file .. '</span>' | .. ci.accessTypes[ args.access ].file .. '</span>' | ||
end | end | ||
| Zeile 598: | Zeile 733: | ||
return cu.getErrorMsgs() | return cu.getErrorMsgs() | ||
.. tostring( mw.html.create( 'cite' ) | .. tostring( mw.html.create( 'cite' ) | ||
:attr( 'class', | :attr( 'class', ci.citeClass .. ci.addCiteClasses[ args.type ] ) | ||
:wikitext( citation ) | :wikitext( citation ) | ||
) | ) | ||
| Zeile 618: | Zeile 752: | ||
args.type = 'map' | args.type = 'map' | ||
elseif cu.getArgValue( ci.params, 'collection', args ) ~= '' then | elseif cu.getArgValue( ci.params, 'collection', args ) ~= '' then | ||
args.type = ' | args.type = 'bookitem' | ||
elseif cu.getArgValue( ci.params, 'journal', args ) ~= '' then | elseif cu.getArgValue( ci.params, 'journal', args ) ~= '' then | ||
args.type = 'journal' | args.type = 'journal' | ||
| Zeile 629: | Zeile 763: | ||
end | end | ||
end | end | ||
return makeCitation( args ) | return cu.templateStyles( frame ) .. makeCitation( args ) | ||
end | end | ||
return ct | return ct | ||