Module:Topic list:修订间差异

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


第17行: 第20行:
end
end


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


第46行: 第55行:


function getTimeStyle(time)
function getTimeStyle(time)
if time == ' 未知日期' then
if time == ' 该讨论主题已被移动' then
return 'background-color: #fee;'
return 'background-color: #fee;'
end
end
第108行: 第117行:


function getTitleList(pageName)
function getTitleList(pageName)
local talk = 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
第118行: 第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
第127行: 第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
第141行: 第150行:
function generateTable(pageName, 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%;"',
'|-',
'|-',
'! # !! 话题 !! 发言条数 ',
'! # !! 话题 !! 发言条 数 !! 参与人 数 ',
'! class="talkpage-topic-list-author" | 发起者',
'! class="talkpage-topic-list-author" | 发起者',
'! class="talkpage-topic-list-last-editor" | 最后发言者',
'! class="talkpage-topic-list-last-editor" | 最后发言者',
第168行: 第177行:
'| [[' .. pageName .. '#' .. talkTitle[i] .. '|' .. talkTitle[i].. ']]',
'| [[' .. pageName .. '#' .. talkTitle[i] .. '|' .. talkTitle[i].. ']]',
'| style="' .. userStyle .. '" | ' .. userInfo.userNum,
'| style="' .. userStyle .. '" | ' .. userInfo.userNum,
'| class="talkpage-topic-list-author" |' .. makeUserLink(userInfo.firstUser),
     '| style="' .. uniqueUserStyle .. '" | ' .. userInfo.uniqueUserNum,
'| 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
第186行: 第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(args[1], 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