Modul:LinkISBN: Unterschied zwischen den Versionen
(Die Seite wurde neu angelegt: „local li = {} local ci = require( 'Modul:Check_isxn' ) li.invalid = ' <span class="error">Ungültige ISBN</span>Kategorie:Seiten mit ISBN-Fehlern'…“) |
KKeine Bearbeitungszusammenfassung |
||
Zeile 8: | Zeile 8: | ||
li.delimiters = { ' and ', ' or ', ' und ', ' oder ', ';' } | li.delimiters = { ' and ', ' or ', ' und ', ' oder ', ';' } | ||
function li.linkISBN( m ) | function li.linkISBN( m, noerror ) | ||
local mm = mw.text.trim( m ) | local mm = mw.text.trim( m ) | ||
if mm == '' then return mm end -- empty string | if mm == '' then return mm end -- empty string | ||
Zeile 21: | Zeile 21: | ||
mm = mw.ustring.gsub( mm, 'ISBN ', '' ) | mm = mw.ustring.gsub( mm, 'ISBN ', '' ) | ||
t = '[[Special:BookSources/' .. mm .. '|' .. 'ISBN ' .. mm .. ']]' | t = '[[Special:BookSources/' .. mm .. '|' .. 'ISBN ' .. mm .. ']]' | ||
t = t .. ci._check_isbn( mm, li.invalid ) | if not noerror then t = t .. ci._check_isbn( mm, li.invalid ) end | ||
if comment ~= '' then t = t .. ' ' .. comment end | if comment ~= '' then t = t .. ' ' .. comment end | ||
Zeile 29: | Zeile 29: | ||
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'] = args['noerror'] or '' | |||
if (args['noerror'] == 'j') or (args['noerror'] == 'y') then args['noerror'] = true | |||
else args['noerror'] = false end | |||
local s | local s | ||
Zeile 41: | Zeile 44: | ||
-- split seperate ISBNs and analyse them | -- split seperate ISBNs and analyse them | ||
for s in mw.ustring.gmatch( args.isbn .. ',', '([^,]+)' ) do | for s in mw.ustring.gmatch( args.isbn .. ',', '([^,]+)' ) do | ||
s = li.linkISBN( s ) | s = li.linkISBN( s, args['noerror'] ) | ||
if s ~= '' then | if s ~= '' then | ||
if result == '' then result = s | if result == '' then result = s |
Version vom 26. November 2016, 08:06 Uhr
Die Dokumentation für dieses Modul kann unter Modul:LinkISBN/doc erstellt werden
local li = {} local ci = require( 'Modul:Check_isxn' ) li.invalid = ' <span class="error">Ungültige ISBN</span>[[Kategorie:Seiten mit ISBN-Fehlern]]' -- patterns for delimiters except ',' li.delimiters = { ' and ', ' or ', ' und ', ' oder ', ';' } function li.linkISBN( m, noerror ) 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 = '[[Special:BookSources/' .. mm .. '|' .. 'ISBN ' .. mm .. ']]' if not noerror then t = t .. ci._check_isbn( mm, li.invalid ) 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'] = args['noerror'] or '' if (args['noerror'] == 'j') or (args['noerror'] == 'y') then args['noerror'] = true else args['noerror'] = false end local s local result = '' if args.isbn ~= '' then -- substitude delimiters for i = 1, #li.delimiters, 1 do args.isbn = mw.ustring.gsub( args.isbn, li.delimiters[i], ',' ); end -- split seperate ISBNs and analyse them for s in mw.ustring.gmatch( args.isbn .. ',', '([^,]+)' ) do s = li.linkISBN( s, args['noerror'] ) 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