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 [[:en: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 được bảo vệ"
		elseif titleObj.namespace == 828 then
			protCatName = "Mô đun phụ thuộc vào mô đun được bảo vệ"
		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
Review Phim:
Review Phim: "Gia Tài Của Ngoại" - Khi "Thời Gian" Hóa Thành "Vàng Bạc"
Chắc hẳn, dạo gần đây, "How to Make Millions Before Grandma Dies" hay "หลานม่า" (Lahn Mah) đã trở thành cơn sốt điện ảnh Đông Nam Á
Top quán kem ngon nổi tiếng TP.HCM giải nhiệt cuối tuần
Top quán kem ngon nổi tiếng TP.HCM giải nhiệt cuối tuần
Kem là một trong những món ăn yêu thích của mọi thế hệ. Đó là lý do mà thế giới kem tại thị trường Việt Nam phát triển rất nhanh và nhiều thương hiệu lớn thế giới cũng có mặt. Dưới đây là top những thương hiệu đang dẫn đầu tại Việt Nam.
Oxytocin - Hormone của tình yêu, lòng tốt và sự tin tưởng
Oxytocin - Hormone của tình yêu, lòng tốt và sự tin tưởng
Trong bài viết này, mình muốn giới thiệu đến các bạn một hormone đại diện cho thứ cảm xúc
Violet Evergarden - Full Anime + Light Novel + Ova
Violet Evergarden - Full Anime + Light Novel + Ova
Đây là câu chuyện kể về người con gái vô cảm trên hành trình tìm kiếm ý nghĩa của tình yêu