跳转到内容

模組:Articles by Quality and Importance/sandbox

维基百科,自由的百科全书

这是本页的一个历史版本,由Where was I last night?留言 | 贡献2016年5月6日 (五) 18:03编辑。这可能和当前版本存在着巨大的差异。

require('Module:No globals')

local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')

local classList = {
	
	{'fa', score = 10},
	{'a', score = 9},
	{'ga', score = 8},
	{'bplus', score = 7.9, disabled = true},
	{'b', score = 7},
	{'c', score = 5},
	{'start', score = 3},
	{'stub', score = 1},
	
	{'fl', score = 10},
	{'al', score = 9, disabled = true},
	{'bl', score = 7, disabled = true},
	{'cl', score = 5, disabled = true},
	{'list', score = 3},
	{'sl', score = 1, disabled = true},
	
	{'category'},
	{'disambig'},
	{'draft'},
	{'file',},
	{'portal'},
	{'project'},
	{'template'},
	{'na'},
	{'unassessed', score = 0},

}

local importanceList = {
	{'top'},
	{'high'},
	{'mid'},
	{'low'},
	{'bottom', disabled = true},
	{'no', disabled = true},
	{'na'},
	{'unknown'},
}

local function getClassName(class, writingSystem)
	if class == 'ALL' then return '' end
	return require('Module:Class/convert')._main({class, writingSystem}) .. (writingSystem == 'trad' and '級' or '级')
end

local function getImportanceName(importance, writingSystem)
	if importance == 'ALL' then return '' end
	return require('Module:Importance/convert')._main({importance, writingSystem}) .. '重要度'
end

local function categoryName(args, class, importance)
	local categoryNamingFormat
	local writingSystem = yesno(args.trad) and 'trad' or 'simp'
	
	if args.format == 'ICT' then
		categoryNamingFormat = getImportanceName(importance, writingSystem) .. getClassName(class, writingSystem)
	else
		categoryNamingFormat = getClassName(class, writingSystem) .. getImportanceName(importance, writingSystem)
	end
	
	return string.format('%s%s%s', categoryNamingFormat, args.project, writingSystem == 'trad' and '條目' or '条目')
end

local function pageNumberOfClassAndImportance(args, class, importance)
	
	if tonumber(args[class..'_'..importance]) then
		return tonumber(args[class..'_'..importance])
	end
	
	return tonumber(mw.site.stats.pagesInCategory( categoryName(args, class, importance), 'pages' ))
end

local function pageNumberWithLink(args, class, importance)
	local pageNumber = mw.language.new('zh'):formatNum(pageNumberOfClassAndImportance(args, class, importance))
	
	if yesno(args.displayZero) == true and pageNumber == 0 then
		return
	end
	
	if yesno(args.link) == false then
		return pageNumber
	end
	
	if args.link == 'catscan' then
		-- 等会再做
	end
	
	if args.link == 'catscan_main' then
		-- 等会再做
	end
	
	if args.link == 'bluelinkonly' then
		if mw.title.makeTitle('Category', categoryName(args, class, importance)).exists then
			return string.format('[[:Category:%s|%s]]', categoryName(args, class, importance), pageNumber)
		end
		return 
	end
	
	return string.format('[[:Category:%s|%s]]', categoryName(args, class, importance), pageNumber)
	
end

local p = {}

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	
	for i, v in ipairs(classList) do
		if yesno(args[v[1] .. '_']) == false then
			v.disabled = true
		elseif yesno(args[v[1] .. '_']) == true then
			v.disable = false
		end
	end

	for i, v in ipairs(importanceList) do
		if yesno(args['_' .. v[1]]) == false then
			v.disabled = true
		elseif yesno(args['_' .. v[1]]) == true then
			v.disable = false
		end
	end

	for i, v in ipairs(class) do
		if v.disabled ~= false then
			for j, w in ipairs(importance) do
				if w.disabled ~= false then
					args[v .. '_' .. w] = pagesNumberOfClassAndImportance(args, v[1], w[1])
					args[v .. '_ALL'] = (args[v .. '_ALL'] or 0) + args[v .. '_' .. w]
					args['ALL_' .. w] = (args['ALL_' .. w] or 0) + args[v .. '_' .. w]
				end
			end
		end
	end
	
	
	return pageNumberWithLink(args, args[1], args[2])
end

return p