Difference between revisions of "Module:User:AnomieBOT/TFDTemplateSubster/row"

From blackwiki
Jump to navigation Jump to search
blackwiki>Anomie
m (Protected "Module:User:AnomieBOT/TFDTemplateSubster/row": User request within own user space ([Edit=Require administrator access] (indefinite) [Move=Require administrator access] (indefinite)))
blackwiki>Anomie
(Add status indicator)
Line 1: Line 1:
 +
local bit32 = require( 'bit32' )
 +
 
local p = {}
 
local p = {}
 +
 +
local function getStatus( frame, tmpl, logpage )
 +
local t = mw.title.new( tmpl )
 +
if not t then
 +
return frame:expandTemplate{ title = 'Not done', args = { 'Invalid' } } .. ' The title "' .. mw.text.nowiki( tmpl ) .. '" is invalid.'
 +
end
 +
if t.id <= 0 then
 +
return frame:expandTemplate{ title = 'Done', args = { 'Deleted' } } .. ' Please remove this row.'
 +
end
 +
 +
t = mw.title.new( logpage )
 +
if not t or not t.exists then
 +
return frame:expandTemplate{ title = 'Not done', args = { 'Invalid' } } .. ' The XfD page [[:' .. logpage .. ']] is invalid or does not seem to exist.'
 +
end
 +
 +
local status = mw.text.jsonDecode( mw.title.new( 'User:AnomieBOT/TFDTemplateSubster/status' ):getContent() )
 +
if type( status ) ~= 'table' then
 +
return ''
 +
end
 +
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{ title = bit32.band( s, 0x8000 ) ~= 0 and 'Done' or 'Working' } .. buts
 +
end
  
 
function p.main( frame )
 
function p.main( frame )
Line 26: Line 75:
 
local ret
 
local ret
 
if string.sub( tmpl, 1, 9 ) == 'Template:' then
 
if string.sub( tmpl, 1, 9 ) == 'Template:' then
    ret = '{{[[' .. tmpl .. '|' .. string.sub( tmpl, 10 ) .. ']]}}'
+
ret = '{{[[' .. tmpl .. '|' .. string.sub( tmpl, 10 ) .. ']]}}'
 
else
 
else
    ret = '{{[[:' .. tmpl .. ']]}}'
+
ret = '{{[[:' .. tmpl .. ']]}}'
 
end
 
end
 
return '* ' .. ret .. ' per [[' .. link .. reason .. ']]<br><small>(' ..
 
return '* ' .. ret .. ' per [[' .. link .. reason .. ']]<br><small>(' ..
        '<span class="plainlinks">[//en.wikipedia.org/w/index.php?title=Special:WhatLinksHere/' .. mw.uri.encode( tmpl ) .. '&limit=999 links]</span>' ..
+
'<span class="plainlinks">[//en.wikipedia.org/w/index.php?title=Special:WhatLinksHere/' .. mw.uri.encode( tmpl ) .. '&limit=999 links]</span>' ..
        '&nbsp;&#124; <span class="plainlinks">[//en.wikipedia.org/w/index.php?title=Special:WhatLinksHere/' .. mw.uri.encode( tmpl ) .. '&limit=999&hidelinks=1 transclusions]</span>' ..
+
'&nbsp;&#124; <span class="plainlinks">[//en.wikipedia.org/w/index.php?title=Special:WhatLinksHere/' .. mw.uri.encode( tmpl ) .. '&limit=999&hidelinks=1 transclusions]</span>' ..
        '&nbsp;&#124; [[' .. string.gsub( tmpl, ':', ' talk:', 1 ) .. '|talk]]' ..
+
'&nbsp;&#124; [[' .. string.gsub( tmpl, ':', ' talk:', 1 ) .. '|talk]]' ..
        '&nbsp;&#124; [[' .. tmpl .. '/doc|doc]]' ..
+
'&nbsp;&#124; [[' .. tmpl .. '/doc|doc]]' ..
        '&nbsp;&#124; [[' .. tmpl .. '/sandbox|sandbox]]' ..
+
'&nbsp;&#124; [[' .. tmpl .. '/sandbox|sandbox]]' ..
        '&nbsp;&#124; [[' .. tmpl .. '/testcases|testcases]]' ..
+
'&nbsp;&#124; [[' .. tmpl .. '/testcases|testcases]]' ..
    ')</small>'
+
')</small><br>' .. getStatus( frame, tmpl, logpage )
 
end
 
end
  
 
return p
 
return p

Revision as of 18:23, 1 February 2020

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{ title = 'Not done', args = { 'Invalid' } } .. ' The title "' .. mw.text.nowiki( tmpl ) .. '" is invalid.'
	end
	if t.id <= 0 then
		return frame:expandTemplate{ title = 'Done', args = { 'Deleted' } } .. ' Please remove this row.'
	end

	t = mw.title.new( logpage )
	if not t or not t.exists then
		return frame:expandTemplate{ title = 'Not done', args = { 'Invalid' } } .. ' The XfD page [[:' .. logpage .. ']] is invalid or does not seem to exist.'
	end

	local status = mw.text.jsonDecode( mw.title.new( 'User:AnomieBOT/TFDTemplateSubster/status' ):getContent() )
	if type( status ) ~= 'table' then
		return ''
	end
	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{ title = bit32.band( s, 0x8000 ) ~= 0 and 'Done' or 'Working' } .. buts
end

function p.main( frame )
	local args = frame:getParent().args
	local tmpl = args[1]
	if tmpl == nil then
		return '* <strong class="error">Row template missing target template name!</strong>\n'
	end
	
	local link, logpage
	if args['link'] then
		link = args['link']
		logpage = string.gsub( link, '#.*', '' )
	else
		if args[2] == nil then
			return '* <strong class="error">Row template missing link or TFD date!</strong>\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 = '{{[[' .. tmpl .. '|' .. string.sub( tmpl, 10 ) .. ']]}}'
	else
		ret = '{{[[:' .. tmpl .. ']]}}'
	end
	return '* ' .. ret .. ' per [[' .. link .. reason .. ']]<br><small>(' ..
		'<span class="plainlinks">[//en.wikipedia.org/w/index.php?title=Special:WhatLinksHere/' .. mw.uri.encode( tmpl ) .. '&limit=999 links]</span>' ..
		'&nbsp;&#124; <span class="plainlinks">[//en.wikipedia.org/w/index.php?title=Special:WhatLinksHere/' .. mw.uri.encode( tmpl ) .. '&limit=999&hidelinks=1 transclusions]</span>' ..
		'&nbsp;&#124; [[' .. string.gsub( tmpl, ':', ' talk:', 1 ) .. '|talk]]' ..
		'&nbsp;&#124; [[' .. tmpl .. '/doc|doc]]' ..
		'&nbsp;&#124; [[' .. tmpl .. '/sandbox|sandbox]]' ..
		'&nbsp;&#124; [[' .. tmpl .. '/testcases|testcases]]' ..
		')</small><br>' .. getStatus( frame, tmpl, logpage )
end

return p