Modul:LinkISBN: Unterschied zwischen den Versionen

Aus skandinavien-wiki.net
KKeine Bearbeitungszusammenfassung
K (31 Versionen von wikivoyage:Modul:LinkISBN importiert)
 
(20 dazwischenliegende Versionen von einem anderen Benutzer werden nicht angezeigt)
Zeile 1: Zeile 1:
local li = {}
-- module interface
local LinkISBN = {
suite  = 'LinkISBN',
serial = '2021-04-08',
item  = 65157187
}


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


li.invalid = '&nbsp;<span class="error">Ungültige ISBN</span>[[Kategorie:Seiten mit ISBN-Fehlern]]'
-- module variable and administration
li.invalidDemo = '&nbsp;<span class="error">Ungültige ISBN</span>'
local li = {
li.invalid = li.invalidDemo .. '[[Kategorie:Seiten mit ISBN-Fehlern]]'
moduleInterface = LinkISBN
li.special = 'Spezial:ISBN-Suche/' -- Special:BookSources
}


-- patterns for delimiters except ','
-- link a single ISBN
li.delimiters = { ' and ', ' or ', ' und ', ' oder ', ';' }
function li._linkISBN( m, ignoreError, demo )
m = mw.text.trim( m )
if m == '' then
return m
end


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


local comment = ''
m = m:gsub( 'ISBN *', '' ):upper() -- x -> X
local t = mw.ustring.gsub( mm, '(.*)(%(.*%))$', '%2' )
local t = '<span class="' .. lb.booksourcesClass .. '">[[Special:Booksources/'
if t ~= mm then
.. m .. '|' .. 'ISBN ' .. m .. ']]</span>'
comment = t
if not ignoreError then
mm = mw.ustring.gsub( mw.ustring.gsub( mm, '(.*)(%(.*%))$', '%1' ), '( +)$', '' )
t = t .. ci._check_isbn( m,
lb.invalidISBN .. ( demo and '' or lb.invalidCat ) )
end
end
 
if comment ~= '' then
mm = mw.ustring.gsub( mm, 'ISBN ', '' )
t = t .. ' ' .. comment
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
end
if comment ~= '' then t = t .. ' ' .. comment end
return t
return t
end
end


function li.linkISBNSet( args )
-- link a list of several ISBNs
args.isbn   = args.isbn or args[1] or ''
function li._linkISBNSet( args )
args.noerror = yn( args.noerror or '', false )
args.isbn = args.isbn or args[ 1 ] or ''
args.demo    = yn( args.demo or '', false )
if args.isbn == '' then
return ''
end


local s
args.ignoreError = yn( args.ignoreError or args.noerror, false )
local result = ''


if args.isbn ~= '' then
local ns    = mw.title.getCurrentTitle().namespace
-- substitude delimiters
local isDemo = ns == 10 or ns == 828
for i = 1, #li.delimiters, 1 do
args.isbn = mw.ustring.gsub( args.isbn, li.delimiters[i], ',' );
end


-- split seperate ISBNs and analyse them
-- split separate ISBNs
for s in mw.ustring.gmatch( args.isbn .. ',', '([^,]+)' ) do
local items = lu.splitItems( args.isbn, lb.delimiters )
s = li.linkISBN( s, args.noerror, args.demo )
if s ~= '' then
-- analyse ISBNs
if result == '' then result = s
local result = ''
else result = result .. ', ' .. s
local s
end
for i, item in ipairs( items ) do
end
s = li._linkISBN( item, args.ignoreError, isDemo )
if s ~= '' then
result = ( result ~= '' and result .. ', ' or '' ) .. s
end
end
end
end
Zeile 66: Zeile 68:


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

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