Importer, Bürokraten, Moderatoren (CommentStreams), Strukturierte-Diskussionen-Bots, Oberflächenadministratoren, Push-Abonnementverwalter, Oversighter, Administratoren, Kampagnenbearbeiter (Hochladeassistent)
855
Bearbeitungen
(+templateStyles) |
K (173 Versionen von wikivoyage:Modul:Citation importiert) |
||
| (38 dazwischenliegende Versionen von einem anderen Benutzer werden nicht angezeigt) | |||
| Zeile 2: | Zeile 2: | ||
local citation = { | local citation = { | ||
suite = 'Citation', | suite = 'Citation', | ||
serial = '2022- | 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 61: | Zeile 74: | ||
local wrong = {} | local wrong = {} | ||
local i | local i | ||
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' ) | if ( args.type == 'web' or args.type == 'webnews' ) | ||
| Zeile 135: | 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 150: | 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 157: | 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 177: | 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 190: | 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 284: | 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 | ||
| 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 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 | ||