This module produces a hatnote for disambiguating a page that is linked to by a given redirect. It implements the {{redirect}} hatnote template.
Penggunaan dari teks wikiPenggunaan dari teks wiki
Modul tidak dapat dijalankan secara langsung dari teks wiki. Untuk itu gunakanlah templat {{redirect}}.
Penggunaan dari LuaPenggunaan dari Lua
Untuk menggunakan modul ini dari Lua, pertama kita harus memuat modulnya.
localmRedirectHatnote=require('Modul:Redirect hatnote')
Modul dapat digunakan dengan sintaks berikut:
mRedirectHatnote._redirect(redirect,data,options,titleObj)
Dokumentasi di atas ditransklusikan dari Modul:Redirect hatnote/doc. (sunting | riwayat)
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
--[[ -- This module produces a "redirect" hatnote. It looks like this: -- '"X" redirects here. For other uses, see Y.' -- It implements the {{redirect}} template. --]] localmHatnote=require('Module:Hatnote') localmHatList=require('Module:Hatnote list') localmArguments--lazily initialize locallibraryUtil=require('libraryUtil') localcheckType=libraryUtil.checkType localcheckTypeMulti=libraryUtil.checkTypeMulti localp={} -------------------------------------------------------------------------------- -- Helper functions -------------------------------------------------------------------------------- localfunctiongetTitle(...) --Calls mw.title.new and returns either a title object, or nil on error localsuccess,titleObj=pcall(mw.title.new,...) returnsuccessandtitleObjornil end -------------------------------------------------------------------------------- -- Main functions -------------------------------------------------------------------------------- functionp.redirect(frame) mArguments=require('Module:Arguments') localargs=mArguments.getArgs(frame,{parentOnly=true}) --Get number of redirects localnumRedirects=tonumber(frame.args[1])or1 -- Create the options table. localoptions={} options.selfref=args.selfref returnp._redirect(args,numRedirects,options) end functionp._redirect(args,numRedirects,options,currentTitle,redirectTitle,targetTitle) -- Validate the input. Don't bother checking currentTitle, redirectTitle or -- targetTitle, as they are only used in testing. checkType('_redirect',1,args,'table') checkType('_redirect',2,numRedirects,'number',true) numRedirects=numRedirectsor1 checkType('_redirect',3,options,'table',true) options=optionsor{} currentTitle=currentTitleormw.title.getCurrentTitle() -- Get the table of redirects localredirect={} fori=1,numRedirectsdo -- Return an error if a redirect parameter is missing. ifnotargs[i]then returnmHatnote.makeWikitextError( 'missing redirect parameter', 'Template:Redirect#Errors', args.category ) end redirect[i]=args[i] end -- Generate the text. localformattedRedirect={} fork,vinpairs(redirect)do formattedRedirect[k]=mHatnote.quote(v) end localtext={ mHatList.andList(formattedRedirect)..' '..(#redirect==1and'beralih'or'dialihkan')..' ke halaman ini.', mHatList._forSee(args,#redirect+1,{title=redirect[1],extratext=args.text}) } text=table.concat(text,' ') -- Functionality for adding categories localcategoryTable={} localfunctionaddCategory(cat) ifcatandcat~=''then -- Add by index to avoid duplicates categoryTable[string.format('[[Category:%s]]',cat)]=true end end --Generate tracking categories localmhOptions={} localredirTitle fork,vinpairs(redirect)do -- We don't need a tracking category if the template invocation has been -- copied directly from the docs, or if we aren't in main- or category-space. ifnotv:find('^REDIRECT%d*$')andv~='TERM'-- andcurrentTitle.namespace==0orcurrentTitle.namespace==14 then redirTitle=redirectTitleorgetTitle(v) ifnotredirTitleornotredirTitle.existsthen addCategory('Missing redirects') elseifnotredirTitle.isRedirectthen ifstring.find(redirTitle:getContent(),'#invoke:RfD')then addCategory('Articles with redirect hatnotes impacted by RfD') else addCategory('Articles with redirect hatnotes needing review') end else localtarget=targetTitleorredirTitle.redirectTarget iftargetandtarget~=currentTitlethen addCategory('Articles with redirect hatnotes needing review') end end end -- Generate the options to pass to [[Module:Hatnote]]. ifcurrentTitle.namespace==0andnotmhOptions.selfref andredirTitleandredirTitle.namespace~=0 then -- We are on a mainspace page, and the hatnote starts with something -- like "Wikipedia:Foo redirects here", so automatically label it as -- a self-reference. mhOptions.selfref=true else mhOptions.selfref=options.selfref end end --concatenate all the categories localcategory='' fork,vinpairs(categoryTable)do category=category..k end returnmHatnote._hatnote(text,mhOptions)..category end returnp