Jump to content

Module:InfoboxImage

Permanently protected module
From Wikipedia, the free encyclopedia

-- 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={};localplaceholder_image={"Blue - Replace this image female.svg","Blue - Replace this image male.svg","Flag of None (square).svg","Flag of None.svg","Flag of.svg","Green - Replace this image female.svg","Green - Replace this image male.svg","Image is needed female.svg","Image is needed male.svg","Location map of None.svg","Male no free image yet.png","Missing flag.png","No flag.svg","No free portrait.svg","No portrait (female).svg","No portrait (male).svg","Red - Replace this image female.svg","Red - Replace this image male.svg","Replace this image female.svg","Replace this image male (blue).svg","Replace this image male.svg","Silver - Replace this image female.svg","Silver - Replace this image male.svg","Replace this image.svg","Cricket no pic.png","CarersLogo.gif","Diagram Needed.svg","Example.jpg","Image placeholder.png","No male portrait.svg","Nocover-upload.png","NoDVDcover copy.png","Noribbon.svg","No portrait-BFD-test.svg","Placeholder barnstar ribbon.png","Project Trains no image.png","Image-request.png","Sin bandera.svg","Sin escudo.svg","Replace this image - temple.png","Replace this image butterfly.png","Replace this image.svg","Replace this image1.svg","Resolution angle.png","Image-No portrait-text-BFD-test.svg","Insert image here.svg","No image available.png","NO IMAGE YET square.png","NO IMAGE YET.png","No Photo Available.svg","No Screenshot.svg","No-image-available.jpg","Null.png","PictureNeeded.gif","Place holder.jpg","Unbenannt.JPG","UploadACopyrightFreeImage.svg","UploadAnImage.gif","UploadAnImage.svg","UploadAnImageShort.svg","CarersLogo.gif","Diagram Needed.svg","No male portrait.svg","NoDVDcover copy.png","Placeholder barnstar ribbon.png","Project Trains no image.png","Image-request.png","Noimage.gif",}localcategories={url_image_links="[[Category:Pages using infoboxes with URL in image parameter]]",thumbnail_images="[[Category:Pages using infoboxes with thumbnail images]]",}localfunctiontrackable()localns=mw.title.getCurrentTitle().nsText:lower()returnnot(ns=='user'orns=='user talk')endfunctioni.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);fori,jinpairs(placeholder_image)doifimage==jthenreturntrueendendreturnfalseendfunctioni.InfoboxImage(frame)localimage=frame.args["image"];ifimage==""orimage==nilthenreturn"";endifimage=="&nbsp;"thenreturnimage;endifframe.args["suppressplaceholder"]~="no"thenifi.IsPlaceholder(image)==truethenreturn"";endendifstring.find(image,"^%[*https?:")then-- Error category.returntrackable()andcategories.url_image_linksor""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=trackable()andcategories.thumbnail_imagesor""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"];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"];localupright=frame.args["upright"]or"";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);breakendendifmaxsize~=""andmaxsize~=nilthen-- if no sizedefault then set to maxsizeifsizedefault==""orsizedefault==nilthensizedefault=maxsizeend-- check to see if size bigger than maxsizeifsize~=""andsize~=nilthenlocalsizenumber=tonumber(mw.ustring.match(size,"%d*"))or0;localmaxsizenumber=tonumber(mw.ustring.match(maxsize,"%d*"))or0;ifsizenumber>maxsizenumberandmaxsizenumber>0thensize=maxsize;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;ifpage~=""andpage~=nilthenresult=result.."|page="..page;endifsize~=""andsize~=nilthenresult=result.."|"..size;elseifsizedefault~=""andsizedefault~=nilthenresult=result.."|"..sizedefault;elseresult=result.."|frameless";endifcenter=="yes"thenresult=result.."|center"endifalt~=""andalt~=nilthenresult=result.."|alt="..alt;endiflink~=""andlink~=nilthenresult=result.."|link="..link;endifborder=="yes"thenresult=result.."|border";endifupright=="yes"thenresult=result.."|upright";elseifupright~=""thenresult=result.."|upright="..upright;endifthumbtime~=""thenresult=result.."|thumbtime="..thumbtime;endifclass~=nilandclass~=""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;endiftitle~=""andtitle~=nilthen-- does title param contain any templatestyles? If yes then set to blank.ifmw.ustring.match(frame:preprocess(title),'UNIQ%-%-templatestyles',1)~=nilthentitle=nil;endendiftitle~=""andtitle~=nilthenresult=result.."|"..title;endresult=result.."]]";returnresult;endendreturni;
close