--[[-- This module produces a link to a main article or articles. It implements the-- template {{main}}.-- -- If the module is used in category or category talk space, it produces "The-- main article for this category is xxx." Otherwise, it produces-- "Main article: xxx".--]]localmHatnote=require('Module:Hatnote')localmHatlist=require('Module:Hatnote list')localmArguments-- lazily initialiselocalp={}functionp.main(frame)mArguments=require('Module:Arguments')localargs=mArguments.getArgs(frame,{parentOnly=true})localpages={}fork,vinpairs(args)doiftype(k)=='number'thenlocaldisplay=args['label '..k]orargs['l'..k]localpage=displayandmw.ustring.format('%s|%s',mw.ustring.gsub(v,'|.*$',''),display)orvpages[#pages+1]=pageendendif#pages==0andmw.title.getCurrentTitle().namespace==0thenreturnmHatnote.makeWikitextError('no page names specified','Template:Main#Errors',args.category)endlocaloptions={selfref=args.selfref}returnp._main(pages,options)endfunctionp._main(args,options)-- Get the list of pages. If no first page was specified we use the current-- page name.localcurrentTitle=mw.title.getCurrentTitle()if#args==0thenargs={currentTitle.text}endlocalfirstPage=mw.ustring.gsub(args[1],'|.*$','')-- Find the pagetype.localpageType=mHatnote.findNamespaceId(firstPage)==0and'مقالهٔ'or'صفحهٔ'-- Make the formatted link textlist=mHatlist.andList(args,true)-- Build the text.localisPlural=#args>1localmainFormlocalcurNs=currentTitle.namespaceif(curNs==14)or(curNs==15)then--category/talk namespacesmainForm=isPluraland'%sهای اصلی این [[راهنما:رده|رده]]، %s هستند.'or'%s اصلی این [[راهنما:رده|رده]]، %s است.'elsemainForm=isPluraland'%s اصلی: %s'or'%s اصلی: %s'endlocaltext=mw.ustring.format(mainForm,pageType,list)-- Process the options and pass the text to the _rellink function in-- [[Module:Hatnote]].options=optionsor{}localhnOptions={selfref=options.selfref}returnmHatnote._hatnote(text,hnOptions)endreturnp