Modul:LinkISBN: Unterschied zwischen den Versionen

Aus skandinavien-wiki.net
KKeine Bearbeitungszusammenfassung
(Parameter demo abgeschafft)
Zeile 2: Zeile 2:
local li = {
local li = {
invalid    = '&nbsp;<span class="error">Ungültige ISBN</span>',
invalid    = '&nbsp;<span class="error">Ungültige ISBN</span>',
invalidCat = '[[Kategorie:Seiten mit ISBN-Fehlern]]',
invalidCat = '[[Category:Seiten mit ISBN-Fehlern]]',
special    = 'Spezial:ISBN-Suche/', -- Special:BookSources
special    = 'Special:ISBN-Suche/', -- Special:BookSources


-- patterns for delimiters except ','
-- patterns for delimiters except ','
Zeile 17: Zeile 17:


function li.linkISBN( m, noerror, demo )
function li.linkISBN( m, noerror, demo )
local mm = mw.text.trim( m )
m = mw.text.trim( m )
if mm == '' then return mm end -- empty string
if m == '' then -- empty string
return m
end


local comment = ''
local comment = '', t
local t = mw.ustring.gsub( mm, '(.*)(%(.*%))$', '%2' )
t = mw.ustring.gsub( m, '(.*)(%(.*%))$', '%2' )
if t ~= mm then
if t ~= m then
comment = t
comment = t
mm = mw.ustring.gsub( mw.ustring.gsub( mm, '(.*)(%(.*%))$', '%1' ), '( +)$', '' )
m = mw.ustring.gsub( mw.ustring.gsub( m, '(.*)(%(.*%))$', '%1' ), '( +)$', '' )
end
end


mm = mw.ustring.gsub( mm, 'ISBN ', '' )
m = mw.ustring.gsub( m, 'ISBN ', '' )
t = '<span class="' .. li.class .. '" title="' .. li.special .. mm
t = '<span class="' .. li.class .. '" title="' .. li.special .. m
.. '">[[' .. li.special .. mm .. '|' .. 'ISBN ' .. mm .. ']]</span>'
.. '">[[' .. li.special .. m .. '|' .. 'ISBN ' .. m .. ']]</span>'
if not noerror then
if not noerror then
if demo then
if demo then
t = t .. ci._check_isbn( mm, li.invalid )
t = t .. ci._check_isbn( m, li.invalid )
else
else
t = t .. ci._check_isbn( mm, li.invalid .. li.invalidCat )
t = t .. ci._check_isbn( m, li.invalid .. li.invalidCat )
end
end
end
end
if comment ~= '' then t = t .. ' ' .. comment end
if comment ~= '' then
t = t .. ' ' .. comment
end
return t
return t
end
end


function li.linkISBNSet( args )
function li.linkISBNSet( args )
ns          = mw.title.getCurrentTitle().namespace
isDemo      = ns == 10 or ns == 828
args.isbn    = args.isbn or args[1] or ''
args.isbn    = args.isbn or args[1] or ''
args.noerror = yn( args.noerror or '', false )
args.noerror = yn( args.noerror or '', false )
args.demo    = yn( args.demo or '', false )
if args.isbn == '' then
return ''
end


local result = '', j, s
local result = '', i, s


if args.isbn ~= '' then
-- split separate ISBNs
-- split separate ISBNs
local items = lb.splitItems( args.isbn, li.delimiters )
local items = lb.splitItems( args.isbn, li.delimiters )
-- analyse ISBNs
-- analyse ISBNs
for j = 1, #items, 1 do
for i = 1, #items, 1 do
s = li.linkISBN( items[ j ], args.noerror, args.demo )
s = li.linkISBN( items[ i ], args.noerror, isDemo )
if s ~= '' then
if s ~= '' then
if result == '' then
if result == '' then
result = s
result = s
else
else
result = result .. ', ' .. s
result = result .. ', ' .. s
end
end
end
end
end
Zeile 69: Zeile 75:


function li.linkISBNs( frame )
function li.linkISBNs( frame )
local args = frame.args
return li.linkISBNSet( frame:getParent().args )
return li.linkISBNSet( args )
end
end


return li
return li

Version vom 8. Juli 2019, 06:55 Uhr

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

-- I18n
local li = {
	invalid    = '&nbsp;<span class="error">Ungültige ISBN</span>',
	invalidCat = '[[Category:Seiten mit ISBN-Fehlern]]',
	special    = 'Special:ISBN-Suche/', -- Special:BookSources

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

	-- CSS class
	class      = 'wv-booksources'
}

local ci = require( 'Module:Check_isxn' )
local lb = require( 'Module:LinkBase' )
local yn = require( 'Module:Yesno' )

function li.linkISBN( m, noerror, demo )
	m = mw.text.trim( m )
	if m == '' then -- empty string
		return m
	end

	local comment = '', t
	t = mw.ustring.gsub( m, '(.*)(%(.*%))$', '%2' )
	if t ~= m then
		comment = t
		m = mw.ustring.gsub( mw.ustring.gsub( m, '(.*)(%(.*%))$', '%1' ), '( +)$', '' )
	end

	m = mw.ustring.gsub( m, 'ISBN ', '' )
	t = '<span class="' .. li.class .. '" title="' .. li.special .. m
		.. '">[[' .. li.special .. m .. '|' .. 'ISBN ' .. m .. ']]</span>'
	if not noerror then
		if demo then
			t = t .. ci._check_isbn( m, li.invalid )
		else
			t = t .. ci._check_isbn( m, li.invalid .. li.invalidCat )
		end
	end
	if comment ~= '' then
		t = t .. ' ' .. comment
	end
	return t
end

function li.linkISBNSet( args )
	ns           = mw.title.getCurrentTitle().namespace
	isDemo       = ns == 10 or ns == 828
	
	args.isbn    = args.isbn or args[1] or ''
	args.noerror = yn( args.noerror or '', false )
	if args.isbn == '' then
		return ''
	end

	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.noerror, isDemo )
		if s ~= '' then
			if result == '' then
				result = s
			else
				result = result .. ', ' .. s
			end
		end
	end
	return result
end

function li.linkISBNs( frame )
	return li.linkISBNSet( frame:getParent().args )
end

return li