Module:InfoboxImage

From YSTV History Wiki
Jump to navigation Jump to search

Overview

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.
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 to frameless.
alt Alt text for the image.
title Title text for image (mouseover text). If blank then alt text is used.
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 220px if not changed at Special: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%).
center If yes, then the image is centered.
thumbtime thumbtime param, used for video clips.
suppressplaceholder If no, then will not suppress certain placeholder images. See Template:Section link.
link Page to go to when clicking on the image.

Note: If you specify the maxsize or sizedefault params, then you should include the px after the number.

Template:Dated maintenance category

Parameters displayed in image syntax

All parameters:

{{#invoke:InfoboxImage | InfoboxImage | image={{{image}}} | size={{{size}}} | maxsize={{{maxsize}}} | sizedefault={{{sizedefault}}} | upright={{{upright}}} | alt={{{alt}}} | title={{{title}}} | thumbtime={{{thumbtime}}} | link={{{link}}} | border=yes | center=yes | page={{{page}}} }}
[[File:{{{image}}}|page={{{page}}}|{{{size}}}|center|alt={{{alt}}}|link={{{link}}}|border|upright={{{upright}}}|thumbtime={{{thumbtime}}}|{{{title}}}]]

When "size" and "maxsize" are defined, the smaller of the two is used (if "px" is omitted it will be added by the module):

{{#invoke:InfoboxImage | InfoboxImage | image={{{image}}} | size=300px | maxsize=250px }}
[[File:{{{image}}}|250px]]

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):

{{#invoke:InfoboxImage | InfoboxImage | image={{{image}}} | sizedefault=250px | maxsize=200px }}
[[File:{{{image}}}|250px]]

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):

{{#invoke:InfoboxImage | InfoboxImage | image={{{image}}} | maxsize=250px }}
[[File:{{{image}}}|250px]]

When "size", "sizedefault", and "maxsize" are not defined, "frameless" is added, which displays the image at the default thumbnail size (220px, but logged in users can change this at Special:Preferences) and is required if using "upright" to scale the default size:

{{#invoke:InfoboxImage | InfoboxImage | image={{{image}}} }}
[[File:{{{image}}}|frameless]]

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={{{image}}} | upright = yes }}
[[File:{{{image}}}|frameless|upright]]

When "alt" is used without "title", the alt text is also used as the title:

{{#invoke:InfoboxImage | InfoboxImage | image={{{image}}} | alt = Alt text }}
[[File:{{{image}}}|frameless|alt=Alt text|Alt text]]

For more information, see Wikipedia:Extended image syntax.

Sample usage

|image = {{#invoke:InfoboxImage|InfoboxImage|image={{{image|}}}|upright={{{image_upright|1}}}|alt={{{alt|}}}}}

Examples

{{#invoke:InfoboxImage|InfoboxImage}}
{{#invoke:InfoboxImage|InfoboxImage|image=}}

{{#invoke:InfoboxImage|InfoboxImage|image=Abbey Rd Studios.jpg}}
{{#invoke:InfoboxImage|InfoboxImage|image=File:Abbey Rd Studios.jpg}}
{{#invoke:InfoboxImage|InfoboxImage|image=Image:Abbey Rd Studios.jpg}}

File:Abbey Rd Studios.jpg

{{#invoke:InfoboxImage|InfoboxImage|image=Abbey Rd Studios.jpg|upright=yes}}

File:Abbey Rd Studios.jpg

{{#invoke:InfoboxImage|InfoboxImage|image=Abbey Rd Studios.jpg|upright=1.2}}

File:Abbey Rd Studios.jpg

{{#invoke:InfoboxImage|InfoboxImage|image=Abbey Rd Studios.jpg|size=100px}}
{{#invoke:InfoboxImage|InfoboxImage|image=Abbey Rd Studios.jpg|size=100}}

100px
{{#invoke:InfoboxImage|InfoboxImage|image=[[Image:Abbey Rd Studios.jpg|200px]]}} 200px
{{#invoke:InfoboxImage|InfoboxImage|image=[[Image:Abbey Rd Studios.jpg|200px]]|title=Abbey Road!}} 200px
{{#invoke:InfoboxImage|InfoboxImage|image=Abbey Rd Studios.jpg|sizedefault=250px|alt=The front stairs and door of Abbey Road Studios}} 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}} 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}} 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}} 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}} The front stairs and door of Abbey Road Studios
{{#invoke:InfoboxImage|InfoboxImage|image=Bilbao.svg|size=100|border=yes}} 200px
{{#invoke:InfoboxImage|InfoboxImage|image=Image is needed male.svg}}
{{#invoke:InfoboxImage|InfoboxImage|image=Image is needed male.svg|suppressplaceholder=no}} File:Image is needed male.svg
{{#invoke:InfoboxImage|InfoboxImage|image=[[File:Image is needed male.svg|200px]]}}
{{#invoke:InfoboxImage|InfoboxImage|image=[[File:Image is needed male.svg|200px]]|suppressplaceholder=no}} 200px
{{#invoke:InfoboxImage|InfoboxImage|image=Abbey Rd Studios.jpg|size=50px|maxsize=100px}} 50px
{{#invoke:InfoboxImage|InfoboxImage|image=Abbey Rd Studios.jpg|size=200px|maxsize=100px}} 100px
{{#invoke:InfoboxImage|InfoboxImage|image=[[File:Abbey Rd Studios.jpg|200px]]|maxsize=100px}} 200px
{{#invoke:InfoboxImage|InfoboxImage|image=Abbey Rd Studios.jpg|maxsize=100px|center=yes}}
{{#invoke:InfoboxImage|InfoboxImage|image=no such image|maxsize=100px|center=yes}}

Placeholder images which can be suppressed

{| | style="vertical-align:top;" | * [[:File:Blue - replace this image female.svg]] * [[:File:Blue - replace this image male.svg]] * [[:File:Female no free image yet.png]] * [[:File:Male no free image yet.png]] * [[:File:Flag of None (square).svg]] * [[:File:Flag of None.svg]] * [[:File:Flag of.svg]] * [[:File:Green - replace this image female.svg]] * [[:File:Green - replace this image male.svg]] * [[:File:Image is needed female.svg]] * [[:File:Image is needed male.svg]] * [[:File:Location map of None.svg]] * [[:File:Male no free image yet.png]] * [[:File:Missing flag.png]] * [[:File:No flag.svg]] * [[:File:No free portrait.svg]] * [[:File:No portrait (female).svg]] * [[:File:No portrait (male).svg]] * [[:File:Red - replace this image female.svg]] * [[:File:Red - replace this image male.svg]] * [[:File:Replace this image female (blue).svg]] * [[:File:Replace this image female.svg]] * [[:File:Replace this image male (blue).svg]] * [[:File:Replace this image male.svg]] * [[:File:Silver - replace this image female.svg]] * [[:File:Silver - replace this image male.svg]] * [[:File:Replace this image.svg]] * [[:File:Cricket no pic.png]] * [[:File:CarersLogo.gif]] * [[:File:Diagram Needed.svg]] * [[:File:Example.jpg]] * [[:File:Image placeholder.png]] * [[:File:No male portrait.svg]] * [[:File:Nocover-upload.png]] * [[:File:NoDVDcover copy.png]] * [[:File:Noribbon.svg]] | style="vertical-align:top;" | * [[:File:No portrait-BFD-test.svg]] * [[:File:Placeholder barnstar ribbon.png]] * [[:File:Project Trains no image.png]] * [[:File:Image-request.png]] * [[:File:Sin bandera.svg]] * [[:File:Sin escudo.svg]] * [[:File:Replace this image - temple.png]] * [[:File:Replace this image butterfly.png]] * [[:File:Replace this image.svg]] * [[:File:Replace this image1.svg]] * [[:File:Resolution angle.png]] * [[:File:Image-No portrait-text-BFD-test.svg]] * [[:File:Insert image here.svg]] * [[:File:No image available.png]] * [[:File:NO IMAGE YET square.png]] * [[:File:NO IMAGE YET.png]] * [[:File:No Photo Available.svg]] * [[:File:No Screenshot.svg]] * [[:File:No-image-available.jpg]] * [[:File:Null.png]] * [[:File:PictureNeeded.gif]] * [[:File:Place holder.jpg]] * [[:File:Unbenannt.JPG]] * [[:File:UploadACopyrightFreeImage.svg]] * [[:File:UploadAnImage.gif]] * [[:File:UploadAnImage.svg]] * [[:File:UploadAnImageShort.svg]] * [[:File:CarersLogo.gif]] * [[:File:Diagram Needed.svg]] * [[:File:No male portrait.svg]] * [[:File:NoDVDcover copy.png]] * [[:File:Placeholder barnstar ribbon.png]] * [[:File:Project Trains no image.png]] * [[:File:Image-request.png]] |}

Tracking categories


  1 -- Inputs:
  2 --    image - Can either be a bare filename (with or without the File:/Image: prefix) or a fully formatted image link
  3 --    page - page to display for multipage images (DjVu)
  4 --    size - size to display the image
  5 --    maxsize - maximum size for image
  6 --    sizedefault - default size to display the image if size param is blank
  7 --    alt - alt text for image
  8 --    title - title text for image
  9 --    border - set to yes if border
 10 --    center - set to yes, if the image has to be centered
 11 --    upright - upright image param
 12 --    suppressplaceholder - if yes then checks to see if image is a placeholder and suppresses it
 13 --    link - page to visit when clicking on image
 14 -- Outputs:
 15 --    Formatted image.
 16 -- More details available at the "Module:InfoboxImage/doc" page
 17 
 18 local i = {};
 19 
 20 local placeholder_image = {
 21     "Blue - Replace this image female.svg",
 22     "Blue - Replace this image male.svg",
 23     "Female no free image yet.png",
 24     "Flag of None (square).svg",
 25     "Flag of None.svg",
 26     "Flag of.svg",
 27     "Green - Replace this image female.svg",
 28     "Green - Replace this image male.svg",
 29     "Image is needed female.svg",
 30     "Image is needed male.svg",
 31     "Location map of None.svg",
 32     "Male no free image yet.png",
 33     "Missing flag.png",
 34     "No flag.svg",
 35     "No free portrait.svg",
 36     "No portrait (female).svg",
 37     "No portrait (male).svg",
 38     "Red - Replace this image female.svg",
 39     "Red - Replace this image male.svg",
 40     "Replace this image female (blue).svg",
 41     "Replace this image female.svg",
 42     "Replace this image male (blue).svg",
 43     "Replace this image male.svg",
 44     "Silver - Replace this image female.svg",
 45     "Silver - Replace this image male.svg",
 46     "Replace this image.svg",
 47 	"Cricket no pic.png",
 48 	"CarersLogo.gif",
 49 	"Diagram Needed.svg",
 50 	"Example.jpg",
 51 	"Image placeholder.png",
 52 	"No male portrait.svg",
 53 	"Nocover-upload.png",
 54 	"NoDVDcover copy.png",
 55 	"Noribbon.svg",
 56 	"No portrait-BFD-test.svg",
 57 	"Placeholder barnstar ribbon.png",
 58 	"Project Trains no image.png",
 59 	"Image-request.png",
 60 	"Sin bandera.svg",
 61 	"Sin escudo.svg",
 62 	"Replace this image - temple.png",
 63 	"Replace this image butterfly.png",
 64 	"Replace this image.svg",
 65 	"Replace this image1.svg",
 66 	"Resolution angle.png",
 67 	"Image-No portrait-text-BFD-test.svg",
 68 	"Insert image here.svg",
 69 	"No image available.png",
 70 	"NO IMAGE YET square.png",
 71 	"NO IMAGE YET.png",
 72 	"No Photo Available.svg",
 73 	"No Screenshot.svg",
 74 	"No-image-available.jpg",
 75 	"Null.png",
 76 	"PictureNeeded.gif",
 77 	"Place holder.jpg",
 78 	"Unbenannt.JPG",
 79 	"UploadACopyrightFreeImage.svg",
 80 	"UploadAnImage.gif",
 81 	"UploadAnImage.svg",
 82 	"UploadAnImageShort.svg",
 83 	"CarersLogo.gif",
 84 	"Diagram Needed.svg",
 85 	"No male portrait.svg",
 86 	"NoDVDcover copy.png",
 87 	"Placeholder barnstar ribbon.png",
 88 	"Project Trains no image.png",
 89 	"Image-request.png",
 90 	"Noimage.gif",
 91 }
 92 
 93 function i.IsPlaceholder(image)
 94     -- change underscores to spaces
 95     image = mw.ustring.gsub(image, "_", " ");
 96     assert(image ~= nil, 'mw.ustring.gsub(image, "_", " ") must not return nil')
 97     -- if image starts with [[ then remove that and anything after |
 98     if mw.ustring.sub(image,1,2) == "[[" then
 99         image = mw.ustring.sub(image,3);
100         image = mw.ustring.gsub(image, "([^|]*)|.*", "%1");
101         assert(image ~= nil, 'mw.ustring.gsub(image, "([^|]*)|.*", "%1") must not return nil')
102     end
103     -- Trim spaces
104     image = mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1');
105     assert(image ~= nil, "mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1') must not return nil")
106     -- remove prefix if exists
107     local allNames = mw.site.namespaces[6].aliases
108     allNames[#allNames + 1] = mw.site.namespaces[6].name
109     allNames[#allNames + 1] = mw.site.namespaces[6].canonicalName
110     for i, name in ipairs(allNames) do
111         if mw.ustring.lower(mw.ustring.sub(image, 1, mw.ustring.len(name) + 1)) == mw.ustring.lower(name .. ":") then
112             image = mw.ustring.sub(image, mw.ustring.len(name) + 2);
113             break
114         end
115     end
116     -- Trim spaces
117     image = mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1');
118     -- capitalise first letter
119     image = mw.ustring.upper(mw.ustring.sub(image,1,1)) .. mw.ustring.sub(image,2);
120 
121     for i,j in pairs(placeholder_image) do
122         if image == j then
123             return true
124         end
125     end
126     return false
127 end
128 
129 function i.InfoboxImage(frame)
130     local image = frame.args["image"];
131     
132     if image == "" or image == nil then
133         return "";
134     end
135     if image == " " then
136         return image;
137     end
138     if frame.args["suppressplaceholder"] ~= "no" then
139         if i.IsPlaceholder(image) == true then
140             return "";
141         end
142     end
143 
144     if mw.ustring.lower(mw.ustring.sub(image,1,5)) == "http:" then
145         return "";
146     end
147     if mw.ustring.lower(mw.ustring.sub(image,1,6)) == "[http:" then
148         return "";
149     end
150     if mw.ustring.lower(mw.ustring.sub(image,1,7)) == "[[http:" then
151         return "";
152     end
153     if mw.ustring.lower(mw.ustring.sub(image,1,6)) == "https:" then
154         return "";
155     end
156     if mw.ustring.lower(mw.ustring.sub(image,1,7)) == "[https:" then
157         return "";
158     end
159     if mw.ustring.lower(mw.ustring.sub(image,1,8)) == "[[https:" then
160         return "";
161     end
162 
163     if mw.ustring.sub(image,1,2) == "[[" then
164         -- search for thumbnail images and add to tracking cat if found
165         if mw.title.getCurrentTitle().namespace == 0 and (mw.ustring.find(image, "|%s*thumb%s*[|%]]") or mw.ustring.find(image, "|%s*thumbnail%s*[|%]]")) then
166             return image .. "[[Category:Pages using infoboxes with thumbnail images]]";
167         elseif mw.title.getCurrentTitle().namespace == 0 then
168             return image .. "[[Category:Pages using deprecated image syntax]]";
169         else
170             return image;
171         end
172     elseif mw.ustring.sub(image,1,2) == "{{" and mw.ustring.sub(image,1,3) ~= "{{{" then
173         return image;
174     elseif mw.ustring.sub(image,1,1) == "<" then
175         return image;
176     elseif mw.ustring.sub(image,1,5) == mw.ustring.char(127).."UNIQ" then
177         -- Found strip marker at begining, so pass don't process at all
178         return image;
179     elseif mw.ustring.sub(image,4,9) == "`UNIQ-" then
180         -- Found strip marker at begining, so pass don't process at all
181         return image;
182     else
183         local result = "";
184         local page = frame.args["page"];
185         local size = frame.args["size"];
186         local maxsize = frame.args["maxsize"];
187         local sizedefault = frame.args["sizedefault"];
188         local alt = frame.args["alt"];
189         local link = frame.args["link"];
190         local title = frame.args["title"];
191         local border = frame.args["border"];
192         local upright = frame.args["upright"] or "";
193         local thumbtime = frame.args["thumbtime"] or "";
194         local center= frame.args["center"];
195         
196         -- remove prefix if exists
197         local allNames = mw.site.namespaces[6].aliases
198         allNames[#allNames + 1] = mw.site.namespaces[6].name
199         allNames[#allNames + 1] = mw.site.namespaces[6].canonicalName
200         for i, name in ipairs(allNames) do
201             if mw.ustring.lower(mw.ustring.sub(image, 1, mw.ustring.len(name) + 1)) == mw.ustring.lower(name .. ":") then
202                 image = mw.ustring.sub(image, mw.ustring.len(name) + 2);
203                 break
204             end
205         end
206         
207         if maxsize ~= "" and maxsize ~= nil then
208             -- if no sizedefault then set to maxsize
209             if sizedefault == "" or sizedefault == nil then
210                 sizedefault = maxsize
211             end
212             -- check to see if size bigger than maxsize
213             if size ~= "" and size ~= nil then
214                 local sizenumber = tonumber(mw.ustring.match(size,"%d*")) or 0;
215                 local maxsizenumber = tonumber(mw.ustring.match(maxsize,"%d*")) or 0;
216                 if sizenumber>maxsizenumber and maxsizenumber>0 then
217                     size = maxsize;
218                 end
219             end
220         end
221         -- add px to size if just a number
222         if (tonumber(size) or 0) > 0 then
223             size = size .. "px";
224         end
225         -- add px to sizedefault if just a number
226         if (tonumber(sizedefault) or 0) > 0 then
227             sizedefault = sizedefault .. "px";
228         end
229         
230         result = "[[File:" .. image;
231         if page ~= "" and page ~= nil then
232             result = result .. "|page=" .. page;
233         end
234         if size ~= "" and size ~= nil then
235             result = result .. "|" .. size;
236         elseif sizedefault ~= "" and sizedefault ~= nil then
237             result = result .. "|" .. sizedefault;
238         else
239             result = result .. "|frameless";
240         end
241         if center == "yes" then
242             result = result .. "|center"
243         end
244         if alt ~= "" and alt ~= nil then
245             result = result .. "|alt=" .. alt;
246         end
247         if link ~= "" and link ~= nil then
248             result = result .. "|link=" .. link;
249         end
250         if border == "yes" then
251             result = result .. "|border";
252         end
253         if upright == "yes" then
254             result = result .. "|upright";
255         elseif upright ~= "" then
256             result = result .. "|upright=" .. upright;
257         end
258         if thumbtime ~= "" then
259             result = result .. "|thumbtime=" .. thumbtime;
260         end
261         if title ~= "" and title ~= nil then
262             result = result .. "|" .. title;
263         elseif alt ~= "" and alt ~= nil then
264             result = result .. "|" .. alt;
265         end
266         result = result .. "]]";
267         
268         return result;
269     end
270 end
271 
272 return i;