local p = {}
local DuplicateBanners = function(text)
local capture = '<span class="wpb%-project">([%w%s]*)</span>'
local banners = {}
for project in text:gmatch(capture) do
if banners[project] == true then
return '[[Thể loại:Bài viết sử dụng bản mẫu Nhóm dự án có bản mẫu trùng lặp|' .. project .. ']]'
end
banners[project] = true
end
end
-- Hàm này dùng để viết hoa chữ cái đầu của pagetype
function firstToUpper(str)
return (str:gsub("^%l", string.upper))
end
local ofinterest = function(collapsed)
local wikiprojects = '[[Wikipedia:Dự án|tiểu dự án]]'
local text = ' thuộc phạm vi bảo hộ của '
if collapsed then
text = text .. 'nhiều ' .. wikiprojects .. '. Nhấn [hiện] để xem thêm chi tiết.'
else
text = text .. 'các ' .. wikiprojects .. ' sau đây:'
end
return text
end
p.main = function(frame)
local classmask = require('Mô đun:Class mask')
local readarticleclass = require('Mô đun:WikiProject banner').readarticleclass
local yesno = require('Mô đun:Yesno')
local args = frame:getParent().args
local class = classmask._main{args.class or ''}
local pagetype = require('Mô đun:Pagetype')._main{class=class}
local out = {}
if yesno(args.blp) or yesno(args.living) then
table.insert(out,frame:expandTemplate{title = 'BLP'})
elseif yesno(args.blpo) then
table.insert(out,frame:expandTemplate{title = 'BLP others'})
end
if yesno(args.activepol) then
table.insert(out, frame:expandTemplate{title = 'Active politician'})
end
local bhargs = {
templatestyles = 'Nhóm dự án/sandbox/styles.css',
collapsed = args.collapsed,
size = '32',
class = 'wpbs',
image = 'WikiProject Council with transparent background.svg',
alt = 'WikiProject Council',
image_link = 'Wikipedia:WikiProject Council'
}
local globalclass = false
if class == '' then -- check if class parameters is defined by any project banner
local articleclass = readarticleclass{ignore_blank=true, only_subtemplates=true}
if articleclass == '' then -- no class parameters are defined by any project banner, so globally unassessed
globalclass = true
end
else -- global class defined, so display it
globalclass = true
end
if globalclass then
local icon = require('Module:Class')._icon{class,size='35px'}
local header = '<td class="assess">' .. icon .. '</td><td class="banner-shell-header" style="text-align: left; font-weight: normal;">'
if args.category == 'no' then
header = header .. 'này '
else
header = header .. firstToUpper(pagetype) .. ' '
end
if class == '' then
header = header .. 'vẫn chưa được xếp hạng'
elseif class=='NA' then
header = header .. 'không cần được xếp hạng'
else
header = header .. 'được xếp hạng <span style="font-weight:bold;">chất lượng ' .. class .. '</span>'
end
header = header .. " trong mục [[Wikipedia:Đánh giá nội dung|đánh giá nội dung]] của Wikipedia.<br>"
if args[1] and args[1]~='' then
header = header .. firstToUpper(pagetype) .. ofinterest(yesno(args.collapsed))
else
if not args.category or args.category=='' then
if mw.title.getCurrentTitle().isTalkPage then
header = header .. '[[Thể loại:Bài viết ' .. (class=='' and 'Chưa được đánh giá' or (class .. '-Chất lượng')) .. ']]'
end
end
end
header = header .. '</td>'
bhargs.header = header
end
if args.header then
bhargs.text = args.header
else
bhargs.text = 'This ' .. pagetype .. ofinterest(yesno(args.collapsed))
end
bhargs[1] = args[1] or ''
table.insert(out,frame:expandTemplate{title='Banner holder', args=bhargs})
if args[1] and args[1]~='' then
local duplicate_cat = DuplicateBanners(args[1])
if duplicate_cat and mw.title.getCurrentTitle().isTalkPage then
table.insert(out, duplicate_cat)
end
elseif mw.title.getCurrentTitle().isTalkPage then
table.insert(out,'[[Thể loại:Bài viết sử dụng bản mẫu Nhóm dự án không có bản mẫu]]')
end
if args.listas and args.listas ~= '' then
table.insert(out,frame:preprocess('{{DEFAULTSORT:' .. args.listas .. '}}'))
end
return table.concat(out)
end
return p