Database changes have finished applying - please report any issues you're (still) seeing to support@shoutwiki.com.
Module:InfoboxImage
![]() | This Lua module is used on a very large number of pages. To avoid large-scale disruption and unnecessary server load, any changes to this module should first be tested in its /sandbox or /testcases subpages. The tested changes can then be added to this page in one single edit. Please consider discussing any changes on the talk page before implementing them. |
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 (mousehover 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 § Placeholder images which can be suppressed. |
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.
Parameters displayed in image syntax
All parameters:
{{#invoke:InfoboxImage | InfoboxImage | image={{{image}}} | size={{{size}}} | 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=250 }}
[[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=250 | maxsize=200 }}
[[File:{{{image}}}|250]]
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=250 }}
[[File:{{{image}}}|250]]
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 TechInfoDepot:Extended image syntax.
Sample usage
|image = {{#invoke:InfoboxImage|InfoboxImage|image={{{image|}}}|upright={{{image_upright|1}}}|alt={{{alt|}}}}}
Examples
Placeholder images which can be suppressed
Tracking/maintenance category
The above documentation is transcluded from Module:InfoboxImage/doc. (edit | history) Editors can experiment in this module's sandbox (create | mirror) and testcases (create) pages. Subpages of this module. |
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 }
91
92 function i.IsPlaceholder(image)
93 -- change underscores to spaces
94 image = mw.ustring.gsub(image, "_", " ");
95 assert(image ~= nil, 'mw.ustring.gsub(image, "_", " ") must not return nil')
96 -- if image starts with [[ then remove that and anything after |
97 if mw.ustring.sub(image,1,2) == "[[" then
98 image = mw.ustring.sub(image,3);
99 image = mw.ustring.gsub(image, "([^|]*)|.*", "%1");
100 assert(image ~= nil, 'mw.ustring.gsub(image, "([^|]*)|.*", "%1") must not return nil')
101 end
102 -- Trim spaces
103 image = mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1');
104 assert(image ~= nil, "mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1') must not return nil")
105 -- remove prefix if exists
106 local allNames = mw.site.namespaces[6].aliases
107 allNames[#allNames + 1] = mw.site.namespaces[6].name
108 allNames[#allNames + 1] = mw.site.namespaces[6].canonicalName
109 for i, name in ipairs(allNames) do
110 if mw.ustring.lower(mw.ustring.sub(image, 1, mw.ustring.len(name) + 1)) == mw.ustring.lower(name .. ":") then
111 image = mw.ustring.sub(image, mw.ustring.len(name) + 2);
112 break
113 end
114 end
115 -- Trim spaces
116 image = mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1');
117 -- capitalise first letter
118 image = mw.ustring.upper(mw.ustring.sub(image,1,1)) .. mw.ustring.sub(image,2);
119
120 for i,j in pairs(placeholder_image) do
121 if image == j then
122 return true
123 end
124 end
125 return false
126 end
127
128 function i.InfoboxImage(frame)
129 local image = frame.args["image"];
130
131 if image == "" or image == nil then
132 return "";
133 end
134 if image == " " then
135 return image;
136 end
137 if frame.args["suppressplaceholder"] ~= "no" then
138 if i.IsPlaceholder(image) == true then
139 return "";
140 end
141 end
142
143 if mw.ustring.lower(mw.ustring.sub(image,1,5)) == "http:" then
144 return "";
145 end
146 if mw.ustring.lower(mw.ustring.sub(image,1,6)) == "[http:" then
147 return "";
148 end
149 if mw.ustring.lower(mw.ustring.sub(image,1,7)) == "[[http:" then
150 return "";
151 end
152 if mw.ustring.lower(mw.ustring.sub(image,1,6)) == "https:" then
153 return "";
154 end
155 if mw.ustring.lower(mw.ustring.sub(image,1,7)) == "[https:" then
156 return "";
157 end
158 if mw.ustring.lower(mw.ustring.sub(image,1,8)) == "[[https:" then
159 return "";
160 end
161
162 if mw.ustring.sub(image,1,2) == "[[" then
163 -- search for thumbnail images and add to tracking cat if found
164 if mw.title.getCurrentTitle().namespace == 0 and (mw.ustring.find(image, "|%s*thumb%s*[|%]]") or mw.ustring.find(image, "|%s*thumbnail%s*[|%]]")) then
165 return image .. "[[Category:Pages using infoboxes with thumbnail images]]";
166 else
167 return image;
168 end
169 elseif mw.ustring.sub(image,1,2) == "{{" and mw.ustring.sub(image,1,3) ~= "{{{" then
170 return image;
171 elseif mw.ustring.sub(image,1,1) == "<" then
172 return image;
173 elseif mw.ustring.sub(image,1,5) == mw.ustring.char(127).."UNIQ" then
174 -- Found strip marker at begining, so pass don't process at all
175 return image;
176 elseif mw.ustring.sub(image,4,9) == "`UNIQ-" then
177 -- Found strip marker at begining, so pass don't process at all
178 return image;
179 else
180 local result = "";
181 local page = frame.args["page"];
182 local size = frame.args["size"];
183 local maxsize = frame.args["maxsize"];
184 local sizedefault = frame.args["sizedefault"];
185 local alt = frame.args["alt"];
186 local link = frame.args["link"];
187 local title = frame.args["title"];
188 local border = frame.args["border"];
189 local upright = frame.args["upright"] or "";
190 local thumbtime = frame.args["thumbtime"] or "";
191 local center= frame.args["center"];
192
193 -- remove prefix if exists
194 local allNames = mw.site.namespaces[6].aliases
195 allNames[#allNames + 1] = mw.site.namespaces[6].name
196 allNames[#allNames + 1] = mw.site.namespaces[6].canonicalName
197 for i, name in ipairs(allNames) do
198 if mw.ustring.lower(mw.ustring.sub(image, 1, mw.ustring.len(name) + 1)) == mw.ustring.lower(name .. ":") then
199 image = mw.ustring.sub(image, mw.ustring.len(name) + 2);
200 break
201 end
202 end
203
204 if maxsize ~= "" and maxsize ~= nil then
205 -- if no sizedefault then set to maxsize
206 if sizedefault == "" or sizedefault == nil then
207 sizedefault = maxsize
208 end
209 -- check to see if size bigger than maxsize
210 if size ~= "" and size ~= nil then
211 local sizenumber = tonumber(mw.ustring.match(size,"%d*")) or 0;
212 local maxsizenumber = tonumber(mw.ustring.match(maxsize,"%d*")) or 0;
213 if sizenumber>maxsizenumber and maxsizenumber>0 then
214 size = maxsize;
215 end
216 end
217 end
218 -- add px to size if just a number
219 if (tonumber(size) or 0) > 0 then
220 size = size .. "px";
221 end
222
223 result = "[[File:" .. image;
224 if page ~= "" and page ~= nil then
225 result = result .. "|page=" .. page;
226 end
227 if size ~= "" and size ~= nil then
228 result = result .. "|" .. size;
229 elseif sizedefault ~= "" and sizedefault ~= nil then
230 result = result .. "|" .. sizedefault;
231 else
232 result = result .. "|frameless";
233 end
234 if center == "yes" then
235 result = result .. "|center"
236 end
237 if alt ~= "" and alt ~= nil then
238 result = result .. "|alt=" .. alt;
239 end
240 if link ~= "" and link ~= nil then
241 result = result .. "|link=" .. link;
242 end
243 if border == "yes" then
244 result = result .. "|border";
245 end
246 if upright == "yes" then
247 result = result .. "|upright";
248 elseif upright ~= "" then
249 result = result .. "|upright=" .. upright;
250 end
251 if thumbtime ~= "" then
252 result = result .. "|thumbtime=" .. thumbtime;
253 end
254 if title ~= "" and title ~= nil then
255 result = result .. "|" .. title;
256 elseif alt ~= "" and alt ~= nil then
257 result = result .. "|" .. alt;
258 end
259 result = result .. "]]";
260
261 return result;
262 end
263 end
264
265 return i;