local p = {}
local getArgs = require('Module:Arguments').getArgs
---@param frame Frame
function p.main(frame)
local args = getArgs(frame)
-- 构建编辑历史项的 wikitext
local parts = {}
-- 添加时间和差异/历史链接
table.insert(parts, string.format('<li>{{plain link|{{fullurl:#|oldid=%s}}|%s}}(',
args.oldid or '', args.datetime or ''))
if args.new == 'true' then
table.insert(parts, '差异')
else
table.insert(parts, string.format('{{plain link|{{fullurl:#|diff=prev&oldid=%s}}|差异}}',
args.oldid or ''))
end
table.insert(parts, string.format(' | {{plain link|{{fullurl:#|oldid=%s&action=history}}|历史}}) ',
args.oldid or ''))
-- 添加用户信息
if args.username then
table.insert(parts, string.format('<span class="mw-changeslist-separator">{{#img:|src=https://commons.moegirl.org.cn/index.php?action=avatar&userName=%s|style=margin-left:0.2em;margin-right:0.2em;width:1.5em;border-radius:15%%;margin-top:-0.2em}}{{plain link|{{canonicalurl:User:%s}}|%s}}([[User talk:%s|讨论]] | [[Special:用户贡献/%s|贡献]]) ',
args.username:gsub("(.) (.)", "%1_%2"),
args.username, args.username:gsub("(.)_(.)", "%1 %2"),
args.username, args.username))
end
-- 添加编辑类型标记
if args.new == 'true' then
table.insert(parts, '<abbr style="font-weight:bold;cursor:help;text-decoration:underline dotted" title="该编辑创建了新页面">新</abbr>')
end
if args.small == 'true' then
table.insert(parts, '<abbr style="font-weight:bold;cursor:help;text-decoration:underline dotted" title="该编辑为小编辑">小</abbr>')
end
if args.robot == 'true' then
table.insert(parts, '<abbr style="font-weight:bold;cursor:help;text-decoration:underline dotted" title="该编辑由机器人执行">机</abbr>')
end
-- 添加字节信息
if args.byte then
table.insert(parts, string.format(' . . (%s字节) ', args.byte))
end
-- 添加字节变化信息
if args.bytechange then
-- 安全地转换字节变化值为数字
local byteChangeStr = tostring(args.bytechange):gsub(",", "")
local byteChangeNum = tonumber(byteChangeStr) or 0
local tagName = (byteChangeNum > 500 or byteChangeNum < -500) and "strong" or "span"
local color
if byteChangeNum > 0 then
color = "#006400" -- 深绿色
elseif byteChangeNum < 0 then
color = "#8b0000" -- 深红色
else
color = "#a2a9b1" -- 灰色
end
table.insert(parts, string.format('<%s dir="ltr" style="color:%s" title="更改后有%s字节">(%s)</%s>',
tagName, color, args.byte or "", args.bytechange, tagName))
end
table.insert(parts, ' <span class="mw-changeslist-separator">. .</span> ')
-- 添加注释
if args.note then
table.insert(parts, string.format('<i>(%s)</i> ', args.note))
end
-- 添加撤销和感谢链接
table.insert(parts, string.format('({{假链|撤销|你想干嘛?}} | [[Special:感谢/%s|感谢]])',
args.oldid or ''))
-- 处理标签
local tags = {}
for k, v in pairs(args) do
if k:match("^tag[0-9]+$") or k:match("^tag_[a-zA-Z]") then
table.insert(tags, v)
end
end
if #tags > 0 then
table.insert(parts, string.format('([[Special:标签|%d个标签]]:%s)',
#tags, table.concat(tags, "、")))
end
-- 添加当前标记
if args.current == 'true' then
table.insert(parts, " '''(当前)'''")
end
table.insert(parts, '</li>')
return frame:preprocess( table.concat(parts, ""))
end
return p