Module:User:AnomieBOT/TFDTemplateSubster/row explained

local bit32 = require('bit32')

local p =

local function getStatus(frame, tmpl, logpage) local t = mw.title.new(tmpl) if not t then return frame:expandTemplate .. ' The title "' .. mw.text.nowiki(tmpl) .. '" is invalid.' end if t.id <= 0 then return frame:expandTemplate .. ' Please remove this row.' end tmpl = t.fullText -- Normalize

t = mw.title.new(logpage) if not t or not t.exists then return frame:expandTemplate .. ' The XfD page is invalid or does not seem to exist.' end

local status = mw.loadJsonData('User:AnomieBOT/TFDTemplateSubster/status') local s = status[tmpl] or 0 local buts = if bit32.band(s, 0x01) ~= 0 then buts[#buts+1] = 'page protection' end if bit32.band(s, 0x02) ~= 0 then buts[#buts+1] = 'bot exclusion' end if bit32.band(s, 0x04) ~= 0 then buts[#buts+1] = 'demo/nosubst transclusions' end if bit32.band(s, 0x08) ~= 0 then buts[#buts+1] = 'unrecognized wikitext' end if bit32.band(s, 0x4000) ~= 0 then buts[#buts+1] = 'errors while attempting to edit' end if bit32.band(s, bit32.bnot(0xc00f)) ~= 0 then buts[#buts+1] = 'unknown reasons' end if #buts > 0 then buts = ', however transclusions may remain due to ' .. mw.text.listToText(buts) else buts = end

return frame:expandTemplate .. butsend

function p.main(frame) local args = frame:getParent.args local tmpl = args[1] if tmpl

nil then return '* Row template missing target template name!\n' end -- Note that the bot has equivalent logic for determining `link`, `logpage`, and `reason`. -- The bot and this module need to be updated in sync with each other. local link, logpage if args['link'] then link = args['link'] logpage = string.gsub(link, '#.*', ) else if args[2]

nil then return '* Row template missing link or TFD date!\n' end logpage = 'WP:Templates for discussion/Log/' .. args[2] link = logpage .. '#' .. (args['section'] or args[1]) end local reason = if args['reason'] then reason = '|' .. args['reason'] end local ret if string.sub(tmpl, 1, 9)

'Template:' then ret = '' else ret = '' end return '* ' .. ret .. ' per ' .. link .. reason .. '
(' .. '

.. mw.uri.encode(tmpl) .. '&limit=999 links' .. ' | .. mw.uri.encode(tmpl) .. '&limit=999&hidelinks=1 transclusions' .. ' | talk' .. ' | doc' .. ' | sandbox' .. ' | testcases' .. ')
' .. getStatus(frame, tmpl, logpage)end

return p