Module:Talkpage
外观
本模塊用於統計討論頁上各位用戶的發言次數。目前不支持DYK等投票頁或VIP等比較特殊的討論頁面。另外,請不要用Flow來欺負我這個電腦高級中手。
{{ #invoke:talkpage | analyse | Project:互助客栈 }}
效果()
| 用戶 | 發言次數 | 最後發言時間 |
|---|---|---|
| MediaWiki message delivery | 6 | 2026年4月27日 (一) 22:52 (UTC) |
| Xhs44444100 | 1 | 2025年4月14日 (一) 10:50 (UTC) |
| Ian7909 | 4 | 2025年11月16日 (日) 01:16 (UTC) |
| 魔琴 | 1 | 2025年10月17日 (五) 23:33 (UTC) |
| Example | 2 | 2026年1月19日 (一) 21:02 (UTC) |
| W0900246517 | 7 | 2024年6月2日 (日) 14:13 (UTC) |
| & | 1 | 2026年5月8日 (五) 01:35 (UTC) |
| Sheminghui.WU | 1 | 2025年11月19日 (三) 08:37 (UTC) |
| Aqurs1 | 1 | 2025年2月20日 (四) 04:40 (UTC) |
| S8321414 | 3 | 2025年12月4日 (四) 05:06 (UTC) |
| 鐵路1 | 4 | 2025年12月5日 (五) 03:54 (UTC) |
| TimFlew | 3 | 2026年1月11日 (日) 02:09 (UTC) |
| Srapoj | 1 | 2025年9月11日 (四) 13:09 (UTC) |
| Hehua | 6 | 2025年3月3日 (一) 14:50 (UTC) |
| HCCB3947 | 2 | 2026年2月3日 (二) 04:00 (UTC) |
| EasonWYC | 1 | 2025年10月19日 (日) 12:26 (UTC) |
| Ericliu1912 | 12 | 2026年3月1日 (日) 17:51 (UTC) |
| Hk97701 | 2 | 2025年9月7日 (日) 01:40 (UTC) |
| ChasingAir | 28 | 2026年2月24日 (二) 09:26 (UTC) |
| LuciferianThomas | 5 | 2026年2月24日 (二) 09:38 (UTC) |
| Sannita (WMF) | 1 | 2025年11月20日 (四) 14:23 (UTC) |
| Ppolar bear | 5 | 2026年1月8日 (四) 01:14 (UTC) |
| Patlabor Ingram | 1 | 2025年2月26日 (三) 16:04 (UTC) |
| スーパー特急 | 1 | 2025年1月11日 (六) 09:43 (UTC) |
| UOzurumba (WMF) | 1 | 2025年9月30日 (二) 02:08 (UTC) |
其中User:Example是未能判斷出名字的用戶,例如簽名格式很不標準等。
如果只關心某一具體話題,可以
{{ #invoke:talkpage | analyse | Project:互助客栈/条目探讨 | topic=某一話題}}
注意不支持簡繁轉換。
其他參數
[编辑源代码]- topic:只統計某個話題。如果標題相同(或者多個標題被匹配),那麼這些話題都會被統計進去。
- ispattern:表示topic是一個lua的匹配字符串。請不要加括號。
- userlink、ipuserlink:指定用戶名的樣式,其中「$USER」會被換為真正的用戶名。例如{{User|$USER}}。
- type:可取user、topic和all。默認為user,即只統計各用戶的發言情況。
topic的表頭如下:
| 主題 | 發言次數 | 參與者人數 | 發起人 | 最後發言者 | 最後發言時間 |
|---|---|---|---|---|---|
| Upcoming Dark Mode user interface rollout for anonymous Wikimedia sites users | 2 | 2 | UOzurumba (WMF) | EasonWYC | 2025年10月19日 (日) 12:26 (UTC) |
| 修订删除方针-快速删除 | 4 | 2 | ChasingAir | ChasingAir | 2025年12月28日 (日) 06:40 (UTC) |
| Request for comment (global AI policy) | 1 | 1 | MediaWiki message delivery | MediaWiki message delivery | 2026年4月26日 (日) 00:58 (UTC) |
| 对User:黄霖莉贡献的事实核查 | 4 | 3 | ChasingAir | Ericliu1912 | 2026年3月1日 (日) 17:51 (UTC) |
| Reminder: Help us decide the name of the new Abstract Wikipedia project | 1 | 1 | Sannita (WMF) | Sannita (WMF) | 2025年11月20日 (四) 14:23 (UTC) |
| 呼吁维基学院订立明确的收录标准 | 5 | 4 | Patlabor Ingram | Ericliu1912 | 2025年9月6日 (六) 15:43 (UTC) |
| 通用行為準則執行規範的年度審查 | 1 | 1 | Example | Example | 2026年1月19日 (一) 21:02 (UTC) |
| 台灣分會2026年2月對話時間 | 1 | 1 | MediaWiki message delivery | MediaWiki message delivery | 2026年2月25日 (三) 22:25 (UTC) |
| 台灣分會2026年4月對話時間 | 1 | 1 | MediaWiki message delivery | MediaWiki message delivery | 2026年4月27日 (一) 22:52 (UTC) |
| 台灣分會2026年1月對話時間 | 1 | 1 | MediaWiki message delivery | MediaWiki message delivery | 2026年1月25日 (日) 00:28 (UTC) |
| 用戶名方針修訂 | 3 | 2 | Ppolar bear | Ppolar bear | 2026年1月8日 (四) 01:14 (UTC) |
| 提议对跨维基导入进行相关修订 | 11 | 4 | ChasingAir | ChasingAir | 2025年12月28日 (日) 06:41 (UTC) |
| 編輯摘要 | 2 | 2 | Ericliu1912 | ChasingAir | 2025年12月6日 (六) 17:21 (UTC) |
| 提议设立Transwiki命名空间 | 10 | 4 | Hehua | 鐵路1 | 2025年3月6日 (四) 03:39 (UTC) |
| 車輛運用頁面無法編輯,無法即時更新現狀,請對正常權限編輯者開啟放編輯權限以利資訊更新,謝謝。 | 1 | 1 | Ian7909 | Ian7909 | 2025年11月9日 (日) 01:33 (UTC) |
| 刪除方針修訂 | 7 | 5 | Ppolar bear | ChasingAir | 2025年12月22日 (一) 17:20 (UTC) |
| 咨询原创性论文研究的提交办法 | 4 | 2 | HCCB3947 | ChasingAir | 2026年2月3日 (二) 13:24 (UTC) |
| 臨時帳號即將推出 | 1 | 1 | Example | Example | 2025年8月26日 (二) 21:36 (UTC) |
| 台灣分會2026年3月對話時間 | 1 | 1 | MediaWiki message delivery | MediaWiki message delivery | 2026年3月28日 (六) 06:28 (UTC) |
| 两个化学院 | 4 | 3 | TimFlew | ChasingAir | 2026年1月12日 (一) 05:15 (UTC) |
| 数学系需要定理的证明 | 2 | 2 | TimFlew | ChasingAir | 2025年12月6日 (六) 17:21 (UTC) |
| 提议设立收录标准与爱好者内容指引 | 12 | 5 | ChasingAir | ChasingAir | 2025年12月4日 (四) 04:55 (UTC) |
| 台灣分會2025年12月對話時間 | 1 | 1 | MediaWiki message delivery | MediaWiki message delivery | 2025年12月22日 (一) 18:57 (UTC) |
| 我是對客運車輛做最新的調整卻被當成是破壞封鎖該如何解決 | 1 | 1 | & | & | 2026年5月8日 (五) 01:35 (UTC) |
| 邀請參與確定Wikifunctions的中文譯名 | 1 | 1 | 魔琴 | 魔琴 | 2025年10月17日 (五) 23:33 (UTC) |
| 主題半保護 | 16 | 6 | LuciferianThomas | Ian7909 | 2025年11月16日 (日) 01:16 (UTC) |
| 部分内容过于繁杂,是否要分进不同页面 | 2 | 2 | TimFlew | ChasingAir | 2025年12月14日 (日) 07:23 (UTC) |
all的表頭如下:
| 主題 | 用戶 | 發言次數 | 最後發言時間 |
|---|---|---|---|
| Upcoming Dark Mode user interface rollout for anonymous Wikimedia sites users | EasonWYC | 1 | 2025年10月19日 (日) 12:26 (UTC) |
| UOzurumba (WMF) | 1 | 2025年9月30日 (二) 02:08 (UTC) | |
| 修订删除方针-快速删除 | Ppolar bear | 1 | 2025年12月12日 (五) 02:57 (UTC) |
| ChasingAir | 3 | 2025年12月28日 (日) 06:40 (UTC) | |
| Request for comment (global AI policy) | MediaWiki message delivery | 1 | 2026年4月26日 (日) 00:58 (UTC) |
| 对User:黄霖莉贡献的事实核查 | ChasingAir | 1 | 2026年2月24日 (二) 09:26 (UTC) |
| LuciferianThomas | 2 | 2026年2月24日 (二) 09:38 (UTC) | |
| Ericliu1912 | 1 | 2026年3月1日 (日) 17:51 (UTC) | |
| Reminder: Help us decide the name of the new Abstract Wikipedia project | Sannita (WMF) | 1 | 2025年11月20日 (四) 14:23 (UTC) |
| 呼吁维基学院订立明确的收录标准 | S8321414 | 1 | 2025年8月13日 (三) 08:15 (UTC) |
| Patlabor Ingram | 1 | 2025年2月26日 (三) 16:04 (UTC) | |
| Xhs44444100 | 1 | 2025年4月14日 (一) 10:50 (UTC) | |
| Ericliu1912 | 2 | 2025年9月6日 (六) 15:43 (UTC) | |
| 通用行為準則執行規範的年度審查 | Example | 1 | 2026年1月19日 (一) 21:02 (UTC) |
| 台灣分會2026年2月對話時間 | MediaWiki message delivery | 1 | 2026年2月25日 (三) 22:25 (UTC) |
| 台灣分會2026年4月對話時間 | MediaWiki message delivery | 1 | 2026年4月27日 (一) 22:52 (UTC) |
| 台灣分會2026年1月對話時間 | MediaWiki message delivery | 1 | 2026年1月25日 (日) 00:28 (UTC) |
| 用戶名方針修訂 | ChasingAir | 1 | 2025年12月16日 (二) 02:26 (UTC) |
| Ppolar bear | 2 | 2026年1月8日 (四) 01:14 (UTC) | |
| 提议对跨维基导入进行相关修订 | Srapoj | 1 | 2025年9月11日 (四) 13:09 (UTC) |
| ChasingAir | 6 | 2025年12月28日 (日) 06:41 (UTC) | |
| LuciferianThomas | 1 | 2025年9月9日 (二) 05:52 (UTC) | |
| Ericliu1912 | 3 | 2025年9月11日 (四) 18:55 (UTC) | |
| 編輯摘要 | ChasingAir | 1 | 2025年12月6日 (六) 17:21 (UTC) |
| Ericliu1912 | 1 | 2025年12月4日 (四) 11:04 (UTC) | |
| 提议设立Transwiki命名空间 | Aqurs1 | 1 | 2025年2月20日 (四) 04:40 (UTC) |
| Ericliu1912 | 1 | 2025年2月13日 (四) 12:47 (UTC) | |
| 鐵路1 | 2 | 2025年3月6日 (四) 03:39 (UTC) | |
| Hehua | 6 | 2025年3月3日 (一) 14:50 (UTC) | |
| 車輛運用頁面無法編輯,無法即時更新現狀,請對正常權限編輯者開啟放編輯權限以利資訊更新,謝謝。 | Ian7909 | 1 | 2025年11月9日 (日) 01:33 (UTC) |
| 刪除方針修訂 | ChasingAir | 3 | 2025年12月22日 (一) 17:20 (UTC) |
| Ericliu1912 | 1 | 2025年11月28日 (五) 09:57 (UTC) | |
| S8321414 | 1 | 2025年12月4日 (四) 05:06 (UTC) | |
| 鐵路1 | 1 | 2025年12月5日 (五) 03:54 (UTC) | |
| Ppolar bear | 1 | 2025年11月28日 (五) 08:31 (UTC) | |
| 咨询原创性论文研究的提交办法 | ChasingAir | 2 | 2026年2月3日 (二) 13:24 (UTC) |
| HCCB3947 | 2 | 2026年2月3日 (二) 04:00 (UTC) | |
| 臨時帳號即將推出 | Example | 1 | 2025年8月26日 (二) 21:36 (UTC) |
| 台灣分會2026年3月對話時間 | MediaWiki message delivery | 1 | 2026年3月28日 (六) 06:28 (UTC) |
| 两个化学院 | ChasingAir | 2 | 2026年1月12日 (一) 05:15 (UTC) |
| Ericliu1912 | 1 | 2026年1月12日 (一) 03:52 (UTC) | |
| TimFlew | 1 | 2026年1月11日 (日) 02:09 (UTC) | |
| 数学系需要定理的证明 | ChasingAir | 1 | 2025年12月6日 (六) 17:21 (UTC) |
| TimFlew | 1 | 2025年12月6日 (六) 14:15 (UTC) | |
| 提议设立收录标准与爱好者内容指引 | ChasingAir | 7 | 2025年12月4日 (四) 04:55 (UTC) |
| Ppolar bear | 1 | 2025年11月27日 (四) 10:50 (UTC) | |
| Sheminghui.WU | 1 | 2025年11月19日 (三) 08:37 (UTC) | |
| S8321414 | 1 | 2025年11月19日 (三) 02:09 (UTC) | |
| Ericliu1912 | 2 | 2025年11月19日 (三) 07:38 (UTC) | |
| 台灣分會2025年12月對話時間 | MediaWiki message delivery | 1 | 2025年12月22日 (一) 18:57 (UTC) |
| 我是對客運車輛做最新的調整卻被當成是破壞封鎖該如何解決 | & | 1 | 2026年5月8日 (五) 01:35 (UTC) |
| 邀請參與確定Wikifunctions的中文譯名 | 魔琴 | 1 | 2025年10月17日 (五) 23:33 (UTC) |
| 主題半保護 | Hk97701 | 2 | 2025年9月7日 (日) 01:40 (UTC) |
| Ian7909 | 3 | 2025年11月16日 (日) 01:16 (UTC) | |
| 鐵路1 | 1 | 2025年2月4日 (二) 01:37 (UTC) | |
| スーパー特急 | 1 | 2025年1月11日 (六) 09:43 (UTC) | |
| LuciferianThomas | 2 | 2023年11月27日 (一) 03:45 (UTC) | |
| W0900246517 | 7 | 2024年6月2日 (日) 14:13 (UTC) | |
| 部分内容过于繁杂,是否要分进不同页面 | ChasingAir | 1 | 2025年12月14日 (日) 07:23 (UTC) |
| TimFlew | 1 | 2025年12月14日 (日) 01:49 (UTC) |
其他函數
[编辑源代码]lastsign
[编辑源代码]獲取最後一個發言的人。例如:
{{ #invoke:talkpage | lastsign | Project:互助客栈 }}
效果():& 2026年5月8日 (五) 01:35 (UTC)
同樣支持上面提到的各個參數。
lastname和lastdate
[编辑源代码]只顯示最後發言人的名字或日期。
count和countuser
[编辑源代码]顯示簽名和簽名者的數量。count函數支持user參數,即只顯示特定用戶的簽名數量。
示例一:
[[User:WQL]]的簽名檔上已經有{{ #invoke:talkpage | count | User Talk:WQL }}個能被識別出來的簽名,這是由{{ #invoke:talkpage | countuser | User Talk:WQL }}位用戶簽出來的。
效果:
User:WQL的簽名檔上已經有1個能被識別出來的簽名,這是由1位用戶簽出來的。
示例二:
Cohaf在WQL的討論頁上發了{{ #invoke:talkpage | count | User talk:WQL | user=Cohaf }}個留言。
效果:
Cohaf在WQL的討論頁上發了0個留言。
已知bug
[编辑源代码]- 目前不支持DYK等投票頁,還有VIP這種標題比較特殊的頁面。
- 程序只是簡單地進行字符串識別。如果有人簽名格式不標準,或者故意搗蛋(例如[1]),程序自然會出bug。
- 未簽名的話肯定不會被統計進去。這個沒法修復。
- 如果有人在六四清場正式開始之前在討論頁上發言,那麼lastsign函數肯定不會顯示他的名字。
local f = {}
f.DATEPATTERN = '(%d-)年(%d-)月(%d-)日 %([一二三四五六日]-%) (%d-):(%d-) %(UTC%)'
f.USERPREFIX = {
'user:', '用戶:', '用户:', '使用者:', 'u:', 'U:',
'user talk:', 'user_talk:', '用戶討論:', '用户讨论:', '使用者討論:', 'ut:','UT:','Ut:',
'special:用户贡献/', 'special:contributions/', 'special:用戶貢獻/', 'special:使用者貢獻/',
'特殊:用户贡献/', '特殊:用戶貢獻/', '特殊:使用者貢獻/', '特殊:contributions/'
}
f.MINDATE = '1989年6月3日 (六) 13:00 (UTC)'
f.MAXDATE = '9999年12月31日 (六) 23:59 (UTC)'
--- 反序尋找字符串
local function rfind(s, pattern, init)
local x, y
local i = init or #s
local len = #s
x, y = string.find(string.reverse(s), string.reverse(pattern), len-i+1, true)
if x then
return len-y+1, len-x+1
end
end
--- 生成用戶名鏈接。默認是指向用戶頁(IP用戶為貢獻頁)的鏈接。
-- @param name 用戶名
-- @param style 自定義樣式,其中$USER會被換成用戶名。
-- @param ipstyle IP用戶的自定義樣式。若未指定則與style相同。
-- @return 維基格式的用戶名鏈接
local function getuserlink(name, style, ipstyle)
if string.find(name, '^%d-%.%d-%.%d-%.%d-$') then
return string.gsub(ipstyle or style or '[[Special:用户贡献/$USER|$USER]]', '$USER', name)
else
return string.gsub(style or '[[User:$USER|$USER]]', '$USER', name)
end
end
--- TODO 去除掉影響分析的文字,例如「===」、「<pre>」等
-- @param orintext 原始討論串。
-- @return 經過預處理之後的討論串。去掉一些搗亂的內容。
local function preprocess(orintext, titlelevel)
local text = orintext
text = string.gsub(text, titlelevel .. '=', '---')
text = string.gsub(text, '<pre>.-</pre>', '')
text = string.gsub(text, '<nowiki>.-</nowiki>', '')
text = string.gsub(text, '{{移動至|.-}}', '')
text = string.gsub(text, '{{talkback|.-}}', '')
text = string.gsub(text, '{{deltalk|.-}}', '')
text = string.gsub(text, '{{移动自|.-}}', '')
return text
end
--- 從長長的討論串中找到特定主題。如果未指定主題則將所有主題分割開並存入table中。
-- @param orintext 原始討論串。
-- @param topic 待提取的主題。未指定的話則改為分割所有主題。
-- @param ispattern 表示topic是否為lua的匹配字符串。
-- @return 返回一個鍵為討論標題值為討論內容的table。如果沒有則返回nil。
local function extracttopic(args)
local orintext = args.text
local topic = args.topic
local ispattern = args.ispattern
local titlelevel = args.titlelevel=='3' and '===' or '=='
-- 預處理
local text = titlelevel .. '\n\n' .. preprocess(orintext, titlelevel) .. '\n' .. titlelevel
local result = {}
local found = nil
local topic2 = topic and mw.text.trim(topic)
for title, content in string.gmatch(text, '[ ]*(.-)[ ]*'..titlelevel..'[ ]*\n(.-)\n'..titlelevel) do
local ok = false
if topic2 and (not ispattern) and title == topic2 then
ok = true
elseif topic2 and ispattern and (string.match(title, topic2)) then
ok = true
elseif not topic2 then
ok = true
end
if ok then
found = true
local temptitle = title
local i = 1
while result[temptitle] do
i = i + 1
temptitle = title .. ' (' .. i .. ')'
end
result[temptitle] = content
end
end
return found and result
end
--- 將討論串上的日期轉為一個數字。
-- @param date 討論串格式的日期。
-- @return 將數字直接拼起來。不是時間戳。
local function date2num(date)
local y,m,d,h,min = string.gmatch(date, f.DATEPATTERN)()
if y and m and d and h and min then
return y*100000000+m*1000000+d*10000+h*100+min
else
return 0
end
end
--- 比較兩個日期的大小。
-- @param date1
-- @param date2
-- @return 若date1<date2則返回true。
local function comparedate(date1, date2)
return date2num(date1) < date2num(date2)
end
--- 統計討論串中各個簽名的次數和最後發言時間。
-- @param orintext 原始討論串
-- @return @todo TODO 需要重寫
function f._count(orintext)
-- 預處理
local text = '\n' .. orintext
local lowertext = string.lower(text)
-- 尋找日期
local result = {}
local x, y
y = 1
repeat
x, y = text.find(text, f.DATEPATTERN, y+1)
if not x then
break
end
local date = string.sub(text, x, y)
-- 截取當前行以便於尋找用戶名
local t1, t2 = rfind(text, '\n', x)
local curtalk = string.sub(lowertext, t1, x-1)
-- 尋找用戶名
local name = nil
for i, v in ipairs(f.USERPREFIX) do
local t3, t4 = rfind(curtalk, '[[' .. v)
if t4 then
local t5 = (string.find(curtalk, '[/#|%]]', t4))
if t5 then
-- 確定用戶名
name = string.sub(text, t1+t4, t1+t5-2)
-- 首字母大寫
local firstletter = string.byte(name, 1, 1)
if firstletter >= 97 and firstletter <=122 then
name = string.upper(string.sub(name, 1, 1)) .. string.sub(name, 2, -1)
end
break
end
end
end
name = name or 'Example'
if not result[name] then
result[name] = {count = 1, firstdate = date, lastdate = date}
else
result[name].count = result[name].count + 1
if comparedate(result[name].lastdate, date) then
result[name].lastdate = date
end
if comparedate(date, result[name].firstdate) then
result[name].firstdate = date
end
end
until false
return result
end
local function maketable(counttable, args)
local tabletype = args.tabletype and mw.text.trim(args.tabletype) or 'user'
local top = '{| class="wikitable sortable"\n|-'
local header
if tabletype == 'all' then
top = '{| class="wikitable"\n|-'
end
local result = { top }
if tabletype == 'topic' then
table.insert(result, '! 主題 !! 發言次數 !! 參與者人數 !! 發起人 !! 最後發言者 !! data-sort-type="number" | 最後發言時間')
for k, v in pairs(counttable.topics) do
if v.count > 0 then
table.insert(result, string.format('|-\n| %s || %s || %s || %s || %s || data-sort-value="%s" | %s',
k, v.count, v.usercount, getuserlink(v.firstname, args.userlink, args.ipuserlink),
getuserlink(v.lastname, args.userlink, args.ipuserlink), date2num(v.lastdate), v.lastdate))
end
end
elseif tabletype == 'topicsimple' then
table.insert(result, '! 主題 !! 發言次數 !! 最後發言者 !! data-sort-type="number" | 最後發言時間')
for k, v in pairs(counttable.topics) do
if v.count > 0 then
table.insert(result, string.format('|-\n| %s || %s || %s || data-sort-value="%s" | %s',
k, v.count, getuserlink(v.lastname, args.userlink, args.ipuserlink), date2num(v.lastdate), v.lastdate))
end
end
elseif tabletype == 'all' then
table.insert(result, '! 主題 !! 用戶 !! 發言次數 !! data-sort-type="number" | 最後發言時間')
for k, v in pairs(counttable.topics) do
if v.count > 0 then
local first = k .. ' || '
if v.usercount > 1 then
first = 'rowspan=' .. v.usercount .. ' | ' .. first
end
for k2, v2 in pairs(v.users) do
table.insert(result, string.format('|-\n| %s%s || %s || data-sort-value="%s" | %s',
first, getuserlink(k2, args.userlink, args.ipuserlink), v2.count, date2num(v2.lastdate), v2.lastdate))
first = ''
end
end
end
else
table.insert(result, '! 用戶 !! 發言次數 !! data-sort-type="number" | 最後發言時間')
for k, v in pairs(counttable.users) do
table.insert(result, string.format('|-\n| %s || %s || data-sort-value="%s" | %s', getuserlink(k, args.userlink, args.ipuserlink), v.count, date2num(v.lastdate), v.lastdate))
end
end
table.insert(result, '|}')
return table.concat(result, '\n')
end
--- 對簽名數據進行匯總
-- @param stat 通過count函數得到的統計數據
-- @return 一個table,發言數、發言人數、最後發言者、最後發言時間
local function getstat(data)
local count = 0
local usercount = 0
local lastdate = f.MINDATE
local lastname = nil
local firstdate = f.MAXDATE
local firstname = nil
for username, userinfo in pairs(data) do
count = count + userinfo.count
usercount = usercount + 1
if comparedate(lastdate, userinfo.lastdate) then
lastdate = userinfo.lastdate
lastname = username
end
if comparedate(userinfo.firstdate, firstdate) then
firstdate = userinfo.firstdate
firstname = username
end
end
return {
count = count,
usercount = usercount,
firstdate = firstdate,
firstname = firstname,
lastdate = lastdate,
lastname = lastname
}
end
--- 統計討論串中各個簽名的次數和最後發言時間。
-- @param args
-- @return
local function getcount(args)
local talk = string.gsub(args.text, '\r', '\n')
local userdata = {}
local result = { users = userdata, topics = {} }
local topics = extracttopic(args) or {}
for title, content in pairs(topics) do
local topicdata = f._count(content)
for username, userinfo in pairs(topicdata) do
local dat = userdata[username] or { count = 0, lastdate = f.MINDATE }
dat.count = dat.count + userinfo.count
dat.lastdate = comparedate(dat.lastdate, userinfo.lastdate) and userinfo.lastdate or dat.lastdate
userdata[username] = dat
end
result.topics[title] = getstat(topicdata)
result.topics[title].users = topicdata
end
return result
end
--- 獲取最後簽名。
-- @param args
-- @return 一個table,包含用戶名和日期。
local function getlastsign(args)
local r = getcount(args)
local lastname = nil
local lastdate = f.MINDATE
for k, v in pairs(r.users) do
if comparedate(lastdate, v.lastdate) then
lastname = k
lastdate = v.lastdate
end
end
return {name=lastname, date=lastdate}
end
--- 將維基百科模板上的參數轉為lua的table。
-- @param frame 維基百科模板上的參數。
-- @return 一個table,包括各個參數。
local function getargs(frame)
return {
text = mw.title.new(frame.args[1]):getContent(),
topic = frame.args.topic,
ispattern = frame.args.ispattern,
userlink = frame.args.userlink,
ipuserlink = frame.args.ipuserlink,
tabletype = frame.args.type,
titlelevel = frame.args.titlelevel
}
end
--- 統計討論頁發言情況。詳情見文檔頁。
-- @param frame 維基百科頁面名。
-- @return 一張表格。
function f.analyse(frame)
local args = getargs(frame)
return maketable(getcount(args), args)
end
--- 獲取最後一個發言的用戶。
-- @param frame 維基百科頁面名。
-- @return 一個用戶名,不使用鏈接。
function f.lastname(frame)
return getlastsign(getargs(frame)).name
end
--- 獲取最後一個發言的日期。
-- @param frame 維基百科頁面名。
-- @return 一個日期。
function f.lastdate(frame)
return getlastsign(getargs(frame)).date
end
--- 獲取最後一個簽名。
-- @param frame 維基百科頁面名。
-- @return 一個簽名鏈接附上一個日期。
function f.lastsign(frame)
local args = getargs(frame)
local lastsign = getlastsign(args)
if lastsign.name then
return string.format('%s %s', getuserlink(lastsign.name, args.userlink, args.ipuserlink), lastsign.date)
end
end
--- 統計簽名數量。
-- @param frame 維基百科頁面名。
-- @return 一個數字。
function f.count(frame)
local data = getcount(getargs(frame))
local username = frame.args.user and mw.text.trim(frame.args.user)
if not username then
local num = 0
for k, v in pairs(data.topics) do
num = num + v.count
end
return num
elseif data.users[username] then
return data.users[username].count
else
return 0
end
end
--- 統計簽名者數量。
-- @param frame 維基百科頁面名。
-- @return 一個數字。
function f.countuser(frame)
local data = getcount(getargs(frame)).users
local count = 0
for _ in pairs(data) do
count = count + 1
end
return count
end
-- 以下用於本地測試
--[[
f.countsigns = getcount
f.lastsign = getlastsign
f.maketable = maketable
]]
f.getcount = getcount
return f