Module:Topic list:修订间差异

添加383字节 、​ 2021年9月9日 (星期四)
无编辑摘要
imported>=海豚=
无编辑摘要
imported>850710247liu
无编辑摘要
 
(未显示3个用户的48个中间版本)
第1行: 第1行:
-- 中文Minecraft Wiki同名模块,原作者为Star00和MysticNebula70
-- 授权协议:CC BY-NC-SA 3.0
local p = {}
local p = {}


第13行: 第16行:
:gsub('用户', 'User')
:gsub('用户', 'User')
:gsub('user', 'User')
:gsub('user', 'User')
:gsub('UTC', 'CST')
return talk
return talk
end
end


function titleConv(talk)
function titleStrip(talk)
-- 论题转换
-- 论题转换
talk = talk
talk = talk
:gsub('===(.-)===', '%1')
return talk
end
function titleConv(title)
-- 论题转换
title = title
:gsub('<.->', '')
:gsub('<.->', '')
:gsub('%[%[', '')
:gsub('%[%[:?.-|(.-)%]%]', '%1')
:gsub('|.-%]%]', '')
:gsub('%[%[:?(.-)%]%]', '%1')
:gsub('%]%]', '')
return title
:gsub('^%s', '')
:gsub('%s$', '')
return talk
end
end


第47行: 第55行:


function getTimeStyle(time)
function getTimeStyle(time)
if time == '该讨论主题已被移动' then
return 'background-color: #fee;'
end
local _, _, year, month, day, hour, min = time:find '(%d+)年(%d+)月(%d+)日%s%(.-%)%s(%d+):(%d+)'
local _, _, year, month, day, hour, min = time:find '(%d+)年(%d+)月(%d+)日%s%(.-%)%s(%d+):(%d+)'


第76行: 第87行:
function trim(text)
function trim(text)
-- remove special strip markers and spaces
-- remove special strip markers and spaces
text = mw.text.killMarkers(text):gsub('^[\t\r\n\f]*(.-)[\t\r\n\f]*$', '%1')
text = mw.text.killMarkers(text):gsub('^[%s\t\r\n\f]*(.-)[%s\t\r\n\f]*$', '%1')
return text
return text
end
end


function makeUserLink(text)
function makeUserLink(text)
if text == '?' then
return text
end
-- 输入用户名以及带有ip:前缀的ip用户。
-- 输入用户名以及带有ip:前缀的ip用户。
local ipUser = text:match 'ip:(.*)'
local ipUser = text:match 'ip:(.*)'
第103行: 第117行:


function getTitleList(pageName)
function getTitleList(pageName)
local talk = conv(mw.getCurrentFrame():expandTemplate {title = ':' .. pageName})
local talk = titleStrip(mw.getCurrentFrame():expandTemplate {title = ':' .. pageName})
local titleList = {}
local titleList = {}
for title in talk:gmatch '==(.-)==' do
for title in talk:gmatch '==(.-)==' do
titleList[#titleList + 1] = title
titleList[#titleList + 1] = titleConv(trim(title))
end
end


第113行: 第127行:


function getTalkTime(talk)
function getTalkTime(talk)
local result = talk:match '[%s%S]*(%d%d%d%d.*) %(CST%)' or ' 未知日期'
local result = talk:match '[%s%S]*(%d%d%d%d.*) %(CST%)' or ' 该讨论主题已被移动'


return result
return result
第122行: 第136行:
local userList = {}
local userList = {}
if text:match '[^\n]*User:([^\n]-)%|[^\n]-CST' == nil then
if text:match '[^\n]*User:([^\n]-)%|[^\n]-CST' == nil then
return {userNum = '?', uniqueUserNum = '?', firstUser = '?', lastUser = '?'}
return {userNum = '-', uniqueUserNum = '-', firstUser = '-', lastUser = '-'}
end
end
for user in text:gmatch '[^\n]*User:([^\n]-)%|[^\n]-CST' do
for user in text:gmatch '[^\n]*User:([^\n]-)%|[^\n]-CST' do
第134行: 第148行:
end
end


function generateTable(talkTitle, talkText)
function generateTable(pageName, talkTitle, talkText)
local body = {
local body = {
'{| class="wikitable sortable collapsible talktable" style="text-align: center;"',
'{| class="wikitable sortable mw-collapsible talktable" style="text-align: center; margin: 0 auto; width: 100%;"',
'|-',
'|-',
'! # !! 话题 !! 发言条数 !! 参与人数 ',
'! # !! 话题 !! 发言条数 !! 参与人数 ',
第161行: 第175行:
'|-',
'|-',
'! style="' .. serialStyle .. '" | ' .. i,
'! style="' .. serialStyle .. '" | ' .. i,
'| [[#' .. titleConv(trim(talkTitle[i])) .. '|' .. titleConv(trim(talkTitle[i])) .. ']]',
'| [[' .. pageName .. '#' .. talkTitle[i] .. '|' .. talkTitle[i].. ']]',
'| style="' .. userStyle .. '" | ' .. userInfo.userNum,
'| style="' .. userStyle .. '" | ' .. userInfo.userNum,
'| style="' .. uniqueUserStyle .. '" | ' .. userInfo.uniqueUserNum,
     '| style="' .. uniqueUserStyle .. '" | ' .. userInfo.uniqueUserNum,
'| class="talkpage-topic-list-author" |' .. makeUserLink(userInfo.firstUser),
'| class="talkpage-topic-list-author" | ' .. makeUserLink(userInfo.firstUser),
'| class="talkpage-topic-list-last-editor" style="' .. timeStyle .. '" | ' .. makeUserLink(userInfo.lastUser),
'| class="talkpage-topic-list-last-editor" style="' .. timeStyle .. '" | ' .. makeUserLink(userInfo.lastUser),
'| class="talkpage-topic-list-time" style="' .. timeStyle .. '" | ' .. time
'| class="talkpage-topic-list-time" style="' .. timeStyle .. '" | ' .. time
第182行: 第196行:


local talkTitle, talkText = getTitleList(args[1]), getTalkList(args[1])
local talkTitle, talkText = getTitleList(args[1]), getTalkList(args[1])
if #talkTitle ~= #talkText then
return error 'Topic list获取错误。'
end
for i = 1, #talkTitle do
for i = 1, #talkTitle do
talkTitle[i] = f:preprocess(talkTitle[i])
talkTitle[i] = f:preprocess(talkTitle[i])
end
end
local result = generateTable(talkTitle, talkText)
return generateTable(args[1], talkTitle, talkText)
 
if #talkTitle == #talkText then
return result
else
return error 'Topic list获取错误。'
end
end
end


return p
return p