Modul:LinkISBN: Unterschied zwischen den Versionen
(Schreibfehler) |
K (args.noerror -> args.ignoreError) |
||
Zeile 2: | Zeile 2: | ||
local LinkISBN = { | local LinkISBN = { | ||
suite = 'LinkISBN', | suite = 'LinkISBN', | ||
serial = ' | serial = '2020-03-26', | ||
item = 65157187 | item = 65157187 | ||
} | } | ||
Zeile 17: | Zeile 17: | ||
-- link a single ISBN | -- link a single ISBN | ||
function li._linkISBN( m, | function li._linkISBN( m, ignoreError, demo ) | ||
m = mw.text.trim( m ) | m = mw.text.trim( m ) | ||
if m == '' then -- empty string | if m == '' then -- empty string | ||
Zeile 30: | Zeile 30: | ||
.. li.categories.special .. m .. '">[[' .. li.categories.special | .. li.categories.special .. m .. '">[[' .. li.categories.special | ||
.. m .. '|' .. 'ISBN ' .. m .. ']]</span>' | .. m .. '|' .. 'ISBN ' .. m .. ']]</span>' | ||
if not | if not ignoreError then | ||
t = t .. ci._check_isbn( m, | t = t .. ci._check_isbn( m, | ||
li.categories.invalidISBN .. ( demo and '' or li.categories.invalidCat ) ) | li.categories.invalidISBN .. ( demo and '' or li.categories.invalidCat ) ) | ||
Zeile 43: | Zeile 43: | ||
function li._linkISBNSet( args ) | function li._linkISBNSet( args ) | ||
args.isbn = args.isbn or args[ 1 ] or '' | args.isbn = args.isbn or args[ 1 ] or '' | ||
args.noerror = yn( args. | args.ignoreError = args.ignoreError or args.noerror | ||
args.ignoreError = yn( args.ignoreError, false ) | |||
if args.isbn == '' then | if args.isbn == '' then | ||
return '' | return '' | ||
Zeile 58: | Zeile 59: | ||
-- analyse ISBNs | -- analyse ISBNs | ||
for i = 1, #items, 1 do | for i = 1, #items, 1 do | ||
s = li._linkISBN( items[ i ], args. | s = li._linkISBN( items[ i ], args.ignoreError, isDemo ) | ||
if s ~= '' then | if s ~= '' then | ||
result = ( result ~= '' and result .. ', ' or '' ) .. s | result = ( result ~= '' and result .. ', ' or '' ) .. s |
Version vom 26. März 2020, 06:08 Uhr
Die Dokumentation für dieses Modul kann unter Modul:LinkISBN/doc erstellt werden
-- module interface local LinkISBN = { suite = 'LinkISBN', serial = '2020-03-26', item = 65157187 } -- module variable, i18n local li = {} -- module import local ci = require( 'Module:Check_isxn' ) local fs = require( 'Module:Failsafe' ) local lb = require( 'Module:LinkBase' ) local li = require( 'Module:LinkBase/i18n' ) local yn = require( 'Module:Yesno' ) -- link a single ISBN function li._linkISBN( m, ignoreError, demo ) m = mw.text.trim( m ) if m == '' then -- empty string return m end local comment = '', t m, comment = lb.extractComment( m ) m = m:gsub( 'ISBN *', '' ):upper() -- x -> X t = '<span class="' .. li.classes.booksources .. '" title="' .. li.categories.special .. m .. '">[[' .. li.categories.special .. m .. '|' .. 'ISBN ' .. m .. ']]</span>' if not ignoreError then t = t .. ci._check_isbn( m, li.categories.invalidISBN .. ( demo and '' or li.categories.invalidCat ) ) end if comment ~= '' then t = t .. ' ' .. comment end return t end -- link a list of several ISBNs function li._linkISBNSet( args ) args.isbn = args.isbn or args[ 1 ] or '' args.ignoreError = args.ignoreError or args.noerror args.ignoreError = yn( args.ignoreError, false ) if args.isbn == '' then return '' end local ns = mw.title.getCurrentTitle().namespace local isDemo = ns == 10 or ns == 828 local result = '', i, s -- split separate ISBNs local items = lb.splitItems( args.isbn, li.delimiters ) -- analyse ISBNs for i = 1, #items, 1 do s = li._linkISBN( items[ i ], args.ignoreError, isDemo ) if s ~= '' then result = ( result ~= '' and result .. ', ' or '' ) .. s end end return result end function li.LinkISBN() return LinkISBN end function li.failsafe( version ) return fs._failsafe( version, LinkISBN ) or '' end function li.linkISBNs( frame ) return li._linkISBNSet( frame:getParent().args ) end return li