跳到内容

Module:Topic list:修订间差异

添加2,315字节 、​ 2021年4月3日 (星期六)
重构;升级
(更新算法)
(重构;升级)
第67行: 第67行:
   end
   end
return len
return len
end
function time_style(time)
local _, _, y, m, d, _hour, _min, _sec = string.find(time, "(%d+)年(%d+)月(%d+)日%s%(.-%)%s(%d+):(%d+)");
local n_short_time = os.date(os.time({year=y, month = m, day = d, hour = _hour, min = _min}))
local n_long_time =os.date(os.time())
local t_time = time_diff(n_long_time,n_short_time);
local time_txt = string.format("%02d", t_time.month).."月"..string.format("%02d", t_time.day).."日  "..string.format("%02d", t_time.hour)..":"..string.format("%02d", t_time.min)..":"..string.format("%02d", t_time.sec);
if string.format("%02d", t_time.month)~="00" then return [[background-color: #bbb;]] end
if tonumber(string.format("%02d", t_time.day))>=7 then return [[background-color: #ddd;]] end
if tonumber(string.format("%02d", t_time.day))>=1 then return [[]] end
return [[background-color: #efe;]]
end
function time_diff(long_time,short_time)
local n_short_time,n_long_time,carry,diff = os.date('*t',short_time),os.date('*t',long_time),false,{}
local colMax = {60,60,24,os.date('*t',os.time{year=n_short_time.year,month=n_short_time.month+1,day=0}).day,12,0}
n_long_time.hour = n_long_time.hour - (n_long_time.isdst and 1 or 0) + (n_short_time.isdst and 1 or 0) -- handle dst
for i,v in ipairs({'sec','min','hour','day','month','year'}) do
diff[v] = n_long_time[v] - n_short_time[v] + (carry and -1 or 0)
carry = diff[v] < 0
if carry then
diff[v] = diff[v] + colMax[i]
end
end
return diff
end
function close(text,timestyle)
local yes=string.match(text, "closed-topic-yes")
local no=string.match(text, "closed-topic-no")
if yes then return [[background-color: #efe;]] end
if no then return [[background-color: #fee;]] end
return timestyle
end
end


第81行: 第118行:
--此处添加导致链接工作不正常的文本
--此处添加导致链接工作不正常的文本
text=trim(trim(text))
text=trim(trim(text))
 
text=string.gsub(text, " (.*)", "%1")
text=LuaReomve(text,"%[")
text=LuaReomve(text,"%]")
return text
return text
end
end
第105行: 第144行:
end
end


function talk_title(pagename)
function title_list(pagename)
local talk=cov(mw.getCurrentFrame():expandTemplate{ title = pagename })
local talk=cov(mw.getCurrentFrame():expandTemplate{ title = pagename })
local match=string.gmatch(talk,"==(.-)==")
local match=string.gmatch(talk,"==(.-)==")
第127行: 第166行:
end
end


function user_list(text)
function user_manage(text)
--输入论 题段 ,输出 参与讨论的User顺序表( 重复)
--输入 的文本 ,输出 和User 关的转换部分table
--1-4分别为发言条数,发言人数,发起人,最后发言的人
local match=string.gmatch (text,".-User:(.-)%|.-CST")
local match=string.gmatch (text,".-User:(.-)%|.-CST")
local userlist={}
local userlist={}
第150行: 第190行:


function get_table(talktitle,talktext)
function get_table(talktitle,talktext)
local result=[[<table class="wikitable" style="text-align:center"><tr><th>#</td><th>话题</td><th>发言</td><th>参与</td><th>发起者</td><th>最近发言</td><th>最后发言时间(CST)</td></tr>]]
local result=[[<table class="wikitable sortable mw-collapsible" style="text-align:center"><tr><th>#</td><th>话题</td><th>发言</td><th>参与</td><th>发起者</td><th>最近发言</td><th>最后发言时间(CST)</td></tr>]]
local tableend=[[</table>]]
local tableend=[[</table>]]
local part=""
local part=""


local list={}
local userinf,time
local time={}
local userstyle,userstyleind,timestyle
local user_len,user_len_ind,firstuser,lastuser=nil,nil,"",""
 
local test="cc"
for i=1,get_len(talktext) 
for i=1,get_len(talktext) 
do
do
time=talk_time(talktext[i])
time,userinf=talk_time(talktext[i]),user_manage(talktext[i])
list=user_list(talktext[i])
if userinf[1]==1 then userstyle=[[text-align: right;background-color: #fcc;"]] else userstyle=[[text-align: right;]] end
part=[[<tr><th>]]..i..[[</td><td>]]..link(talktitle[i])..[[</td><td>]]..list[1]..[[</td><td>]]..list[2]..[[</td><td>]]..list[3]..[[</td><td>]]..list[4]..[[</td><td>]]..tostring(time)
if userinf[2]==1 then userstyleind=[[text-align: right;background-color: #fcc;"]] else userstyleind=[[text-align: right;]] end
timestyle=time_style(time)
part=[[<tr><th>]]..i..[[</td><td>]]..link(talktitle[i])..[[</td><td style="]]..userstyle..[[">]]..userinf[1]..[[</td><td style="]]..userstyleind..[[">]]..userinf[2]..[[</td><td>]].."[[User:"..userinf[3].."|"..userinf[3].."]]"..[[</td><td style="]]..timestyle..[[">]].."[[User:"..userinf[4].."|"..userinf[4].."]]"..[[</td><td style="]]..timestyle..[[">]]..tostring(time)
result=result..part
result=result..part
end
end
第173行: 第212行:


function p.main(frame)
function p.main(frame)
local talktitle=talk_title(frame.args[1])
local talktitle,talktext=title_list(frame.args[1]),talk_list(frame.args[1])
local talktext=talk_list(frame.args[1],talktext)
if get_len(talktitle)==get_len(talktext) then return tostring(get_table(talktitle,talktext)) else return frame:expandTemplate{ title = 'error', args = { 'Topic list 获取错误。' } } end
 
if get_len(talktitle)==get_len(talktext) then return get_table(talktitle,talktext) else return frame:expandTemplate{ title = 'error', args = { 'Topic list 获取错误。' } } end
end
end


return p
return p