Difference between revisions of "Module:TfdLinks"
From MINR.ORG WIKI
(testing a lua implementation of template:tfd links) |
Rickyboy320 (talk | contribs) m (14 revisions imported: Import Template Tlx and subtemplates) |
||
(13 intermediate revisions by 3 users not shown) | |||
Line 10: | Line 10: | ||
end | end | ||
− | local function | + | local function fullurllink(t, a, s) |
− | return '//en.wikipedia.org/w/index.php?title=' | + | return '[//en.wikipedia.org/w/index.php?title=' .. urlencode(t) .. '&' .. a .. ' ' .. s .. ']' |
end | end | ||
function p.main(frame) | function p.main(frame) | ||
− | local args = frame | + | local args = frame:getParent().args |
− | local ns = (args['catfd'] and args['catfd'] ~= '') and 'Category' or 'Template' | + | local ns = ((args['catfd'] and args['catfd'] ~= '') and 'Category') |
+ | or ((args['module'] and args['module'] ~= '') and 'Module') | ||
+ | or 'Template' | ||
local tname = mw.getContentLanguage():ucfirst(args['1'] or 'Example') | local tname = mw.getContentLanguage():ucfirst(args['1'] or 'Example') | ||
− | local fname = ns | + | 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' | + | and 'WP:Templates for discussion/Log/' .. ymd |
or frame:preprocess('{{FULLPAGENAME}}') | or frame:preprocess('{{FULLPAGENAME}}') | ||
local sep = ' <b>·</b> ' | local sep = ' <b>·</b> ' | ||
− | local res = '<span id="' | + | local res = '<span id="' .. ns .. ':' .. tname |
− | + | .. '" class="plainlinks nourlexpansion 1x">' | |
− | + | .. '[[:' .. ns .. ':' .. tname .. ']] (' | |
if ymd ~= '' then | if ymd ~= '' then | ||
− | local dmy = frame:expandTemplate{ title = 'date', args = { | + | local dmy = frame:expandTemplate{ title='date', args={ymd, 'dmy'} } |
− | res = res | + | res = res .. '[[' .. fullpagename .. '#' .. fname |
+ | .. '|' .. dmy .. ']]) (' | ||
end | end | ||
− | res = res | + | res = res .. fullurllink(fname, 'action=edit', 'edit') .. sep |
− | res = res | + | res = res .. '[[' .. ns .. ' talk:' .. tname .. '|talk]]' .. sep |
− | res = res | + | res = res .. fullurllink(fname, 'action=history', 'history') .. sep |
if ns ~= 'Category' then | if ns ~= 'Category' then | ||
− | res = res | + | res = res .. fullurllink('Special:Whatlinkshere/' |
+ | .. fname, 'limit=999', 'links') .. sep | ||
end | end | ||
− | res = res | + | res = res .. fullurllink('Special:Log', 'page=' |
− | res = res | + | .. urlencode(fname), 'logs') .. sep |
− | res = res | + | res = res .. '[[Special:PrefixIndex/' .. fname .. '/|subpages]]' |
− | res = res | + | res = res .. '<span class="sysop-show">' .. sep .. fullurllink(fname, 'action=delete&wpReason=' |
+ | .. urlencode('[[' .. fullpagename .. '#' .. fname .. ']]'), 'delete') .. '</span>' | ||
+ | res = res .. ')</span>' | ||
return res | return res |
Latest revision as of 19:29, 11 August 2017
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 fullurllink(t, a, s) return '[//en.wikipedia.org/w/index.php?title=' .. urlencode(t) .. '&' .. a .. ' ' .. s .. ']' end function p.main(frame) local args = frame:getParent().args local ns = ((args['catfd'] and args['catfd'] ~= '') and 'Category') or ((args['module'] and args['module'] ~= '') and 'Module') 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 = ' <b>·</b> ' local res = '<span id="' .. ns .. ':' .. tname .. '" class="plainlinks nourlexpansion 1x">' .. '[[:' .. ns .. ':' .. tname .. ']] (' if ymd ~= '' then local dmy = frame:expandTemplate{ title='date', args={ymd, 'dmy'} } res = res .. '[[' .. fullpagename .. '#' .. fname .. '|' .. dmy .. ']]) (' end res = res .. fullurllink(fname, 'action=edit', 'edit') .. sep res = res .. '[[' .. ns .. ' talk:' .. tname .. '|talk]]' .. sep res = res .. fullurllink(fname, 'action=history', 'history') .. sep if ns ~= 'Category' then res = res .. fullurllink('Special:Whatlinkshere/' .. fname, 'limit=999', 'links') .. sep end res = res .. fullurllink('Special:Log', 'page=' .. urlencode(fname), 'logs') .. sep res = res .. '[[Special:PrefixIndex/' .. fname .. '/|subpages]]' res = res .. '<span class="sysop-show">' .. sep .. fullurllink(fname, 'action=delete&wpReason=' .. urlencode('[[' .. fullpagename .. '#' .. fname .. ']]'), 'delete') .. '</span>' res = res .. ')</span>' return res end return p