This Lua module is used in system messages, and onapproximately 5,230,000 pages, or roughly 8% of all pages. Changes to it can cause immediate changes to the Wikipedia user interface. To avoid major disruption and server load, any changes should be tested in the module's/sandbox or/testcases subpages, or in your ownmodule sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on thetalk page before implementing them.
Thismodule is rated asready 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 onhelp pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed throughsandbox testing rather than repeated trial-and-error editing.
This module is used within infoboxes to process the image parameters and tidy up the formatting of the result.
Parameters
Parameter
Description
image
Required. The main parameter that should be passed over which contains the image info.
size
Size to display image, in pixels. Use is discouraged perWP:THUMBSIZE; see|upright= below instead.
maxsize
Maximum size to display image. Note: If no size or sizedefault params specified then image will be shown at maxsize.
sizedefault
The size to use for the image if no size param is specified. Defaults toframeless.
alt
Alt text for the image.
title
Title text for image (mouseover text).
border
If yes, then a border is added.
page
The page number to be displayed when using a multi-page image.
upright
If upright=yes, adds "upright" which displays image at 75% of default image size (which is 250px if not changed atSpecial:Preferences). If a value, adds "upright=value" to image, where values less than 1 scale the image down (0.9 = 90%) and values greater than 1 scale the image up (1.15 = 115%).
When "size" is not defined, "sizedefault" is used, even if larger than "maxsize" (in actual use "px" is required after the number; omitted here to show it is not added by the module):
When "size" and "sizedefault" are not defined, "maxsize" is used (in actual use "px" is required after the number; omitted here to show it is not added by the module):
When "size", "sizedefault", and "maxsize" are not defined, "frameless" is added, which displays the image at the default thumbnail size (250px, but logged in users can change this atSpecial:Preferences) and is required if using "upright" to scale the default size:
Use of "upright" without a number value, which displays the image at approximately 75% of the user's default size (multiplied by 0.75 then rounded to nearest 10):
{{#invoke:InfoboxImage|InfoboxImage|image=Abbey Rd Studios.jpg|sizedefault=250px|alt=The front stairs and door of Abbey Road Studios}}
{{#invoke:InfoboxImage|InfoboxImage|image=Abbey Rd Studios.jpg|sizedefault=250|alt=The front stairs and door of Abbey Road Studios}}
{{#invoke:InfoboxImage|InfoboxImage|image=Abbey Rd Studios.jpg|sizedefault=250px|alt=The front stairs and door of Abbey Road Studios|title=Exterior, front view of Abbey Road studios}}
{{#invoke:InfoboxImage|InfoboxImage|image=Abbey Rd Studios.jpg|alt=The front stairs and door of Abbey Road Studios}}
{{#invoke:InfoboxImage|InfoboxImage|image=Abbey Rd Studios.jpg|size=100px|alt=The front stairs and door of Abbey Road Studios}}
{{#invoke:InfoboxImage|InfoboxImage|image=Bandera de Bilbao.svg|size=100|border=yes}}
-- Inputs:-- image - Can either be a bare filename (with or without the File:/Image: prefix) or a fully formatted image link-- page - page to display for multipage images (DjVu)-- size - size to display the image-- maxsize - maximum size for image-- sizedefault - default size to display the image if size param is blank-- alt - alt text for image-- title - title text for image-- border - set to yes if border-- center - set to yes, if the image has to be centered-- upright - upright image param-- suppressplaceholder - if yes then checks to see if image is a placeholder and suppresses it-- link - page to visit when clicking on image-- class - HTML classes to add to the image-- Outputs:-- Formatted image.-- More details available at the "Module:InfoboxImage/doc" pagelocali={}-- List of placeholder images and tracking categories stored in [[Module:InfoboxImage/data]]-- Other constants:-- the system-wide default thumbnail size (in px)localdefaultThumbnailSize=250-- If page is not a user page, return tracking category. Else return empty.localfunctiontrackingCat(cat)localns=mw.title.getCurrentTitle().nsText:lower()localcategories=mw.loadData('Module:InfoboxImage/data').categoriesreturn(ns~='user'andns~='user talk'andcategories[cat])or""end-- Determine whether image is a placeholderfunctioni.IsPlaceholder(image)-- change underscores to spacesimage=mw.ustring.gsub(image,"_"," ");assert(image~=nil,'mw.ustring.gsub(image, "_", " ") must not return nil')-- if image starts with [[ then remove that and anything after |ifmw.ustring.sub(image,1,2)=="[["thenimage=mw.ustring.sub(image,3);image=mw.ustring.gsub(image,"([^|]*)|.*","%1");assert(image~=nil,'mw.ustring.gsub(image, "([^|]*)|.*", "%1") must not return nil')end-- Trim spacesimage=mw.ustring.gsub(image,'^[ ]*(.-)[ ]*$','%1');assert(image~=nil,"mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1') must not return nil")-- remove prefix if existslocalallNames=mw.site.namespaces[6].aliasesallNames[#allNames+1]=mw.site.namespaces[6].nameallNames[#allNames+1]=mw.site.namespaces[6].canonicalNamefori,nameinipairs(allNames)doifmw.ustring.lower(mw.ustring.sub(image,1,mw.ustring.len(name)+1))==mw.ustring.lower(name..":")thenimage=mw.ustring.sub(image,mw.ustring.len(name)+2);breakendend-- Trim spacesimage=mw.ustring.gsub(image,'^[ ]*(.-)[ ]*$','%1');-- capitalise first letterimage=mw.ustring.upper(mw.ustring.sub(image,1,1))..mw.ustring.sub(image,2);localplaceholder_image=mw.loadData('Module:InfoboxImage/data').placeholder_imagereturnplaceholder_image[image]endlocalfunctionisempty(x)return(notx)orx==""end-- Main entry pointfunctioni.InfoboxImage(frame)localimage=frame.args["image"];ifisempty(image)thenreturn"";endifimage==" "thenreturnimage;endifframe.args["suppressplaceholder"]~="no"thenifi.IsPlaceholder(image)==truethenreturn"";endendifstring.find(image,"^%[*https?:")then-- Error category.returntrackingCat("url_image_links")endifmw.ustring.sub(image,1,2)=="[["then-- search for thumbnail images and add to tracking cat if foundlocalcat="";ifmw.title.getCurrentTitle().namespace==0and(mw.ustring.find(image,"|%s*thumb%s*[|%]]")ormw.ustring.find(image,"|%s*thumbnail%s*[|%]]"))thencat=trackingCat("thumbnail_images")endreturnimage..cat;elseifmw.ustring.sub(image,1,2)=="{{"andmw.ustring.sub(image,1,3)~="{{{"thenreturnimage;elseifmw.ustring.sub(image,1,1)=="<"thenreturnimage;elseifmw.ustring.sub(image,1,8)==mw.ustring.char(127).."'\"`UNIQ"then-- Found strip marker at begining, so pass don't process at allreturnimage;elselocalresult="";localpage=frame.args["page"];localupright=frame.args["upright"]or""localsize=frame.args["size"];localmaxsize=frame.args["maxsize"];localsizedefault=frame.args["sizedefault"];localalt=frame.args["alt"];locallink=frame.args["link"];localtitle=frame.args["title"];localborder=frame.args["border"];localthumbtime=frame.args["thumbtime"]or"";localcenter=frame.args["center"];localclass=frame.args["class"];-- remove prefix if existslocalallNames=mw.site.namespaces[6].aliasesallNames[#allNames+1]=mw.site.namespaces[6].nameallNames[#allNames+1]=mw.site.namespaces[6].canonicalNamefori,nameinipairs(allNames)doifmw.ustring.lower(mw.ustring.sub(image,1,mw.ustring.len(name)+1))==mw.ustring.lower(name..":")thenimage=mw.ustring.sub(image,mw.ustring.len(name)+2);breakendendifnotisempty(maxsize)then-- if no sizedefault nor upright, then set to maxsizeifisempty(sizedefault)andisempty(upright)thensizedefault=maxsizeend-- check to see if size bigger than maxsizelocalmaxsizenumber=tonumber(mw.ustring.match(maxsize,"%d*"))or0;ifnotisempty(size)thenlocalsizenumber=tonumber(mw.ustring.match(size,"%d*"))or0;ifsizenumber>maxsizenumberandmaxsizenumber>0thensize=maxsize;endend-- check to see if upright bigger than maxsize (at default preferred size)ifnotisempty(upright)thenlocaluprightnumber=tonumber(upright)or(upright=="yes"and0.75)or0ifuprightnumber*defaultThumbnailSize>maxsizenumberandmaxsizenumber>0thenupright=tostring(maxsizenumber/defaultThumbnailSize)endendend-- add px to size if just a numberif(tonumber(size)or0)>0thensize=size.."px";end-- add px to sizedefault if just a numberif(tonumber(sizedefault)or0)>0thensizedefault=sizedefault.."px";endresult="[[File:"..image;ifnotisempty(page)thenresult=result.."|page="..page;endifnotisempty(size)thenresult=result.."|"..size;elseifnotisempty(sizedefault)andisempty(upright)thenresult=result.."|"..sizedefault;elseresult=result.."|frameless";endifcenter=="yes"thenresult=result.."|center"endifnotisempty(alt)thenresult=result.."|alt="..alt;endifnotisempty(link)thenresult=result.."|link="..link;endifborder=="yes"thenresult=result.."|border";endifupright=="yes"thenresult=result.."|upright";elseifupright~=""thenresult=result.."|upright="..upright;endifthumbtime~=""thenresult=result.."|thumbtime="..thumbtime;endifnotisempty(class)thenresult=result.."|class="..class;end-- if alt value is a keyword then do not use as a descriptionifalt=="thumbnail"oralt=="thumb"oralt=="frameless"oralt=="left"oralt=="center"oralt=="right"oralt=="upright"oralt=="border"ormw.ustring.match(altor"",'^[0-9]*px$',1)~=nilthenalt=nil;endifnotisempty(title)then-- does title param contain any templatestyles? If yes then set to blank.ifmw.ustring.match(frame:preprocess(title),'UNIQ%-%-templatestyles',1)~=nilthentitle=nil;endendifnotisempty(title)thenresult=result.."|"..title;endresult=result.."]]";returnresult;endendreturni;