Modul:LinkISBN: Unterschied zwischen den Versionen
(code check) |
(Umbenennung) |
||
Zeile 2: | Zeile 2: | ||
local LinkISBN = { | local LinkISBN = { | ||
suite = 'LinkISBN', | suite = 'LinkISBN', | ||
serial = '2020- | serial = '2020-10-24', | ||
item = 65157187 | item = 65157187 | ||
} | } | ||
Zeile 12: | Zeile 12: | ||
local ci = require( 'Module:Check_isxn' ) | local ci = require( 'Module:Check_isxn' ) | ||
local fs = require( 'Module:Failsafe' ) | local fs = require( 'Module:Failsafe' ) | ||
local | local li = require( 'Module:Link utilities/i18n' ) | ||
local | local lu = require( 'Module:Link utilities' ) | ||
local yn = require( 'Module:Yesno' ) | local yn = require( 'Module:Yesno' ) | ||
Zeile 24: | Zeile 24: | ||
local comment = '' | local comment = '' | ||
m, comment = | m, comment = lu.extractComment( m ) | ||
m = m:gsub( 'ISBN *', '' ):upper() -- x -> X | m = m:gsub( 'ISBN *', '' ):upper() -- x -> X | ||
Zeile 53: | Zeile 53: | ||
-- split separate ISBNs | -- split separate ISBNs | ||
local items = | local items = lu.splitItems( args.isbn, li.delimiters ) | ||
-- analyse ISBNs | -- analyse ISBNs |
Version vom 24. Oktober 2020, 14:03 Uhr
Die Dokumentation für dieses Modul kann unter Modul:LinkISBN/doc erstellt werden
-- module interface local LinkISBN = { suite = 'LinkISBN', serial = '2020-10-24', item = 65157187 } -- module variable, i18n local li = {} -- module import local ci = require( 'Module:Check_isxn' ) local fs = require( 'Module:Failsafe' ) local li = require( 'Module:Link utilities/i18n' ) local lu = require( 'Module:Link utilities' ) local yn = require( 'Module:Yesno' ) -- link a single ISBN function li._linkISBN( m, ignoreError, demo ) m = mw.text.trim( m ) if m == '' then return m end local comment = '' m, comment = lu.extractComment( m ) m = m:gsub( 'ISBN *', '' ):upper() -- x -> X local 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 '' if args.isbn == '' then return '' end args.ignoreError = yn( args.ignoreError or args.noerror, false ) local ns = mw.title.getCurrentTitle().namespace local isDemo = ns == 10 or ns == 828 -- split separate ISBNs local items = lu.splitItems( args.isbn, li.delimiters ) -- analyse ISBNs local result = '' local s for i, item in ipairs( items ) do s = li._linkISBN( item, 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