Module:AfC: Difference between revisions
Appearance
Content deleted Content added
forgot the frame |
The Earwig (talk | contribs) also make sure the sortkey for modified times works |
||
Line 30: | Line 30: | ||
cols[6] = p.printuser(modified_by) |
cols[6] = p.printuser(modified_by) |
||
cols[7] = p.invoke("Module:Revision", "diff", frame, title, "prev", old_id, modified_at) |
cols[7] = string.format('<span style="display:none" class="sortkey">%s</span>%s', old_id, p.invoke("Module:Revision", "diff", frame, title, "prev", old_id, modified_at)) |
||
local colstring = "" |
local colstring = "" |
||
for i=1, 7 do colstring = colstring .. string.format("<td>%s</td>", cols[i]) end |
for i=1, 7 do colstring = colstring .. string.format("<td>%s</td>", cols[i]) end |
Revision as of 23:43, 13 May 2013
This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
The AfC module contains code to render rows of Template:AFC statistics.
Usage
{{#invoke:AfC|row|s=status|t=title|z=size|sr=special user|sd=special time|si=special oldid|mr=modify user|md=modify time|mi=modify oldid|…}}
Parameters
{{{s}}}
: status (one of p, a, d, r, m){{{t}}}
: full title of page{{{z}}}
: size of page (number of bytes)
{{{mr}}}
: username of last page modifier{{{md}}}
: time page was last modified{{{mi}}}
: oldid at last modification time
{{{sr}}}
: username of page reviewer/submitter (or any special second case){{{sd}}}
: time page was "specialed"{{{si}}}
: oldid at "special" time
{{{n}}}
: whether or not the template should display special notes about this page{{{nc}}}
: (copyvio) submission is a suspected copyright violation{{{nu}}}
: (unsourced) submission lacks references completely{{{ni}}}
: (no-inline) submission has no inline citations{{{ns}}}
: (short) submission is less than a kilobyte in length{{{nr}}}
: (resubmit) submission was resubmitted after a previous decline{{{no}}}
: (old) submission has not been touched in over four days{{{nj}}}
: (rejected) submission was rejected{{{nb}}}
: (blocked) submitter is currently blocked
Examples
{{#invoke:AfC|row|s=a|t=Walter Erwin Diewert|z=2029|sr=Miniapolis|sd=13:31, 15 Oct 2013|si=577279496|mr=Derek R Bullamore|md=18:52, 15 Oct 2013|mi=577320678}}Lua error in package.lua at line 80: module 'Module:Revision' not found.
Submission | Accepted | Last modified | ||||
---|---|---|---|---|---|---|
Title | Size | Notes | User | Time | User | Time |
local p = {}
revlib = require("Module:Revision");
-- current call example: {{AFC statistics/row|s=p|t=Confidential Incident Reporting & Analysis System (CIRAS)|h=Submissions/Confidential Incident Reporting & A...|z=6.7 kB|sr=CIRAS|sd=15:19, 22 Jan 2009|si=265715189|mr=SBaker43|md=04:45, 15 Mar 2013|mi=544281825}}
function p.row(frame)
local status = frame.args["s"]
local title = frame.args["t"]
local short = p.shorttitle(title, 30);
local size = frame.args["z"]
local modified_by = frame.args["mr"]
local modified_at = frame.args["md"]
local old_id = frame.args["mi"]
local special_user = frame.args["sr"]
local special_time = frame.args["sd"]
local special_id = tonumber(frame.args["si"])
local display_notes = tonumber(frame.args["n"])
local rowtemplate = "<tr style=\"background-color:%s\"> %s </tr>"
local colorthing = p.color(status, false)
local cols = {}
cols[1] = string.format("[[:%s|%s]]", title, short)
cols[2] = size
if display_notes then cols[3] = p.notes(frame) else cols[3] = "" end
if special_id then
cols[4] = p.printuser(special_user)
cols[5] = string.format('<span style="display:none" class="sortkey">%s</span>%s', special_id, p.invoke("Module:Revision", "diff", frame, title, "prev", special_id, special_time))
else
cols[4] = "Unknown"
cols[5] = "Unknown"
end
cols[6] = p.printuser(modified_by)
cols[7] = string.format('<span style="display:none" class="sortkey">%s</span>%s', old_id, p.invoke("Module:Revision", "diff", frame, title, "prev", old_id, modified_at))
local colstring = ""
for i=1, 7 do colstring = colstring .. string.format("<td>%s</td>", cols[i]) end
return string.format(rowtemplate, colorthing, colstring)
end
function p.notes(frame)
local result = ""
local is_suspected_copyvio = tonumber(frame.args["nc"])
local is_unsourced = tonumber(frame.args["nu"])
local no_inline = tonumber(frame.args["ni"])
local is_short = tonumber(frame.args["ns"])
local is_resubmit = tonumber(frame.args["nr"])
local is_old = tonumber(frame.args["no"])
local submitter_is_blocked = tonumber(frame.args["nb"])
if is_suspected_copyvio then result = result .. "<abbr title=\"Submission is a suspected copyright violation\">copyvio</abbr>  " end
if is_unsourced then result = result .. "<abbr title=\"Submission lacks references completely\">unsourced</abbr>  " end
if no_inline then result = result .. "<abbr title=\"Submission has no inline citations\">no-inline</abbr>  " end
if is_short then result = result .."<abbr title=\"Submission is less than a kilobyte in length\">short</abbr>  " end
if is_resubmit then result = result .. "<abbr title=\"Submission was resubmitted after a previous decline\">resubmit</abbr>  " end
if is_old then result = result .. "<abbr title=\"Submission has not been touched in over four days\">old</abbr>  " end
if submitter_is_blocked then result = result .. "<abbr title=\"Submitter is currently blocked\">blocked</abbr>|}}" end
return result
end
function p.color(status, dark)
local result
local dark_colors = {
p = "#979158",
d = "#a07980",
r = "#708a92",
a = "#5f9e5f"
}
local normal_colors = {
p = "#f3eba3",
d = "#ffcdd5",
r = "#b1dae8",
a = "#adfcad"
}
if dark then
return dark_colors[status] or "#7e7f7a"
else
return normal_colors[status] or "#d2d3cc"
end
end
function p.printuser(user)
return string.format("[[User:%s|%s]] ([[User talk:%s|t]])", user, user, user)
end
function p.shorttitle(fulltitle, maxlength)
--strip off namespace:basepage/ if it exists and anything is left
--if not, strip off namespace
--truncate to maxlength
local startindex, size, namespace, basetitle, subtitle = mw.ustring.find(fulltitle, "([^:]*):([^\/]*)\/?(.*)")
local effective_title = subtitle or basetitle
if (effective_title == nil or string.len(effective_title) == 0) then effective_title = fulltitle end
effective_title = string.gsub(effective_title, "^Submissions/", "")
-- return mw.text.truncate( effective_title, maxlength ) (mw.text is not yet deployed!)
if (mw.ustring.len(effective_title) > maxlength) then
return mw.ustring.sub(effective_title, 1, maxlength - 3) .. "..."
else
return effective_title
end
end
--equivalent of {{#Invoke:module|function|arg1|arg2|namedarg=arg3|namedarg2=arg4}} becomes
--p.invoke("module", "function", frame, arg1, arg2, {namedarg=arg3}, {namedarg2=arg4})
function p.invoke(modname, call, frame, ...)
local mymod = require(modname)
local nargs = {}
for i,v in ipairs(arg) do
if type(v) == "table" then
local argname, argv = ipairs(v)
nargs[argname] = tostring(argv)
else
nargs[i] = tostring(v)
end
end
local childframe = frame:newChild{title = nil, args = nargs}
return mymod[call](childframe)
end
return p