Modul:LinkISBN: Unterschied zwischen den Versionen

Aus skandinavien-wiki.net
K (+upper())
K (31 Versionen von wikivoyage:Modul:LinkISBN importiert)
 
(13 dazwischenliegende Versionen von einem anderen Benutzer werden nicht angezeigt)
Zeile 1: Zeile 1:
-- I18n
-- module interface
local li = {
local LinkISBN = {
invalid    = '&nbsp;<span class="error">Ungültige ISBN</span>',
suite  = 'LinkISBN',
invalidCat = '[[Category:Seiten mit ISBN-Fehlern]]',
serial = '2021-04-08',
special    = 'Special:ISBN-Suche/', -- Special:BookSources
item  = 65157187
 
-- patterns for delimiters except ','
delimiters = { ' and ', ' or ', ' und ', ' oder ', ';' },
 
-- CSS class
class      = 'wv-booksources'
}
}


-- module import
local ci = require( 'Module:Check_isxn' )
local ci = require( 'Module:Check_isxn' )
local lb = require( 'Module:LinkBase' )
local lb = require( 'Module:LinkISBN/i18n' )
local lu = require( 'Module:Link utilities' )
local yn = require( 'Module:Yesno' )
local yn = require( 'Module:Yesno' )


function li.linkISBN( m, noerror, demo )
-- module variable and administration
local li = {
moduleInterface = LinkISBN
}
 
-- link a single ISBN
function li._linkISBN( m, ignoreError, demo )
m = mw.text.trim( m )
m = mw.text.trim( m )
if m == '' then -- empty string
if m == '' then
return m
return m
end
end


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


m = mw.ustring.gsub( m, 'ISBN ', '' )
m = m:gsub( 'ISBN *', '' ):upper() -- x -> X
m = m:upper() -- x -> X
local t = '<span class="' .. lb.booksourcesClass .. '">[[Special:Booksources/'
t = '<span class="' .. li.class .. '" title="' .. li.special .. m
.. m .. '|' .. 'ISBN ' .. m .. ']]</span>'
.. '">[[' .. li.special .. m .. '|' .. 'ISBN ' .. m .. ']]</span>'
if not ignoreError then
if not noerror then
t = t .. ci._check_isbn( m,
if demo then
lb.invalidISBN .. ( demo and '' or lb.invalidCat ) )
t = t .. ci._check_isbn( m, li.invalid )
else
t = t .. ci._check_isbn( m, li.invalid .. li.invalidCat )
end
end
end
if comment ~= '' then
if comment ~= '' then
Zeile 46: Zeile 40:
end
end


function li.linkISBNSet( args )
-- link a list of several ISBNs
ns          = mw.title.getCurrentTitle().namespace
function li._linkISBNSet( args )
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 )
if args.isbn == '' then
if args.isbn == '' then
return ''
return ''
end
end


local result = '', i, s
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
-- split separate ISBNs
local items = lb.splitItems( args.isbn, li.delimiters )
local items = lu.splitItems( args.isbn, lb.delimiters )
-- analyse ISBNs
-- analyse ISBNs
for i = 1, #items, 1 do
local result = ''
s = li.linkISBN( items[ i ], args.noerror, isDemo )
local s
for i, item in ipairs( items ) do
s = li._linkISBN( item, args.ignoreError, isDemo )
if s ~= '' then
if s ~= '' then
if result == '' then
result = ( result ~= '' and result .. ', ' or '' ) .. s
result = s
else
result = result .. ', ' .. s
end
end
end
end
end
Zeile 76: Zeile 68:


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


return li
return li

Aktuelle Version vom 11. Februar 2023, 20:58 Uhr

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

-- module interface
local LinkISBN = {
	suite  = 'LinkISBN',
	serial = '2021-04-08',
	item   = 65157187
}

-- module import
local ci = require( 'Module:Check_isxn' )
local lb = require( 'Module:LinkISBN/i18n' )
local lu = require( 'Module:Link utilities' )
local yn = require( 'Module:Yesno' )

-- module variable and administration
local li = {
	moduleInterface = LinkISBN
}

-- 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="' .. lb.booksourcesClass .. '">[[Special:Booksources/'
		.. m .. '|' .. 'ISBN ' .. m .. ']]</span>'
	if not ignoreError then
		t = t .. ci._check_isbn( m,
			lb.invalidISBN .. ( demo and '' or lb.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, lb.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.linkISBNs( frame )
	return li._linkISBNSet( frame:getParent().args )
end

return li