Database changes have finished applying - please report any issues you're (still) seeing to support@shoutwiki.com.
Module:InfoboxImage
From Eureka Wiki
Jump to navigation
Jump to search
Documentation for this module may be created at Module:InfoboxImage/doc
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;