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

ماڊيول:Lua banner

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

هي ماڊيول {{lua}} سانچي کي لاڳو ڪري ٿو.

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

[سنواريو]

هي ماڊيول سڌو سنئون وڪي متن مان استعمال نٿو ڪري سگهجي. اهو رڳو {{lua}} سانچي وسيلي استعمال ڪري سگهجي ٿو. دستاويزن لاءِ مهرباني ڪري سانچي وارو صفحو ڏسو.

Lua ماڊيولن مان استعمال

[سنواريو]

هن ماڊيول کي ٻين Lua ماڊيولن مان استعمال ڪرڻ لاءِ، سڀ کان پهرين ماڊيول کي لوڊ ڪريو.

local mLuaBanner = require('Module:Lua banner')

ان کان پوءِ توهان _main فنڪشن ذريعي هڪ پاسي وارو خانو ٺاهي سگهو ٿا.

mLuaBanner._main(args)

args وارو متغير هڪ ٽيبل هجڻ گهرجي، جنهن ۾ اهي دليل شامل هجن جيڪي ماڊيول ڏانهن موڪلڻا آهن. ڪهڙا مختلف دليل ڏئي سگهجن ٿا ۽ اهي ماڊيول جي نتيجي تي ڪيئن اثرانداز ٿين ٿا، ان لاءِ مهرباني ڪري {{lua}} سانچي جا دستاويز ڏسو.

نگراني وارو زمرو

[سنواريو]

-- هي ماڊيول {{lua}} سانچي کي لاڳو ڪري ٿو.
local yesno = require('Module:Yesno')
local mList = require('Module:List')
local mTableTools = require('Module:TableTools')
local mMessageBox = require('Module:Message box')

local p = {}

function p.main(frame)
	local origArgs = frame:getParent().args
	local args = {}
	for k, v in pairs(origArgs) do
		v = v:match('^%s*(.-)%s*$')
		if v ~= '' then
			args[k] = v
		end
	end
	return p._main(args)
end

function p._main(args)
	local modules = mTableTools.compressSparseArray(args)
	local box = p.renderBox(modules)
	local trackingCategories = p.renderTrackingCategories(args, modules)
	return box .. trackingCategories
end

function p.renderBox(modules)
	local boxArgs = {}
	if #modules < 1 then
		boxArgs.text = '<strong class="error">غلطي: ڪو بہ ماڊيول مقرر نه ڪيو ويو</strong>'
	else
		local moduleLinks = {}
		for i, module in ipairs(modules) do
			moduleLinks[i] = string.format('[[:%s]]', module)
			local maybeSandbox = mw.title.new(module .. '/sandbox')
			if maybeSandbox and maybeSandbox.exists then
				moduleLinks[i] = moduleLinks[i] .. string.format(' ([[:%s|ريتخانو]])', maybeSandbox.fullText)
			end
		end
		local moduleList = mList.makeList('bulleted', moduleLinks)
		local title = mw.title.getCurrentTitle()
		if title.subpageText == "doc" then
			title = title.basePageTitle
		end
		if title.contentModel == "Scribunto" then
			boxArgs.text = 'هي ماڊيول هيٺين ٻين ماڊيولن تي دارومدار رکي ٿو:' .. moduleList
		else
			boxArgs.text = 'هي سانچو [[وڪيپيڊيا:Lua|Lua]] استعمال ڪري ٿو:\n' .. moduleList
		end
	end
	boxArgs.type = 'notice'
	boxArgs.small = true
	boxArgs.image = '[[File:Lua-Logo.svg|30px|alt=|link=]]'
	return mMessageBox.main('mbox', boxArgs)
end

function p.renderTrackingCategories(args, modules, titleObj)
	if yesno(args.nocat) then
		return ''
	end

	local cats = {}

	if #modules < 1 then
		cats[#cats + 1] = 'Lua سانچن ۾ غلطيون'
	end

	titleObj = titleObj or mw.title.getCurrentTitle()
	local subpageBlacklist = {
		doc = true,
		sandbox = true,
		sandbox2 = true,
		testcases = true
	}

	if not subpageBlacklist[titleObj.subpageText] then
		local protCatName

		if titleObj.namespace == 10 then
			local category = args.category
			if not category then
				local categories = {
					['Module:String'] = 'String Lua ماڊيول تي ٻڌل سانچا',
					['Module:Math'] = 'Math Lua ماڊيول تي ٻڌل سانچا',
					['Module:BaseConvert'] = 'BaseConvert Lua ماڊيول تي ٻڌل سانچا',
					['Module:Citation/CS1'] = 'Citation/CS1 Lua ماڊيول تي ٻڌل سانچا'
				}
				category = modules[1] and categories[modules[1]]
				category = category or 'Lua تي ٻڌل سانچا'
			end
			cats[#cats + 1] = category
			protCatName = 'گهٽ تحفظ وارا Lua ماڊيول استعمال ڪندڙ سانچا'
		elseif titleObj.namespace == 828 then
			protCatName = 'گهٽ تحفظ وارن ماڊيولن تي دارومدار رکندڙ ماڊيول'
		end

		if not args.noprotcat and protCatName then
			local protLevels = {
				autoconfirmed = 1,
				extendedconfirmed = 2,
				templateeditor = 3,
				sysop = 4
			}

			local currentProt
			if titleObj.id ~= 0 then
				local currentEditProt = titleObj.protectionLevels and titleObj.protectionLevels["edit"]
				currentProt = currentEditProt and currentEditProt[1]
			end

			if currentProt == nil then
				currentProt = 0
			else
				currentProt = protLevels[currentProt] or 0
			end

			for i, module in ipairs(modules) do
				if module ~= 'WP:libraryUtil' then
					local moduleTitle = mw.title.new(module)
					local moduleEditProt = moduleTitle and moduleTitle.protectionLevels and moduleTitle.protectionLevels["edit"]
					local moduleProt = moduleEditProt and moduleEditProt[1]

					if moduleProt == nil then
						moduleProt = 0
					else
						moduleProt = protLevels[moduleProt] or 0
					end

					if moduleProt < currentProt then
						cats[#cats + 1] = protCatName
						break
					end
				end
			end
		end
	end

	for i, cat in ipairs(cats) do
		cats[i] = string.format('[[زمرو:%s]]', cat)
	end

	return table.concat(cats)
end

return p