https://mw.lojban.org/index.php?title=Module:Redirect_template&feed=atom&action=history
Module:Redirect template - Revision history
2024-03-28T11:12:43Z
Revision history for this page on the wiki
MediaWiki 1.38.4
https://mw.lojban.org/index.php?title=Module:Redirect_template&diff=113034&oldid=prev
Gleki: 1 revision imported
2015-04-20T09:36:12Z
<p>1 revision imported</p>
<p><b>New page</b></p><div>require('Module:No globals')<br />
<br />
local p = {}<br />
<br />
-- key is beginning of arg name. value is table with namespace number and link<br />
-- alternatively, a function taking the namespace number and returning a validity<br />
-- can be used<br />
local namespaceCategories = {<br />
all = { function() return true end },<br />
main = { 0, '[[wp:mainspace|main]]' },<br />
help = { 12, '[[wp:help namespace|help]]' },<br />
portal = { 100, '[[wp:portal|portal]]' },<br />
talk = { function(n) return n > 0 and n%2 == 1 end, '[[Help:Using talk pages|talk]]' },<br />
template = { 10, '[[wp:template namespace|template]]' },<br />
wikipedia = { 4, '[[wp:project namespace|Wikipedia project]]' },<br />
category = { 14, '[[wp:categorization|category]]' },<br />
user = { 2, '[[wp:user pages|user]]' },<br />
}<br />
<br />
-- Don't convert blank category to nil<br />
local function valueFunc(key, val)<br />
if type(val) == 'string' then<br />
val = val:match('^%s*(.-)%s*$')<br />
if val == '' and key ~= 'category' and key ~= 'embed' then<br />
return nil<br />
end<br />
end<br />
return val<br />
end<br />
<br />
local function getPrettyName(args)<br />
for k in pairs(namespaceCategories) do<br />
if args[k .. ' category'] then<br />
return "'''[[:Category:" .. args[k .. ' category'] .. "|" .. args.name .. "]]''': "<br />
end<br />
end<br />
return "'''" .. args.name .. "''': "<br />
end<br />
<br />
function p.core(frame, args)<br />
if not args then<br />
args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:Redirect template/core', valueFunc = valueFunc})<br />
end<br />
local namespace = mw.title.getCurrentTitle().namespace<br />
local otherCategory = args['other category'] and (args.category or string.format('[[Category:%s]]', args['other category']))<br />
local embedPossible = args.embed == nil or args.embed == 'yes'<br />
<br />
--- XXX: this is a HORRIBLE HACK. kill it with fire as soon as https://bugzilla.wikimedia.org/show_bug.cgi?id=12974 is fixed<br />
local beCompatibleWithBug12974 = args.info and (args.info:find('^[:;#*]', 1) == 1 or args.info:find('{|', 1, true) == 1) and '\n' or ' '<br />
<br />
local retval = string.format('*%sThis is a redirect%s%s.%s%s\n',<br />
embedPossible and args.name and getPrettyName(args) or '',<br />
args.from and (' from ' .. args.from) or '',<br />
args.to and (' to ' .. args.to) or '',<br />
args.info and beCompatibleWithBug12974 or '',<br />
args.info or ''<br />
)<br />
for k,v in pairs(namespaceCategories) do<br />
if args[k .. ' category'] then<br />
if type(v[1]) == 'function' and v[1](namespace) or v[1] == namespace then<br />
retval = retval .. (args.category or string.format('[[Category:%s]]', args[k .. ' category']))<br />
elseif args['other category'] then<br />
retval = retval .. otherCategory<br />
else<br />
retval = retval .. frame:expandTemplate{title = 'Incorrect redirect template', args = {v[2]}}<br />
end<br />
end<br />
end<br />
return retval<br />
end<br />
<br />
function p.main(frame)<br />
local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:Redirect template', valueFunc = valueFunc})<br />
local retval = p.core(frame, args)<br />
if mw.title.getCurrentTitle().namespace == 0 then<br />
if args.printworthy == 'yes' then<br />
return retval .. (args.category or '[[Category:Printworthy redirects]]')<br />
elseif args.printworthy == 'no' then<br />
return retval .. (args.category or '[[Category:Unprintworthy redirects]]')<br />
end<br />
end<br />
return retval<br />
end<br />
<br />
return p</div>
Gleki