Module:Tracked: Difference between revisions
Appearance
hp>Xaosflux update from sandbox |
from enwikisource s:Module:Tracked 14459324 |
||
Line 1: | Line 1: | ||
require('strict') | |||
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('Tracked in [[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 = "Resolved", | |||
fixed = "Resolved", | |||
invalid = "Invalid", | |||
duplicate = "Duplicate", | |||
declined = "Declined", | |||
wontfix = "Declined", | |||
stalled = "Stalled", | |||
open = "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 |
Revision as of 09:36, 25 January 2025
Lua error in package.lua at line 80: module 'Module:Yesno' not found. Implements {{tracked}}.
require('strict')
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('Tracked in [[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 = "Resolved",
fixed = "Resolved",
invalid = "Invalid",
duplicate = "Duplicate",
declined = "Declined",
wontfix = "Declined",
stalled = "Stalled",
open = "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