Modul:LinkISBN: Unterschied zwischen den Versionen
K (Kleine Änderungen) |
(umgestellt) |
||
Zeile 13: | Zeile 13: | ||
local ci = require( 'Modul:Check_isxn' ) | local ci = require( 'Modul:Check_isxn' ) | ||
local lb = require( 'Module:LinkBase' ) | |||
local yn = require( 'Modul:Yesno' ) | local yn = require( 'Modul:Yesno' ) | ||
Zeile 46: | Zeile 47: | ||
args.demo = yn( args.demo or '', false ) | args.demo = yn( args.demo or '', false ) | ||
local s | local i, s | ||
local result = '' | local result = '' | ||
if args.isbn ~= '' then | if args.isbn ~= '' then | ||
-- | -- split separate numbers | ||
local items = lb.splitItems( args.isbn, li.delimiters ) | |||
-- split seperate ISBNs and analyse them | -- split seperate ISBNs and analyse them | ||
for | for i = 1, #items, 1 do | ||
s = li.linkISBN( | s = li.linkISBN( items[ i ], args.noerror, args.demo ) | ||
if s ~= '' then | if s ~= '' then | ||
if result == '' then result = s | if result == '' then result = s |
Version vom 7. Mai 2019, 05:26 Uhr
Die Dokumentation für dieses Modul kann unter Modul:LinkISBN/doc erstellt werden
-- I18n local li = { invalid = ' <span class="error">Ungültige ISBN</span>', invalidCat = '[[Kategorie:Seiten mit ISBN-Fehlern]]', special = 'Spezial:ISBN-Suche/', -- Special:BookSources -- patterns for delimiters except ',' delimiters = { ' and ', ' or ', ' und ', ' oder ', ';' }, -- CSS class class = 'wv-booksources' } local ci = require( 'Modul:Check_isxn' ) local lb = require( 'Module:LinkBase' ) local yn = require( 'Modul:Yesno' ) function li.linkISBN( m, noerror, demo ) local mm = mw.text.trim( m ) if mm == '' then return mm end -- empty string local comment = '' local t = mw.ustring.gsub( mm, '(.*)(%(.*%))$', '%2' ) if t ~= mm then comment = t mm = mw.ustring.gsub( mw.ustring.gsub( mm, '(.*)(%(.*%))$', '%1' ), '( +)$', '' ) end mm = mw.ustring.gsub( mm, 'ISBN ', '' ) t = '<span class="' .. li.class .. '" title="' .. li.special .. mm .. '">[[' .. li.special .. mm .. '|' .. 'ISBN ' .. mm .. ']]</span>' if not noerror then if demo then t = t .. ci._check_isbn( mm, li.invalid ) else t = t .. ci._check_isbn( mm, li.invalid .. li.invalidCat ) end end if comment ~= '' then t = t .. ' ' .. comment end return t end function li.linkISBNSet( args ) args.isbn = args.isbn or args[1] or '' args.noerror = yn( args.noerror or '', false ) args.demo = yn( args.demo or '', false ) local i, s local result = '' if args.isbn ~= '' then -- split separate numbers local items = lb.splitItems( args.isbn, li.delimiters ) -- split seperate ISBNs and analyse them for i = 1, #items, 1 do s = li.linkISBN( items[ i ], args.noerror, args.demo ) if s ~= '' then if result == '' then result = s else result = result .. ', ' .. s end end end end return result end function li.linkISBNs( frame ) local args = frame.args return li.linkISBNSet( args ) end return li