Zeroclanzhang(讨论 | 贡献)2024年1月21日 (日) 19:28的版本 (创建页面,内容为“require('strict') local p = {} -- key is beginning of arg name. value is table with namespace number and link -- alternatively, a function taking the namespace number and returning a validity -- can be used local namespaceCategories = { all = { function() return true end }, main = { 0, 'main' }, help = { 12, 'help' }, portal = { 100, 'portal' }, talk = { function(n) return n > 0 and n%2 == 1 end, '[[He…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
This Lua module is used on many pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them.
This module depends on the following other modules:
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing.
This module implements {{redirect template}}. Please see the template page for documentation.
require('strict')localp={}-- key is beginning of arg name. value is table with namespace number and link-- alternatively, a function taking the namespace number and returning a validity-- can be usedlocalnamespaceCategories={all={function()returntrueend},main={0,'[[wp:mainspace|main]]'},help={12,'[[wp:help namespace|help]]'},portal={100,'[[wp:portal|portal]]'},talk={function(n)returnn>0andn%2==1end,'[[Help:Talk pages|talk]]'},template={10,'[[wp:template namespace|template]]'},wikipedia={4,'[[wp:project namespace|Wikipedia project]]'},category={14,'[[wp:categorization|category]]'},user={2,'[[wp:user pages|user]]'},}-- remove whitespaces from beginning and end of argslocalfunctionvalueFunc(key,val)iftype(val)=='string'thenval=val:match('^%s*(.-)%s*$')ifval==''thenreturnnilendendreturnvalendlocalfunctiongetPrettyName(args)forkinpairs(namespaceCategories)doifargs[k..' category']thenreturnstring.format("'''[[:Category:%s|%s]]''': ",args[k..' category'],args.name)endendreturnstring.format("'''%s''': ",args.name)endfunctionp.main(frame)localargs=require('Module:Arguments').getArgs(frame,{wrappers='Template:Redirect template',valueFunc=valueFunc})localnamespace=mw.title.getCurrentTitle().namespace--- XXX: this is a HORRIBLE HACK. kill it with fire as soon as https://bugzilla.wikimedia.org/show_bug.cgi?id=12974 is fixedlocalbeCompatibleWithBug12974=args.infoand(args.info:find('^[:;#*]',1)==1orargs.info:find('{|',1,true)==1)and'\n'or' 'localcontent=string.format('\n<div class="rcat %s">\n*%sThis is a redirect%s%s.%s%s\n</div>',args.idand('rcat-'..string.gsub(args.id,' ','_'))or'',args.nameandgetPrettyName(args)or'',args.fromand(' from '..args.from)or'',args.toand(' to '..args.to)or'',args.infoandbeCompatibleWithBug12974or'',args.infoor'')fork,vinpairs(namespaceCategories)doifargs[k..' category']theniftype(v[1])=='function'andv[1](namespace)orv[1]==namespacethenifargs.sortkeythencontent=content..string.format('[[Category:%s|%s]]',args[k..' category'],args.sortkey)elsecontent=content..string.format('[[Category:%s]]',args[k..' category'])endelseifargs['other category']thenifargs.sortkeythencontent=content..string.format('[[Category:%s|%s]]',args['other category'],args.sortkey)elsecontent=content..string.format('[[Category:%s]]',args['other category'])endelsecontent=content..frame:expandTemplate{title='Incorrect redirect template',args={v[2]}}endendendifnamespace==0thenlocalyesno=require('Module:Yesno')ifyesno(args.printworthy)==truethenreturncontent..'[[Category:Printworthy redirects]]'elseifyesno(args.printworthy)==falsethenreturncontent..'[[Category:Unprintworthy redirects]]'endendreturncontentendreturnp