Module:Internet Archive small links

Documentation for this module may be created at Module:Internet Archive small links/doc

require('strict')

local p = {} --p stands for package

local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local make_style_string = require('Module:Optional style').make_style_string

local function IAlink(id, suffix)
	local add
	if suffix then
		add = " " .. suffix
	else
		add = ""
	end
	return "[https://archive.org/details/" .. (id or "") .. " IA" .. add .. "]"
end

function p.links(frame)
	local args = getArgs(frame)
	
	-- make links
	local start = tonumber(args.start) or 1
	local prefix = args.prefix or ''
	local suffix = args.suffix or ''
	local numbers = yesno(args.numbers or 'yes')
	local display = args.display
	
	local style = make_style_string({['font-size'] = '83%', ['style'] = args.style})
	
	local links = {}
	for k, id in pairs(args) do
		if tonumber(k) then
			if numbers then
				table.insert(links, IAlink(id, k + start - 1))
			else
				table.insert(links, IAlink(id, args.display))
			end
		end
	end
	
	local link_string = '<span title="Copy of this work at the Internet Archive" ' .. style .. '">' .. prefix .. table.concat(links, ", ") .. suffix .. '</span>'
	
	-- tracking cat
	local cat
	local page = mw.title.getCurrentTitle()
	if (page.nsText == 'Template' or page.nsText == 'Module') and page.rootText == 'Internet Archive small links' then
		cat = ''
	else
		cat = '[[Category:Pages linking to scanned works at Internet Archive]]'
	end
	
	return link_string .. cat
end

return p