مواد ڏانھن هلو

ماڊيول:File link

کليل ڄاڻ چيڪلي، وڪيپيڊيا مان


هي ماڊيول فائلن ڏانهن وڪي ٽيڪسٽ لنڪ ٺاهڻ لاءِ استعمال ڪيو ويندو آهي. اهو خاص طور تي انهن سانچن ۽ ماڊيولن لاءِ ڪارائتو آهي جيڪي فائل لنڪ ٺاهڻ لاءِ پيچيده لاجڪ استعمال ڪن ٿا. سادا فائل لنڪ سڌو وڪي ٽيڪسٽ مارڪ اپ سان ٺاهڻ گهرجن، ڇاڪاڻ⁠تہ اهو هن ماڊيول کي سڏڻ کان گهٽ وسيلا استعمال ڪندو آهي. وڪي ٽيڪسٽ فائل مارڪ اپ بابت مدد لاءِ ميڊياوڪي (MediaWiki) تي دستاويز ڏسو.

وڪي ٽيڪسٽ مان استعمال

[سنواريو]

وڪي ٽيڪسٽ مان، هن ماڊيول کي عام طور ڪنهن سانچي مان سڏيو ويندو آهي، اڪثر ڪري {{file link}} سان. مهرباني ڪري دستاويز لاءِ سانچي جو صفحو ڏسو. بهرحال، ان کي هي سنٽيڪس استعمال ڪري سڌو به سڏي سگهجي ٿو:

{{#invoke:File link|main|arguments}}

لُوا (Lua) مان استعمال

[سنواريو]

پهريان توهان کي ماڊيول کي امپورٽ ڪرڻو پوندو:

local mFileLink = require('Module:File link')

ان کان پوءِ توهان _main فنڪشن استعمال ڪري فائل لنڪ ٺاهي سگهو ٿا:

mFileLink._main(args)

args هڪ آرگومينٽ ٽيبل آهي جنهن ۾ هي ڪيئي (keys) ٿي سگهن ٿا:

  • file – فائل جو نالو (ضروري)
  • format – فائل فارميٽ، مثال: 'thumb', 'thumbnail', 'frame', 'framed', يا 'frameless'
  • formatfile – 'thumbnail' فارميٽ سان استعمال لاءِ مخصوص فائل نالو
  • border – true يا "yes" ڪرڻ سان تصوير جي چوڌاري بارڊر لڳندو
  • location – فائل جي افقي جڳهه: 'right', 'left', 'center', يا 'none'
  • alignment – عمودي ترتيب: 'baseline', 'middle', 'sub', 'super', 'text-top', 'text-bottom', 'top', يا 'bottom'
  • size – تصوير جو سائيز، مثال: '100px', 'x100px' يا '100x100px'
  • upright – ڊگهي ۽ سنهين تصويرن لاءِ سائيز مقرر ڪرڻ لاءِ
  • link – اهو صفحو جنهن ڏانهن فائل لنڪ ٿيندي
  • alt – alt ٽيڪسٽ
  • caption – فائل جو ڪيپشن
  • page – گهڻ صفحن واري فائل (مثال PDF) لاءِ صفحي جو نمبر
  • class – تصويري لنڪ ۾ class پيرا ميٽر شامل ڪري ٿو
  • lang – فائل جي ٻولي مقرر ڪري ٿو
  • start – آڊيو يا وڊيو لاءِ شروعاتي وقت
  • end – آڊيو يا وڊيو لاءِ آخري وقت
  • thumbtime – وڊيو فائل لاءِ thumbnail ٺاهڻ جو وقت

انهن سڀني پيرا ميٽرن جو اثر ڏسڻ لاءِ ميڊياوڪي تصويرن جي مدد صفحو ڏسو.

مثال

[سنواريو]

صرف فائل سان:

mFileLink.main{file = 'Example.png'}
-- نتيجو: [[File:Example.png]]

فارميٽ، سائيز، لنڪ ۽ ڪيپشن سان:

mFileLink.main{
	file = 'Example.png',
	format = 'thumb',
	size = '220px',
	link = 'Wikipedia:Sandbox',
	caption = 'An example.'
}
-- نتيجو: [[File:Example.png|thumb|220px|link=Wikipedia:Sandbox|An example.]]

فارميٽ، سائيز ۽ بارڊر سان:

mFileLink.main{
	file = 'Example.png',
	format = 'frameless',
	size = '220px',
	border = true
}
-- نتيجو: [[File:Example.png|frameless|border|220px]]



-- This module provides a library for formatting file wikilinks.

local yesno = require('Module:Yesno')
local checkType = require('libraryUtil').checkType

local p = {}

function p._main(args)
	checkType('_main', 1, args, 'table')

	-- This is basically libraryUtil.checkTypeForNamedArg, but we are rolling our
	-- own function to get the right error level.
	local function checkArg(key, val, level)
		if type(val) ~= 'string' then
			error(string.format(
				"type error in '%s' parameter of '_main' (expected string, got %s)",
				key, type(val)
			), level)
		end
	end

	local ret = {}

	-- Adds a positional parameter to the buffer.
	local function addPositional(key)
		local val = args[key]
		if not val then
			return nil
		end
		checkArg(key, val, 4)
		ret[#ret + 1] = val
	end

	-- Adds a named parameter to the buffer. We assume that the parameter name
	-- is the same as the argument key.
	local function addNamed(key)
		local val = args[key]
		if not val then
			return nil
		end
		checkArg(key, val, 4)
		ret[#ret + 1] = key .. '=' .. val
	end

	-- Filename
	checkArg('file', args.file, 3)
	ret[#ret + 1] = 'File:' .. args.file

	-- Format
	if args.format then
		checkArg('format', args.format)
		if args.formatfile then
			checkArg('formatfile', args.formatfile)
			ret[#ret + 1] = args.format .. '=' .. args.formatfile
		else
			ret[#ret + 1] = args.format
		end
	end

	-- Border
	if yesno(args.border) then
		ret[#ret + 1] = 'border'
	end

	addPositional('location')
	addPositional('alignment')
	addPositional('size')
	addNamed('upright')
	addNamed('link')
	addNamed('alt')
	addNamed('page')
	addNamed('class')
	addNamed('lang')
	addNamed('start')
	addNamed('end')
	addNamed('thumbtime')
	addPositional('caption')

	return string.format('[[%s]]', table.concat(ret, '|'))
end

function p.main(frame)
	local origArgs = require('Module:Arguments').getArgs(frame, {
		wrappers = 'Template:File link'
	})
	if not origArgs.file then
		error("'file' parameter missing from [[Template:File link]]", 0)
	end

	-- Copy the arguments that were passed to a new table to avoid looking up
	-- every possible parameter in the frame object.
	local args = {}
	for k, v in pairs(origArgs) do
		-- Make _BLANK a special argument to add a blank parameter. For use in
		-- conditional templates etc. it is useful for blank arguments to be
		-- ignored, but we still need a way to specify them so that we can do
		-- things like [[File:Example.png|link=]].
		if v == '_BLANK' then
			v = ''
		end
		args[k] = v
	end
	return p._main(args)
end

return p