Hoppa till innehållet

Modul:ISBN

Från Wikipedia

Dokumentation [visa] [redigera] [historik] [rensa sidcachen]


Den här modulen används av mallen {{ISBN}}.

p = {}
p.ISBN = function( frame )
	local pframe = frame:getParent()
	local args = pframe.args
	local arg = args[ 1 ]
	if arg then
		local template = '{{ISBN|' .. arg .. '}}'
		local copy = arg -- Kopiera så att vi kan vandalisera ISBN-numret internt och sedan returnera arg
		copy = copy:gsub( '-', '' )
		copy = copy:gsub( ' ', '' )
		local length = copy:len()
		if length == 10 then
			copy = copy:sub( 1, 9 )
			length = length -1
			local t = {}
			for i = 1, length do
				t[ i ] = copy:sub( i, i )
			end
			local t2 = {}
			local multiplier = 10
			for i = 1, #t do
				t2[ i ] = t[ i ] * multiplier
				multiplier = multiplier -1
				mw.log( t2[ i ] )
			end
			local sum = 0
			for i = 1, #t2 do
				sum = sum + t2[ i ]
			end
			mw.log( sum )
			local remainder = sum % 11
			mw.log( remainder )
			local checkdigit = 11 - remainder
			mw.log( checkdigit )
			if checkdigit % 11 ~= 0 then
				return frame:preprocess( template .. '[[Kategori:Sidor med felaktigt ISBN]]' )
			end
		elseif length == 13 then
			
		else
			return frame:preprocess( template .. '[[Kategori:Sidor med felaktigt ISBN]]' )
		end
		return frame:preprocess( template )
	else
		return '<span class="error">[[Mall:ISBN]] anropad utan argument</span>[[Kategori:Sidor som anropar Mall:ISBN utan argument]]'
	end
end
return p