跳转到内容

模組:Articles by Quality and Importance/sandbox

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

这是本页的一个历史版本,由D2F0F5留言 | 贡献2015年2月13日 (五) 06:41编辑。这可能和当前版本存在着巨大的差异。

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

local classList = {	
	{'fa', '特色'},
	{'a', '甲'},
	{'ga', '优良'},
	{'b', '乙'},
	{'c', '丙'},
	{'start', '初'},
	{'stub', '小作品'},
	{'fl', '特色列表'},
	{'list', '列表'},
	{'category', '分类'},
	{'disambig', '消歧义'},
	{'file', '文件'},
	{'portal', '主题'},
	{'project', '专题'},
	{'template', '模板'},
	{'na', '不适用'},
	{'unassessed', '未评'}
}
local importanceList = {
	{'top', '极高'},
	{'high', '高'},
	{'mid', '中'},
	{'low', '低'},
	{'na', '不适用'},
	{'unknown', '未知'}
}
local classExtendedList = { 'category', 'disambig', 'file', 'portal', 'project', 'template' }

local function number(args, i, j)
	local l = mw.language.new( 'zh' )
	return l:formatNum( tonumber( args[i ..'_' ..j] or '0' ) )
end

local p = {}

function p.main(frame)
	local args = getArgs(frame, {
		valueFunc = function (key, value)
			if value == '' then
				return nil
			else
				return value
			end
		end
	})

	for i, v in ipairs( classList ) do
		if yesno( args[v[1] .. '_'] ) ~= false then
			for j, w in ipairs( importanceList ) do
				if yesno( args['_' .. w[1]] ) ~= false then
					args[v[1] .. '_total'] = ( args[v[1] .. '_total'] or '0' ) + ( args[v[1] .. '_' .. w[1]] or '0' )
					args['total_' .. w[1]] = ( args['total_' .. w[1]] or '0' ) + ( args[v[1] .. '_' .. w[1]] or '0' )
				end
			end
		end
	end
	
	return p._main(args)
end
 
function p._main(args)
	
	local tablebody = ''
	
	for i, v in ipairs( classList ) do
		if args[v[1] .. '_'] ~= false then
			if args[v[1] .. 'total'] ~= 0 then
				for j, w in ipairs( importanceList ) do
					if args['_' .. w[1]] ~= false then
						if args['total_' .. w[1]] ~= 0 then
							tablebody = tablebody .. number(args, v[1], w[1]) .. '\t'
						end
					end
				end
				tablebody = tablebody .. number(args, v[1], 'total' )
				tablebody = tablebody .. '<br />'
			end
		end
	end
	

	return tablebody
	-- Main module code goes here.
end
 
return p