Modul:LinkISBN: Unterschied zwischen den Versionen

Aus skandinavien-wiki.net
KKeine Bearbeitungszusammenfassung
KKeine Bearbeitungszusammenfassung
Zeile 27: Zeile 27:
.. '">[[' .. li.special .. mm .. '|' .. 'ISBN ' .. mm .. ']]</span>'
.. '">[[' .. li.special .. mm .. '|' .. 'ISBN ' .. mm .. ']]</span>'
if not noerror then
if not noerror then
if demo == 'true' then
if demo then
t = t .. ci._check_isbn( mm, li.invalidDemo )
t = t .. ci._check_isbn( mm, li.invalidDemo )
else
else
Zeile 40: Zeile 40:
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 ''
args.noerror = yn( args.noerror or '' )
args.noerror = yn( args.noerror, false )
args.demo    = yn( args.demo or '' )
args.demo    = args.demo or ''


local s
local s

Version vom 20. Dezember 2016, 09:54 Uhr

Die Dokumentation für dieses Modul kann unter Modul:LinkISBN/doc erstellt werden

local li = {}

local ci = require( 'Modul:Check_isxn' )
local yn = require( 'Modul:Yesno' )

li.invalid = '&nbsp;<span class="error">Ungültige ISBN</span>[[Kategorie:Seiten mit ISBN-Fehlern]]'
li.invalidDemo = '&nbsp;<span class="error">Ungültige ISBN</span>'
li.invalid = li.invalidDemo .. '[[Kategorie:Seiten mit ISBN-Fehlern]]'
li.special = 'Spezial:ISBN-Suche/' -- Special:BookSources

-- patterns for delimiters except ','
li.delimiters = { ' and ', ' or ', ' und ', ' oder ', ';' }

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="wv-booksources" title="' .. li.special .. mm
		.. '">[[' .. li.special .. mm .. '|' .. 'ISBN ' .. mm .. ']]</span>'
	if not noerror then
		if demo then
			t = t .. ci._check_isbn( mm, li.invalidDemo )
		else
			t = t .. ci._check_isbn( mm, li.invalid )
		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 '' )
	args.demo    = yn( args.demo or '' )

	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, 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