モジュール:Tracked
モジュールの解説[作成]
local getArgs = require('Module:Arguments').getArgs
local p = {}
-- Entry point when #invoke'ed by a template or wikipage.
function p.main(frame)
local args = getArgs(frame)
return p._main(args)
end
-- Entry point when called from other Lua modules.
function p._main(args)
-- Check if the template provided a status
local manual_status
if args[2] ~= nil and args[2] ~= '' then
manual_status = args[2]
end
-- Check if the template provided a tracker number
local task
if args[1] ~= nil and args[1] ~= '' then
if string.match(args[1], "^[Tt]%d+$") then
-- It's a Phab task, so just use it as is (minus the "T")
task = string.gsub(args[1], "^[Tt]", "")
elseif string.match(args[1], "^%d+$") then
-- It's a bzImport, so massage it first
task = args[1] + 2000
else
-- Tracking arg given, but doesn't match our patterns
-- FIXME: Emit a visible error for this? Tracking cat?
end
else
-- No tracking number provided.
-- FIXME: Emit a visible error for this? Tracking cat?
end
-- Now create the top level container
local box = mw.html.create('div')
:attr("role", "note")
:addClass('tracked')
:addClass('plainlinks')
box:tag('span')
:addClass('tracked-header')
:wikitext('[[phabricator:|Phabricator]]追跡')
if task then
box:addClass('mw-trackedTemplate')
:addClass("phab-T" .. task) -- Easily find the task in JS
:attr('data-phab-task', task) -- Task ID for easy access in JS
local linktext = mw.html.create('span')
:addClass('tracked-linktext')
:wikitext("Task T" .. task)
local wikitext_link = '[[phabricator:T' .. task .. '|' .. tostring(linktext) .. ']]'
box:tag('span')
:addClass('tracked-link')
:wikitext(wikitext_link)
end
local s = {
resolved = "解決済み",
fixed = "解決済み",
invalid = "依頼無効",
duplicate = "依頼重複",
declined = "却下済み",
wontfix = "却下済み",
stalled = "停滞中",
open = "議論中"
}
if manual_status then
local status_text = "Unknown"
local status_span = box:tag('span')
status_span:addClass('tracked-closure')
if manual_status == "resolved" or manual_status == "fixed" then
status_span:addClass('tracked-resolved')
end
if s[manual_status] ~= nil then
status_text = s[manual_status]
end
status_span:wikitext(status_text)
end
return tostring(box)
end
return p