「模組:修訂追蹤」:修訂間差異
外觀
建立內容為「local p = {} function p.display() local frame = mw.getCurrentFrame() local dataPage = '維基百科:修訂追蹤資料庫' local content = mw.title.new(dataPage):getContent() or '' local rows = {} for line in mw.text.gsplit(content, '\n') do local title, user, date = string.match(line, '{{(.-)|([^|]+)|([^}]+)}}') if title and user and date then table.insert(rows, string.format('|-\n| %s || User:%s || %…」的新頁面 |
無編輯摘要 |
||
(未顯示同一使用者於中間所作的 2 次修訂) | |||
第1行: | 第1行: | ||
local p = {} | local p = {} | ||
function p.display(frame) | |||
-- 除錯:檢查frame | |||
if not frame then | |||
return "錯誤:沒有frame參數" | |||
end | |||
local dataPage = 'Project:修訂追蹤資料庫' | |||
-- 除錯:檢查頁面 | |||
local title = mw.title.new(dataPage) | |||
if not title then | |||
return "錯誤:無法創建title物件,頁面名稱:" .. dataPage | |||
end | |||
if not title.exists then | |||
return "錯誤:頁面不存在:" .. dataPage | |||
end | |||
-- 除錯:檢查內容 | |||
local content = title:getContent() | |||
if not content then | |||
return "錯誤:無法獲取頁面內容" | |||
end | |||
if content == '' then | |||
return "頁面內容為空" | |||
end | |||
-- 除錯:顯示原始內容(前100字符) | |||
local debug_content = string.sub(content, 1, 100) | |||
local rows = {} | local rows = {} | ||
local line_count = 0 | |||
local match_count = 0 | |||
-- 解析內容 | |||
for line in mw.text.gsplit(content, '\n') do | for line in mw.text.gsplit(content, '\n') do | ||
local | line_count = line_count + 1 | ||
line = mw.text.trim(line) | |||
if line ~= '' then | |||
local title_name, user, date = string.match(line, '{{([^|]+)|([^|]+)|([^}]+)}}') | |||
if title_name and user and date then | |||
match_count = match_count + 1 | |||
title_name = mw.text.trim(title_name) | |||
user = mw.text.trim(user) | |||
date = mw.text.trim(date) | |||
table.insert(rows, string.format('|-\n| [[%s]] || [[User:%s|%s]] || %s', | |||
title_name, user, user, date)) | |||
end | |||
end | end | ||
end | end | ||
-- 除錯資訊 | |||
local debug_info = string.format("除錯資訊:處理了%d行,找到%d個匹配<br/>", line_count, match_count) | |||
debug_info = debug_info .. "內容開頭:" .. debug_content .. "<br/><br/>" | |||
-- 如果沒有找到任何資料 | |||
if #rows == 0 then | |||
return debug_info .. "目前沒有修訂追蹤資料。" | |||
end | |||
-- 建立表格 | |||
local header = '{| class="wikitable sortable"\n! 條目 !! 參與者 !! 起始日期\n' | local header = '{| class="wikitable sortable"\n! 條目 !! 參與者 !! 起始日期\n' | ||
local footer = '\n|}' | local footer = '\n|}' | ||
return header .. table.concat(rows, '\n') .. footer | |||
return debug_info .. header .. table.concat(rows, '\n') .. footer | |||
end | end | ||
-- 簡單測試函數 | |||
function p.test(frame) | |||
return "模組正常運作!frame參數:" .. tostring(frame) | |||
end | |||
return p |
於 2025年8月20日 (三) 00:24 的最新修訂
可在模組:修訂追蹤/doc建立此模組的說明文件
local p = {}
function p.display(frame)
-- 除錯:檢查frame
if not frame then
return "錯誤:沒有frame參數"
end
local dataPage = 'Project:修訂追蹤資料庫'
-- 除錯:檢查頁面
local title = mw.title.new(dataPage)
if not title then
return "錯誤:無法創建title物件,頁面名稱:" .. dataPage
end
if not title.exists then
return "錯誤:頁面不存在:" .. dataPage
end
-- 除錯:檢查內容
local content = title:getContent()
if not content then
return "錯誤:無法獲取頁面內容"
end
if content == '' then
return "頁面內容為空"
end
-- 除錯:顯示原始內容(前100字符)
local debug_content = string.sub(content, 1, 100)
local rows = {}
local line_count = 0
local match_count = 0
-- 解析內容
for line in mw.text.gsplit(content, '\n') do
line_count = line_count + 1
line = mw.text.trim(line)
if line ~= '' then
local title_name, user, date = string.match(line, '{{([^|]+)|([^|]+)|([^}]+)}}')
if title_name and user and date then
match_count = match_count + 1
title_name = mw.text.trim(title_name)
user = mw.text.trim(user)
date = mw.text.trim(date)
table.insert(rows, string.format('|-\n| [[%s]] || [[User:%s|%s]] || %s',
title_name, user, user, date))
end
end
end
-- 除錯資訊
local debug_info = string.format("除錯資訊:處理了%d行,找到%d個匹配<br/>", line_count, match_count)
debug_info = debug_info .. "內容開頭:" .. debug_content .. "<br/><br/>"
-- 如果沒有找到任何資料
if #rows == 0 then
return debug_info .. "目前沒有修訂追蹤資料。"
end
-- 建立表格
local header = '{| class="wikitable sortable"\n! 條目 !! 參與者 !! 起始日期\n'
local footer = '\n|}'
return debug_info .. header .. table.concat(rows, '\n') .. footer
end
-- 簡單測試函數
function p.test(frame)
return "模組正常運作!frame參數:" .. tostring(frame)
end
return p