Module:Request for permission links

local p = {} local getArgs = require('Module:Arguments').getArgs

function p.links(permission, parenthetical, username, userURL) local l = {} -- To add a new link, find an empty line in the section below -- and add either a link or a wikilink, like so: --	--		l[#l+1] = '[URL external link]' --		l[#l+1] = 'wikilink' --	-- However, replace any instance of a username with: --	--		'..userURL..'		-- For a [ ]  URL/external link --		'..username..'		-- For a  wikilink --	-- Each new "l" (link string) will automatically have a spaced dot in -- the final output. To skip the spaced dot, add a line before with: --	--		before('') --	-- See the existing links below for examples. local Before = {, , ''} -- Skip dots before 1, 2, 3. function before( replacement ) Before[#l+1] = replacement end -- First links: 1. Userpage, 2. parenthetical (defined below in p.main) -- 3. User talk page, 4. User talk page history, 5. User contributions. l[1] = ..username.. l[2] = parenthetical l[3] = '(t'	l[4] = 'th'	l[5] = 'c'	-- Permission-specific contributions links	if permission == 'Template editor' then		before(' (') l[#l+1] = 'template space' l[#l+1] = 'edit requests) '	elseif permission == 'Page mover' then		before(' (') l[#l+1] = 'RM/TR' l[#l+1] = 'RMs) '	elseif permission == 'File mover' then		before(' (') l[#l+1] = 'file space) '	end	l[#l+1] = ' del'	l[#l+1] = ' cross-wiki'	l[#l+1] = 'SUL'	l[#l+1] = 'edit counter'

if permission == 'Event coordinator' then l[#l+1] = 'accounts created' elseif permission == 'Template editor' then l[#l+1] = 'templates created' else l[#l+1] = 'pages created (xtools'		l[#l+1] = 'sigma)' end

l[#l+1] = 'non-automated edits' l[#l+1] = 'BLP edits' l[#l+1] = 'undos' l[#l+1] = 'manual reverts' l[#l+1] = 'rollbacks' l[#l+1] = 'logs' before(' (')	l[#l+1] = 'blocks'	l[#l+1] = 'rights'	l[#l+1] = 'moves) ' if permission == 'New page reviewer' then l[#l+1] = 'curation log' l[#l+1] = 'patrol log' l[#l+1] = 'AFD stats' l[#l+1] = 'AFC stats' l[#l+1] = 'CSD log' l[#l+1] = 'PROD log' l[#l+1] = 'Draftify log' l[#l+1] = 'Mainspace edits' elseif permission == 'Page mover' then l[#l+1] = 'CSD log' end

l[#l+1] = 'rfar' l[#l+1] = 'spi' l[#l+1] = 'cci)'	-- New links should be somewhere above this line.	-- Next, links for assigning permissions and notifying the user.	before(' (') if permission == 'AutoWikiBrowser' then l[#l+1] = "edit CheckPage)"	else		l[#l+1] = " assign permissions )" end local subpages = {'Account creator', 'Autopatrolled', 'AutoWikiBrowser', 'Confirmed', 'Event coordinator', 'Extended confirmed', 'File mover', 'Mass message sender', 'New page reviewer', 'Page mover', 'Pending changes reviewer', 'Rollback', 'Template editor'} local templates = {['Account creator']='acc', ['Autopatrolled']='ap', ['AutoWikiBrowser']=false, ['Confirmed']=false, ['Event coordinator']='ev', ['Extended confirmed']=false, ['File mover']='fm', ['Mass message sender']='mms', ['New page reviewer']='npr', ['Page mover']='pm', ['Pending changes reviewer']='pc', ['Rollback']='rb', ['Template editor']='te'} if permission then if templates[permission] then local templateURL = mw.ustring.gsub(permission..' granted', '%s', '%%20') local headingURL = templateURL if permission == 'Rollback' then templateURL = templateURL..'%20'..'2' -- Template:Rollback granted 2 end before(' (')			l[#l+1] = 'notify) ' else l[#l] = l[#l]..' ' end else before(' (')		for i=1,#subpages do			if templates[subpages[i]] then				local templateURL = mw.ustring.gsub(subpages[i]..' granted', '%s', '%%20')				l[#l+1] = ''..templates[subpages[i]..']'			end		end		l[#l] = l[#l]..') ' end -- All links should be within a plainlinks span Before[1] = ' ' l[#l] = l[#l]..' ' local ret = '' for n=1,#l do ret = ret .. (Before[n] or " &middot; ") .. l[n] end return ret end -- This is the main function (the one directly called by the template). -- It determines the permission (if uniquely determined), the username, -- and the URL encoding of the username, then creates a parenthetical -- listing any permission(s) sought at subpages of WP:PERM (if viewing the 	-- main WP:PERM page rather than a subpage WP:PERM/[...]). -- It then uses this information to call the p.links function above. function p.main(frame) local args = getArgs(frame) local username = args['User'] or args['1'] or 'Example' -- local userURL = frame:callParserFunction('urlencode', username, 'PATH') -- local permission = args['permission'] -- local base = 'Wikipedia:Requests for permissions' -- A/K/A WP:PERM. local current = mw.allToString(mw.title.getCurrentTitle) -- local shortened = mw.ustring.gsub(current, base..'/', '') -- Subtitle, if the current title is a subpage of WP:PERM. -- The 13 subpages of WP:PERM currently used for requesting permissions: local subpages = {'Account creator', 'Autopatrolled', 'AutoWikiBrowser', 'Confirmed', 'Event coordinator', 'Extended confirmed', 'File mover', 'Mass message sender', 'New page reviewer', 'Page mover', 'Pending changes reviewer', 'Rollback', 'Template editor'} local check = {['Account creator']=true, ['Autopatrolled']=true, ['AutoWikiBrowser']=true, ['Confirmed']=true, ['Event coordinator']=true, ['Extended confirmed']=true, ['File mover']=true, ['Mass message sender']=true, ['New page reviewer']=true, ['Page mover']=true, ['Pending changes reviewer']=true, ['Rollback']=true, ['Template editor']=true} -- Use check[x] to check whether x is one of the subpages. -- Ignore any provided args.permission if not valid if not check[permission] then permission = nil end local intext = {} local count = 0 local tentative = '' -- If viewing WP:PERM or its subpages, then check each subpage for a request for this user. if current == base or check[shortened] then local text = {} local pattern = mw.ustring.gsub('', "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" ) -- Copied from _escapePattern in Module:String for i=1,#subpages do			text[i] = mw.title.new( base..'/'..subpages[i] ):getContent or '' if text[i] ~= mw.ustring.gsub(text[i], pattern, '') then intext[i] = true tentative = subpages[i] count = count + 1 end end -- If exactly one subpage with a request, then use that as the permission. if count == 1 then permission = tentative end -- If the page is one one of the subpages, then use that as the permission. if check[shortened] then permission = shortened end end -- Now to form the parenthetical. local parenthetical = ' ' -- If requesting multiple perms at WP:PERM, show each one requested. if count > 1 then parenthetical = ' ( requesting '		local first = true		for i=1,#subpages do			if intext[i] then				if not first then					parenthetical = parenthetical .. ', '				else					first = false				end				parenthetical = parenthetical....subpages[i]..			end		end		parenthetical = parenthetical..' ) ' -- If requesting one perm, but viewed on a page other than that -- perm's subpage of WP:PERM, then show the permission requested. elseif permission then if current ~= base..'/'..permission then parenthetical = ' ( requesting '..permission..' ) ' end end return p.links(permission, parenthetical, username, userURL) end

return p