Mô đun:CountVotes
Tài liệu mô đun[tạo]
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)
end
local function isNegativeVote(templateName)
return TableTools.inArray(negativeVoteTemplateNames, templateName)
end
function 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, negativeVotesNumber
end
return p
Wiki - Keonhacai copa chuyên cung cấp kiến thức thể thao, keonhacai tỷ lệ kèo, bóng đá, khoa học, kiến thức hằng ngày được chúng tôi cập nhật mỗi ngày mà bạn có thể tìm kiếm tại đây có nguồn bài viết: https://vi.wikipedia.org/wiki/M%C3%B4_%C4%91un:CountVotes