Jump to content

विभाग:Small scan link

विकिस्रोत कडून

विभाग:Small scan link/doc येथे या विभागाचे दस्तावेजीकरण तयार करु शकता

local p = {} --p stands for package

-- simple function to make a link to a give index page
local function index_link(index, display)
	return "[[" .. "Index:" .. index .. "|" .. display .. "]]"	
end

-- get the n'th link in the args, inclusing name if given
local function get_link(args, n)
	local display = n
	local argname = 'name' .. n
	if args[argname] ~= nil then
		display = args[argname]
	end

	return index_link(args[n], display)
end

--[=[
Return a formatted small scan link
Args:
   1,2,3....        : The index pages to link to
   name1, name2, ...: Display text for corresponding index page
]=]
function p.small_scan_link( frame )
	local args = frame:getParent().args
	
	local s = ''

	if args[1] == nil then
		error("At least an Index page is required", 0) 	
	end
	
	if args[2] == nil then
		-- single argument

		local target = args[1]
		local link_text = ""
		-- use the provided name if there is one
		if args['name1'] ~= nil then
			link_text = args['name1']
		else
			-- name based on existance of target
			if mw.title.new("Index:" .. target).exists then
				link_text = "transcription project"
			else
				link_text = "start transcription"
			end
		end
		s = index_link(target, link_text)
	else
		-- multiple positional args

		local i = 1
		s = "transcription volumes: "
		-- iterate positional parameters
		while args[i] ~= nil do
			s = s .. get_link(args, i)
			i = i + 1
			
			if args[i] ~= nil then
				s = s .. ", "
			end
		end
	end

	return "<span class=\"scanlink\" style=\"font-size: 83%;\">(" .. s .. ")</span>"
end

return p