Mô đun:Lua banner

-- Mô đun này thực hiện bản mẫu {{lua}}.
local yesno = require('Mô đun:Yesno')
local mList = require('Mô đun:List')
local mTableTools = require('Mô đun:TableTools')
local mMessageBox = require('Mô đun: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">Lỗi: không có mô đun nào được gọi ra</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.exists then
				moduleLinks[i] = moduleLinks[i] .. string.format(' ([[:%s|chỗ thử]])', 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 = 'Mô đun này phụ thuộc vào các mô đun sau:' .. moduleList
		else
			boxArgs.text = 'Bản mẫu này sử dụng [[Wikipedia:Lua|Lua]]:\n' .. moduleList
		end
	end
	boxArgs.type = 'notice'
	boxArgs.small = true
	boxArgs.image = '[[Tập tin:Lua-logo-nolabel.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 = {}

	-- Error category
	if #modules < 1 then
		cats[#cats + 1] = 'Bản mẫu Lua có lỗi'
	end

	-- Lua templates category
	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 = {
					['Mô đun:String'] = 'Bản mẫu dựa trên ngôn ngữ Lua String',
					['Mô đun:Math'] = 'Bản mẫu dựa trên ngôn ngữ Lua Math',
					['Mô đun:BaseConvert'] = 'Bản mẫu dựa trên ngôn ngữ mô đun Lua BaseConvert',
					['Mô đun:Citation'] = 'Bản mẫu chú thích dựa trên ngôn ngữ Lua'
				}
				categories['Mô đun:Citation/CS1'] = categories['Mô đun:Citation']
				category = modules[1] and categories[modules[1]]
				category = category or 'Bản mẫu dựa trên ngôn ngữ Lua'
			end	
			cats[#cats + 1] = category
			protCatName = "Bản mẫu sử dụng mô đun Lua bị khóa"
		elseif titleObj.namespace == 828 then
			protCatName = "Mô đun phụ thuộc vào mô đun bị khóa"
		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
				-- id is 0 (page does not exist) if am previewing before creating a template.
				currentProt = titleObj.protectionLevels["edit"][1]
			end
			if currentProt == nil then currentProt = 0 else currentProt = protLevels[currentProt] end
			for i, module in ipairs(modules) do
				if module ~= "WP:libraryUtil" then
					local moduleProt = mw.title.new(module).protectionLevels["edit"][1]
					if moduleProt == nil then moduleProt = 0 else moduleProt = protLevels[moduleProt] 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('[[Thể loại:%s]]', cat)
	end
	return table.concat(cats)
end

return p
Chúng tôi bán
Bài viết liên quan
Nhân vật Lộng Ngọc - Thiên Hành Cửu Ca
Nhân vật Lộng Ngọc - Thiên Hành Cửu Ca
Nàng, tên gọi Lộng Ngọc, là đệ nhất cầm cơ của Hàn quốc, thanh lệ thoát tục, hoa dung thướt tha, thu thủy gợi tình
[Tóm tắt và đánh giá sách] Mindset - Sức mạnh của việc đổi mới tư duy
[Tóm tắt và đánh giá sách] Mindset - Sức mạnh của việc đổi mới tư duy
Mindset là cuốn sách giúp bạn hiểu cặn kẽ về sức mạnh của tư duy dưới nghiên cứu đánh giá tâm lý học - hành vi con người
Tổng quan Hạt Giống Ma Vương và Ma Vương trong Tensura
Tổng quan Hạt Giống Ma Vương và Ma Vương trong Tensura
Ma Vương được xem là danh hiệu cao nhất, là một bậc tiến hóa tối thượng mà một Ma Vật có thể đạt được, chỉ xếp sau Long Chủng