Jump to content
Wikipedia The Free Encyclopedia

Module:RFC

From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
This module depends on the following other modules:

Implements {{Sum RFC }}, {{Ref RFC }}, and {{IETF RFC }}. Please see documentation for those templates.

Usage

{{Sum RFC}}{{#invoke:RFC|sum}}

{{Ref RFC}}{{#invoke:RFC|ref}}

{{IETF RFC}}{{#invoke:RFC|IETF}}

The above documentation is transcluded from Module:RFC/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.

 -- Implements {{Sum RFC}}, {{Ref RFC}}, and {{IETF RFC}}
 require('strict')
 localgetArgs=require('Module:Arguments').getArgs
 localerr=require('Module:Error')._error
 localyesno=require('Module:Yesno')
 localp={}

 localsectionMatch=function(n,t)return'<section%s+begin=rfc'..n..t..'%s*/>(.-)<section%s+end=rfc'..n..t..'%s*/>'end
 localisblank=function(v)return(vor'')==''end

 localfunctionsummary(args,dbContent,frame)
 --implements {{Ref RFC/summary}}, which is only used by {{Sum RFC}}
 --args.ref(false): add a reference to the summary.
 --args.plain(false): do not prepend the RFC number with 'RFC'.
 --args.title(true): include the title of the RFC.
 --args.status(true): include the status of the RFC.
 --args.notes(false): include the notes of the RFC.
 --args.comment(''): add a {{Block indent}} with a comment.
 ifnotframethenframe=mw.getCurrentFrame()end
 localrefContent=""
 localrfc=isblank(tonumber(args[1]))and0ortonumber(args[1])
 ifnotdbContentthen
 dbContent=mw.title.new('Template:Ref RFC/db/'..math.floor(rfc/100)).content
 end

 ifyesno(args.reforfalse,false)then
 refContent=p._ref({[1]=rfc,notes=yesno(args.refnotesortrue,true)and'yes'or'no'},dbContent,frame)
 end

 ifyesno(args.plainorfalse,false)then
 returnp._IETF({[1]=rfc,plainlink='yes'})..refContent
 end

 localoutput={}
 table.insert(output,p._IETF({[1]=rfc,link='no'}))
 ifyesno(args.titleortrue,true)then
 localtitleContent=mw.ustring.match(dbContent,sectionMatch(rfc,'title'))

 ifrfc<10000thentable.insert(output,'&numsp;')end
 ifrfc<1000thentable.insert(output,'&numsp;')end
 ifrfc<100thentable.insert(output,'&numsp;')end
 ifrfc<10thentable.insert(output,'&numsp;')end
 table.insert(output,string.format(
 '&ndash;&numsp;"%s"%s ',
 frame:extensionTag('cite',frame:preprocess(titleContent)..','),
 refContent
 ))
 ifyesno(args.statusortrue,true)then
 localstatusContent=mw.ustring.match(dbContent,sectionMatch(rfc,'status'))
 table.insert(output,"''"..statusContent..".''")
 end
 table.insert(output,' ')
 ifyesno(args.notesorfalse,false)then
 localnotesContent=mw.ustring.match(dbContent,sectionMatch(rfc,'notes'))
 table.insert(output,frame:preprocess(notesContent))
 end
 elseifyesno(args.reforfalse,false)then
 table.insert(output,refContent)
 end
 if(notisblank(args.comment))then
 table.insert(output,frame:expandTemplate{title="Block indent",args={text=args.comment}})
 end
 returntable.concat(output)
 end

 localfunctionsecpage(section,page,pp)
 --implements {{Ref RFC/secpage}}, which is only used by {{Ref RFC/getref}}
 localoutput={}
 ifnotisblank(section)then
 table.insert(output,'sec. '..section)
 ifnotisblank(page)ornotisblank(pp)then
 table.insert(output,',&nbsp;')
 end
 end

 ifnotisblank(page)then
 table.insert(output,'p. '..page)
 elseifnotisblank(pp)then
 table.insert(output,'pp. '..pp)
 end

 ifnotisblank(page)ornotisblank(pp)ornotisblank(section)then
 table.insert(output,'.')
 end

 returntable.concat(output)
 end

 localfunctiongetref(rfc,section,page,pp,notes,quote,status,dbContent,frame)
 -- implements {{Ref RFC/getref}}, which is only used by {{REf RFC}}
 ifnotframethenframe=mw.getCurrentFrame()end
 localoutput={}
 localrefContent=mw.ustring.match(dbContent,sectionMatch(rfc,'ref'))
 table.insert(output,refContent..' ')
 ifyesno(statusortrue,true)then
 localstatusContent=mw.ustring.match(dbContent,sectionMatch(rfc,'status'))
 table.insert(output,"''"..statusContent..".''")
 end
 table.insert(output,' '..secpage(section,page,pp)..' ')
 ifyesno(notesortrue,true)then
 localnotesContent=mw.ustring.match(dbContent,sectionMatch(rfc,'notes'))
 table.insert(output,notesContent)
 end
 table.insert(output,' ')
 ifnotisblank(quote)then
 table.insert(output,frame:extensionTag('q',quote))
 end
 returntable.concat(output)
 end

 functionp._IETF(args,frame)
 -- Implements {{IETF RFC}}
 ifnotframethenframe=mw.getCurrentFrame()end
 ifnotisblank(args[1])then
 localcll=require('Module:Catalog lookup link')._main
 localcllArgs={
 ['link-prefix']='https://www.rfc-editor.org/rfc/rfc',
 ['list-leadout']=args.leadoutor''
 }
 fori=1,9do
 cllArgs[i]=tonumber(args[i])
 end
 ifyesno(args.plainlinkorfalse,false)==falseandyesno(args.linkortrue,true)==truethen
 cllArgs['article-link']='RFC (identifier)'
 end
 ifyesno(args.plainlinkorfalse,false)==falsethen
 cllArgs['article-name']='RFC'
 end
 returncll(cllArgs,frame)
 else
 localerrMsg='Parameter error in {{[[Template:IETF RFC|IETF RFC]]}}: Missing [[RFC (identifier)|RFC]].'
 returnerr({message=errMsg,style='font-size:inherit',tag='span'})
 end
 end
 functionp.IETF(frame)
 returnp._IETF(getArgs(frame),frame)
 end

 functionp._ref(args,dbContent,frame)
 --implements {{Ref RFC}}
 ifnotframethenframe=mw.getCurrentFrame()end
 localrfc=tonumber(args[1])
 ifrfcthen
 localdb='Template:Ref RFC/db/'..math.floor(rfc/100)
 if(notdbContent)andrfcthen
 dbContent=mw.title.new(db).content
 end
 ifdbContentthen
 localrefContent=mw.ustring.match(dbContent,sectionMatch(rfc,'ref'))
 ifrefContentthen
 localoutput={}
 ifyesno(args['repeat']orfalse,false)then
 output[1]=frame:extensionTag('ref','',{name='rfc'..rfc})
 else
 output[1]=getref(rfc,args.section,args.p,args.pp,args.notes,args.quote,args.status,dbContent,frame)
 ifyesno(args.refortrue,true)then
 localrefname=''
 ifisblank(args.p)andisblank(args.pp)andisblank(args.section)andisblank(args.quote)then
 refname='rfc'..rfc
 end
 output[1]=frame:extensionTag('ref',output[1],{name=refname})
 else
 output[1]=frame:preprocess(output[1])
 end
 end
 ifnotisblank(args.rp)then
 table.insert(output,frame:expandTemplate{title='rp',args={page=args.rp}})
 end
 ifnotisblank(args.rpp)then
 table.insert(output,frame:expandTemplate{title='rp',args={pages=args.rpp}})
 end
 ifnotisblank(args.rsection)then
 table.insert(output,frame:expandTemplate{title='rp',args={at='§'..args.rsection}})
 end
 returntable.concat(output)
 else
 localerrMsg='REFERENCE FOR RFC'..rfc..' IS NOT DEFINED YET.'
 returnerr({errMsg})..' You are invited to add it [['..db..'|here]].'
 end
 else
 localerrMsg='REFERENCE FOR RFC'..rfc..' IS NOT DEFINED YET.'
 returnerr({errMsg})..' You are invited to add it [[Template:Ref RFC/db|here]].'
 end
 else
 localerrMsg='Parameter error in {{[[Template:Ref RFC|Ref RFC]]}}: Missing [[RFC (identifier)|RFC]].'
 returnerr({message=errMsg,style='font-size:inherit',tag='span'})
 end
 end
 functionp.ref(frame)
 returnp._ref(getArgs(frame),nil,frame)
 end

 functionp._sum(args,frame)
 --implements {{Sum RFC}}
 ifnotframethenframe=mw.getCurrentFrame()end
 ifnotisblank(args[1])then
 localrfc=tonumber(args[1])
 ifrfcthen
 localdb='Template:Ref RFC/db/'..math.floor(rfc/100)
 localdbContent=mw.title.new(db).content
 ifdbContentthen
 localtitleContent=mw.ustring.match(dbContent,sectionMatch(rfc,'title'))
 iftitleContentthen
 returnsummary(args,dbContent,frame)
 else
 localerrMsg='Reference for RFC'..rfc..' is not defined yet.'
 returnerr({errMsg})..' You are invited to add it [['..db..'|here]].'
 end
 else
 localerrMsg='Reference for RFC'..rfc..' is not defined yet.'
 returnerr({errMsg})..' You are invited to add it [[Template:Ref RFC/db|here]].'
 end
 else
 localerrMsg='Parameter error in {{[[Template:Sum RFC|Sum RFC]]}}: "'..args[1]..'" is not a number.'
 returnerr({message=errMsg,style='font-size:inherit',tag='span'})
 end
 else
 localerrMsg='Parameter error in {{[[Template:Sum RFC|Sum RFC]]}}: Missing [[RFC (identifier)|RFC]].'
 returnerr({message=errMsg,style='font-size:inherit',tag='span'})
 end
 end
 functionp.sum(frame)
 returnp._sum(getArgs(frame),frame)
 end

 returnp

AltStyle によって変換されたページ (->オリジナル) /