Module:XfD old/sandbox
Appearance
![]() | This is the module sandbox page for Module:XfD old (diff). See also the companion subpage for test cases. |
This module provides various tasks relating to old XfDs:
- Produces the "Old discussions" at Wikipedia:Templates for discussion and Wikipedia:Templates for discussion/All current discussions, and Wikipedia:Files for discussion
- Populates Wikipedia:Categories for discussion/Awaiting closure
- Populates Wikipedia:Categories for discussion/All old discussions
- Implements {{XFD backlog}}
local p = {}
local tableTools = require("Module:TableTools")
local ymd = require("Module:YMD to ISO")._main
local lang = mw.getContentLanguage()
function sortkey(name1, name2)
local key1 = ymd(mw.ustring.match(name1, "Log/(.*)"))
local key2 = ymd(mw.ustring.match(name2, "Log/(.*)"))
return key1 > key2
end
function p._main(frame, makeoutput)
local t = frame.args.title or frame:getParent():getTitle()
local content = mw.title.new(t .. "/Old unclosed discussions"):getContent();
local m = mw.ustring.gmatch(content, "* %[%[(" .. t .. "/Log/[^#]*)")
local seen = {}
while true do
local x = m()
if not x then
break
end
if seen[x] == nil then
seen[x] = 0
end
seen[x] = seen[x] + 1
end
local out = ""
for k, v in tableTools.sortedPairs(seen, sortkey) do
out = out .. makeoutput(k, v)
end
return mw.text.trim(out)
end
function p.list(frame)
local function listoutput(k, v)
return "* [[" .. k .. "]] (" .. tostring(v) .. " open) \n"
end
return p._main(frame, listoutput)
end
p.main = p.list
function p.transclude(frame)
local function transoutput(k, v)
return frame:preprocess("{{" .. k .. "}}")
end
return p._main(frame, transoutput)
end
return p