Jump to content

Module:Redirect template

Permanently protected module
From Wikipedia, the free encyclopedia

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]]'},draft={118,'[[wp:drafts|draft]]'},}-- 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://phabricator.wikimedia.org/T14974 is fixed--- [[phab:T14974]] was previously known as [[bugzilla:12974]] https://bugzilla.wikimedia.org/show_bug.cgi?id=12974localbeCompatibleWithBug14974=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.infoandbeCompatibleWithBug14974or'',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
close