Editing Module:Redirect template

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 18: Line 18:
 
}
 
}
  
-- remove whitespaces from beginning and end of args
+
-- Don't convert blank category to nil
 
local function valueFunc(key, val)
 
local function valueFunc(key, val)
 
if type(val) == 'string' then
 
if type(val) == 'string' then
 
val = val:match('^%s*(.-)%s*$')
 
val = val:match('^%s*(.-)%s*$')
if val == '' then
+
if val == '' and key ~= 'category' and key ~= 'embed' then
 
return nil
 
return nil
 
end
 
end
Line 32: Line 32:
 
for k in pairs(namespaceCategories) do
 
for k in pairs(namespaceCategories) do
 
if args[k .. ' category'] then
 
if args[k .. ' category'] then
return string.format("'''[[:Category:%s|%s]]''': ", args[k .. ' category'], args.name)
+
return "'''[[:Category:" .. args[k .. ' category'] .. "|" .. args.name .. "]]''': "
 
end
 
end
 
end
 
end
return string.format("'''%s''': ", args.name)
+
return "'''" .. args.name .. "''': "
 
end
 
end
  
function p.main(frame)
+
function p.core(frame, args)
local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:Redirect template', valueFunc = valueFunc})
+
if not args then
 +
args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:Redirect template/core', valueFunc = valueFunc})
 +
end
 
local namespace = mw.title.getCurrentTitle().namespace
 
local namespace = mw.title.getCurrentTitle().namespace
 +
local otherCategory = args['other category'] and (args.category or string.format('[[Category:%s]]', args['other category']))
 +
local embedPossible = args.embed == nil or args.embed == 'yes'
  
 
--- XXX: this is a HORRIBLE HACK. kill it with fire as soon as https://bugzilla.wikimedia.org/show_bug.cgi?id=12974 is fixed
 
--- XXX: this is a HORRIBLE HACK. kill it with fire as soon as https://bugzilla.wikimedia.org/show_bug.cgi?id=12974 is fixed
 
local beCompatibleWithBug12974 = args.info and (args.info:find('^[:;#*]', 1) == 1 or args.info:find('{|', 1, true) == 1) and '\n' or ' '
 
local beCompatibleWithBug12974 = args.info and (args.info:find('^[:;#*]', 1) == 1 or args.info:find('{|', 1, true) == 1) and '\n' or ' '
 
 
local content = string.format('\n<div class="rcat %s">\n*%sThis is a redirect%s%s.%s%s\n</div>',
+
local retval = string.format('*%sThis is a redirect%s%s.%s%s',
args.id and ('rcat-' .. string.gsub(args.id, ' ', '_')) or '',
+
embedPossible and args.name and getPrettyName(args) or '',
args.name and getPrettyName(args) or '',
 
 
args.from and (' from ' .. args.from) or '',
 
args.from and (' from ' .. args.from) or '',
 
args.to and (' to ' .. args.to) or '',
 
args.to and (' to ' .. args.to) or '',
Line 53: Line 56:
 
args.info or ''
 
args.info or ''
 
)
 
)
 
 
for k,v in pairs(namespaceCategories) do
 
for k,v in pairs(namespaceCategories) do
 
if args[k .. ' category'] then
 
if args[k .. ' category'] then
 
if type(v[1]) == 'function' and v[1](namespace) or v[1] == namespace then
 
if type(v[1]) == 'function' and v[1](namespace) or v[1] == namespace then
content = content .. string.format('[[Category:%s]]', args[k .. ' category'])
+
retval = retval .. (args.category or string.format('[[Category:%s]]', args[k .. ' category']))
 
elseif args['other category'] then
 
elseif args['other category'] then
content = content .. string.format('[[Category:%s]]', args['other category'])
+
retval = retval .. otherCategory
 
else
 
else
content = content .. frame:expandTemplate{title = 'Incorrect redirect template', args = {v[2]}}
+
retval = retval .. frame:expandTemplate{title = 'Incorrect redirect template', args = {v[2]}}
 
end
 
end
 
end
 
end
 
end
 
end
 +
return retval
 +
end
  
if namespace == 0 then
+
function p.main(frame)
local yesno = require('Module:Yesno')
+
local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:Redirect template', valueFunc = valueFunc})
if yesno(args.printworthy) == true then
+
local retval = p.core(frame, args)
return content .. '[[Category:Printworthy redirects]]'
+
if mw.title.getCurrentTitle().namespace == 0 then
elseif yesno(args.printworthy) == false then
+
if args.printworthy == 'yes' then
return content .. '[[Category:Unprintworthy redirects]]'
+
return retval .. (args.category or '[[Category:Printworthy redirects]]')
 +
elseif args.printworthy == 'no' then
 +
return retval .. (args.category or '[[Category:Unprintworthy redirects]]')
 
end
 
end
 
end
 
end
return content
+
return retval
 
end
 
end
  
 
return p
 
return p

Please note that all contributions to All About Ayrshire may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see All About Ayrshire:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)

Template used on this page: