Jump to content
Wikipedia The Free Encyclopedia

Module:Portal-inline

From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing.
Page template-protected This module is currently protected from editing.
See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected.
Warning This Lua module is used on approximately 249,000 pages .
To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them.
This module depends on the following other modules:

This module implements Template:Portal-inline. This module accepts one unnamed parameter which is the portal to link to and several named parameters:

  • size— optional; Specify |size=small to show a 23x20 image or |size=tiny for a ×ばつ15 image instead of the usual size.
  • text— optional; Specify |text=(name) for a different associated name to appear.
  • short— optional; Specify |short=anything to remove portal from the output.
  • redlinks— optional; Specify |redlinks=yes to show the portal if it is redlinked.
  • nowrap— optional; Specify |nowrap=yes to prevent the entire output from wrapping.
The above documentation is transcluded from Module:Portal-inline/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.

 -- determine whether we're being called from a sandbox
 localisSandbox=mw.getCurrentFrame():getTitle():find('sandbox',1,true)
 localsandbox=isSandboxand'/sandbox'or''

 localgetArgs=require('Module:Arguments').getArgs
 localyesno=require('Module:Yesno')
 localportalModule=require('Module:Portal'..sandbox)
 localgetImageName=portalModule._image
 localcheckPortals=portalModule._checkPortals
 localprocessPortalArgs=portalModule._processPortalArgs

 localp={}

 -- Function to format error message and tracking category
 -- Arguments:
 -- errMsg: string, or nil/false if no error
 -- trackingCat: string for tracking category (or empty string)
 localfunctionformatError(errMsg,trackingCat)
 localresult=trackingCator''
 iferrMsgthen
 localerrTag=mw.html.create('span')
 errTag:addClass("error")
 errTag:css("font-size",'100%')
 errTag:wikitext("Error: "..errMsg)
 result=tostring(errTag)..result
 end
 returnresult
 end

 localfunctionimage(portal,args)
 localsize=args.size=="small"and"21x19px"or
 args.size=="tiny"and"17x15px"or
 "32x28px"
 returnstring.format('[[File:%s|%s]]',getImageName(portal,true),size)
 end

 localfunctionlink(portal,args)
 localdisplayName=""
 ifnot(args.text==""orargs.text==nil)then
 displayName=args.text
 elseifargs.shortthen
 displayName=portal
 else
 displayName=portal.." portal"
 end
 returnstring.format('[[Portal:%s|%s]]',portal,displayName)
 end

 functionp._main(portals,args)

 -- Normalize all arguments
 ifargs.redlinks=='include'thenargs.redlinks=trueend
 forkey,defaultinpairs({tracking=true,redlinks=false,short=false})do
 ifargs[key]==nilthenargs[key]=defaultend
 args[key]=yesno(args[key],default)
 end

 localtrackingCat=''
 localerrMsg=nil

 -- Check for existing categories, drop if not. 
 -- Possible generate tracking category & error message if needed
 args.minPortals=args.minPortalsor1
 args.maxPortals=args.maxPortalsor1
 portals,trackingCat,errMsg=checkPortals(portals,args)
 -- use more specific tracking cat for inline portal
 trackingCat=mw.ustring.gsub(trackingCat,"Portal templates","Portal-inline template")
 -- either too many/few portals, or no portals left after filtering, then return
 iferrMsgor#portals==0then
 returnformatError(errMsg,trackingCat)
 end
 fstring='<span class="nowrap">%s </span>%s%s'
 ifyesno(args.nowrapor'')then
 fstring='<span class="nowrap">%s %s%s</span>'
 end
 returnmw.ustring.format(fstring,image(portals[1],args),link(portals[1],args),(trackingCator''))
 end

 functionp.main(frame)
 localorigArgs=getArgs(frame)
 localportals,args=processPortalArgs(origArgs)
 returnp._main(portals,args)
 end

 returnp

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