Difference between revisions of "Module:TfdLinks"

From MINR.ORG WIKI
Line 11: Line 11:
  
 
local function fullurl(t, a)
 
local function fullurl(t, a)
return '//en.wikipedia.org/w/index.php?title=' + t + '&' + a
+
return '//en.wikipedia.org/w/index.php?title=' .. t .. '&' .. a
 
end
 
end
  
Line 18: Line 18:
 
local ns = (args['catfd'] and args['catfd'] ~= '') and 'Category' or 'Template'
 
local ns = (args['catfd'] and args['catfd'] ~= '') and 'Category' or 'Template'
 
local tname = mw.getContentLanguage():ucfirst(args['1'] or 'Example')
 
local tname = mw.getContentLanguage():ucfirst(args['1'] or 'Example')
local fname = ns + ':' + tname
+
local fname = ns .. ':' .. tname
 
local ymd = args['2'] or ''
 
local ymd = args['2'] or ''
 
local fullpagename = (ymd ~= '')
 
local fullpagename = (ymd ~= '')
and 'WP:Templates for discussion/Log' + ymd
+
and 'WP:Templates for discussion/Log' .. ymd
 
or frame:preprocess('{{FULLPAGENAME}}')
 
or frame:preprocess('{{FULLPAGENAME}}')
 
local sep = '&nbsp;<b>·</b> '
 
local sep = '&nbsp;<b>·</b> '
 
 
local res = '<span id="' + ns + ':' + tname  
+
local res = '<span id="' .. ns .. ':' .. tname  
+ '" class="plainlinks nourlexpansion 1x">'
+
.. '" class="plainlinks nourlexpansion 1x">'
+ '[[:' + ns + ':' + tname + ']]&nbsp;('
+
.. '[[:' .. ns .. ':' .. tname .. ']]&nbsp;('
 
 
 
if ymd ~= '' then
 
if ymd ~= '' then
 
local dmy = frame:expandTemplate{ title = 'date', args = {args['2'], 'dmy'} }  
 
local dmy = frame:expandTemplate{ title = 'date', args = {args['2'], 'dmy'} }  
res = res + '[[' + fullpagename + '#' + fname + '|' + dmy + ') ('
+
res = res .. '[[' .. fullpagename .. '#' .. fname .. '|' .. dmy .. ') ('
 
end
 
end
res = res + '[' + fullurl(fname, 'action=edit') + ' edit]' + sep
+
res = res .. '[' .. fullurl(fname, 'action=edit') .. ' edit]' .. sep
res = res + '[[' + ns + ' talk:' + tname + '|talk]]' + sep
+
res = res .. '[[' .. ns .. ' talk:' .. tname .. '|talk]]' .. sep
res = res + '[' + fullurl(fname, 'action=history') + ' history' + sep
+
res = res .. '[' .. fullurl(fname, 'action=history') .. ' history' .. sep
 
if ns ~= 'Category' then
 
if ns ~= 'Category' then
res = res + '[' + fullurl('Special:Whatlinkshere/' + fname, 'limit=999') + ' links]' + sep
+
res = res .. '[' .. fullurl('Special:Whatlinkshere/' .. fname, 'limit=999') .. ' links]' .. sep
 
end
 
end
res = res + '[' + fullurl('Special:Log', 'page=' + urlencode(fname)) + ' logs]' + sep
+
res = res .. '[' .. fullurl('Special:Log', 'page=' .. urlencode(fname)) .. ' logs]' .. sep
res = res + '[[Special:PrefixIndex/' + fname + '|subpages]]' + sep
+
res = res .. '[[Special:PrefixIndex/' .. fname .. '|subpages]]' .. sep
res = res + '[' + fullurl(fname, 'action=delete&wpReason=' + urlencode('[[' + fullpagename + '#' + fname + ']]')) + ' delete]'
+
res = res .. '[' .. fullurl(fname, 'action=delete&wpReason=' .. urlencode('[[' .. fullpagename .. '#' .. fname .. ']]')) .. ' delete]'
res = res + ')</span>'
+
res = res .. ')</span>'
 
 
 
return res
 
return res

Revision as of 15:32, 22 December 2016

Documentation for this module may be created at Module:TfdLinks/doc

-- This module implements [[Template:Tfd links]]
local p = {}

local function urlencode(text)
	-- Return equivalent of {{urlencode:text}}.
	local function byte(char)
		return string.format('%%%02X', string.byte(char))
	end
	return text:gsub('[^ %w%-._]', byte):gsub(' ', '+')
end

local function fullurl(t, a)
	return '//en.wikipedia.org/w/index.php?title=' .. t .. '&' .. a
end

function p.main(frame)
	local args = frame:getParent().args
	local ns = (args['catfd'] and args['catfd'] ~= '') and 'Category' or 'Template'
	local tname = mw.getContentLanguage():ucfirst(args['1'] or 'Example')
	local fname = ns .. ':' .. tname
	local ymd = args['2'] or ''
	local fullpagename = (ymd ~= '')
		and	'WP:Templates for discussion/Log' .. ymd
		or frame:preprocess('{{FULLPAGENAME}}')
	local sep = '&nbsp;<b>·</b> '
	
	local res = '<span id="' .. ns .. ':' .. tname 
		.. '" class="plainlinks nourlexpansion 1x">'
		.. '[[:' .. ns .. ':' .. tname .. ']]&nbsp;('
	
	if ymd ~= '' then
		local dmy = frame:expandTemplate{ title = 'date', args = {args['2'], 'dmy'} } 
		res = res .. '[[' .. fullpagename .. '#' .. fname .. '|' .. dmy .. ') ('
	end
	res = res .. '[' .. fullurl(fname, 'action=edit') .. ' edit]' .. sep
	res = res .. '[[' .. ns .. ' talk:' .. tname .. '|talk]]' .. sep
	res = res .. '[' .. fullurl(fname, 'action=history') .. ' history' .. sep
	if ns ~= 'Category' then
		res = res .. '[' .. fullurl('Special:Whatlinkshere/' .. fname, 'limit=999') .. ' links]' .. sep
	end
	res = res .. '[' .. fullurl('Special:Log', 'page=' .. urlencode(fname)) .. ' logs]' .. sep
	res = res .. '[[Special:PrefixIndex/' .. fname .. '|subpages]]' .. sep
	res = res .. '[' .. fullurl(fname, 'action=delete&wpReason=' .. urlencode('[[' .. fullpagename .. '#' .. fname .. ']]')) .. ' delete]'
	res = res .. ')</span>'
	
	return res
end

return p