Editing Module:Redirect template
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: | ||
} | } | ||
− | -- | + | -- 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 | + | return "'''[[:Category:" .. args[k .. ' category'] .. "|" .. args.name .. "]]''': " |
end | end | ||
end | end | ||
− | return | + | return "'''" .. args.name .. "''': " |
end | end | ||
− | function p. | + | function p.core(frame, args) |
− | + | 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 | + | local retval = string.format('*%sThis is a redirect%s%s.%s%s', |
− | + | embedPossible and 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 | ||
− | + | retval = retval .. (args.category or string.format('[[Category:%s]]', args[k .. ' category'])) | |
elseif args['other category'] then | elseif args['other category'] then | ||
− | + | retval = retval .. otherCategory | |
else | else | ||
− | + | retval = retval .. frame:expandTemplate{title = 'Incorrect redirect template', args = {v[2]}} | |
end | end | ||
end | end | ||
end | end | ||
+ | return retval | ||
+ | end | ||
− | + | function p.main(frame) | |
− | + | local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:Redirect template', valueFunc = valueFunc}) | |
− | if | + | local retval = p.core(frame, args) |
− | return | + | if mw.title.getCurrentTitle().namespace == 0 then |
− | elseif | + | if args.printworthy == 'yes' then |
− | return | + | 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 | + | return retval |
end | end | ||
return p | return p |