Bước tới nội dung

Mô đun:CountVotes/sandbox

Bách khoa toàn thư mở Wikipedia
local TableTools = require('Module:TableTools')local p = {}local positiveVoteTemplateNames = {	'ok', 'agree', 'support',	'đồng ý', 'tán thành', 'ủng hộ',	'phiếu xóa', 'bqx', 'phiếu xóa nhanh', 'phiếu xoá nhanh', 'bqxn'}local negativeVoteTemplateNames = {	'ok?', 'disagree', 'oppose',	'phản đối', 'chưa đồng ý', 'phản đối mạnh', 'phản đối kịch liệt',	'phiếu giữ', 'bqg', 'phiếu giữ nhanh', 'bqgn',	'chống', 'giữ'}local function isPositiveVote(templateName)	return TableTools.inArray(positiveVoteTemplateNames, templateName)endlocal function isNegativeVote(templateName)	return TableTools.inArray(negativeVoteTemplateNames, templateName)endfunction p._main(title)	local positiveVotesNumber, negativeVotesNumber = 0, 0	if (title or {}).exists then		local content = title:getContent()		for line in string.gmatch(content, '([^\n]+)') do			local match = line:match('^[#*]:?%s-{{([^|]-)}}')					or line:match('^[#*]:?<li%s-value=.?%d.?>{{([^|]-)}}')			if match then				match = mw.ustring.lower(mw.text.trim(match))				if isPositiveVote(match) then					positiveVotesNumber = positiveVotesNumber + 1				elseif isNegativeVote(match) then					negativeVotesNumber = negativeVotesNumber + 1				end			end		end	end	return positiveVotesNumber, negativeVotesNumberendfunction p.positive(frame)	local titleText = frame.args[1] or mw.title.getCurrentTitle().fullText	local title = mw.title.new(titleText)	local pos, _ = p._main(title)	return tostring(pos)endfunction p.negative(frame)	local titleText = frame.args[1] or mw.title.getCurrentTitle().fullText	local title = mw.title.new(titleText)	local _, neg = p._main(title)	return tostring(neg)endreturn p