https://tnfshwiki.tfcis.org/index.php?title=%E6%A8%A1%E7%B5%84:Redirect_template&feed=atom&action=history模組:Redirect template - 修訂歷史2024-03-28T20:59:36Z本 Wiki 上此頁面的修訂歷史MediaWiki 1.39.2https://tnfshwiki.tfcis.org/index.php?title=%E6%A8%A1%E7%B5%84:Redirect_template&diff=4491&oldid=prevXiplus:新頁面: require('Module:No globals') local p = {} -- key is beginning of arg name. value is table with namespace number and link -- alternatively, a function taking the namespace number and...2016-04-10T09:31:34Z<p>新頁面: require('Module:No globals') local p = {} -- key is beginning of arg name. value is table with namespace number and link -- alternatively, a function taking the namespace number and...</p>
<p><b>新頁面</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, '[[Wikipedia:條目|條目]]' },<br />
help = { 12, '[[wp:幫助頁面|幫助]]' },<br />
portal = { 100, '[[wp:主題|主題]]' },<br />
talk = { function(n) return n > 0 and n%2 == 1 end, '[[Help:使用討論頁|討論]]' },<br />
template = { 10, '[[wp:模板空間|模板]]' },<br />
wikipedia = { 4, '[[wp:項目空間|竹園Wiki項目]]' },<br />
category = { 14, '[[wp:分類|分類]]' },<br />
user = { 2, '[[wp:用戶頁|用戶]]' },<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('<hr />%s這是%s%s重定向。%s%s\n',<br />
embedPossible and args.name and getPrettyName(args) or '',<br />
args.from and ( ( args.to and '由' or '') .. args.from .. (args.to and '' or '的' ) ) or '',<br />
args.to and ( ( args.from and ',' or '') .. '指向' .. 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 = '不正確的重定向模板', 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:值得列印的重定向]]')<br />
elseif args.printworthy == 'no' then<br />
return retval .. (args.category or '[[Category:不需列印的重定向]]')<br />
end<br />
end<br />
return retval<br />
end<br />
<br />
return p</div>Xiplus