-17 Removals
+78 Additions

Created by:srdjanm

1-- Inputs:1-- Inputs:
2-- image - Can either be a bare filename (with or without the File:/Image: prefix) or a fully formatted image link2-- 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)
3-- size - size to display the image4-- size - size to display the image
4-- maxsize - maximum size for image5-- maxsize - maximum size for image
5-- sizedefault - default size to display the image if size param is blank6-- sizedefault - default size to display the image if size param is blank
6-- alt - alt text for image7-- alt - alt text for image
7-- title - title text for image8-- title - title text for image
8-- border - set to yes if border9-- border - set to yes if border
9-- center - set to yes, if the image has to be centered10-- center - set to yes, if the image has to be centered
10-- upright - upright image param11-- upright - upright image param
11-- suppressplaceholder - if yes then checks to see if image is a placeholder and suppresses it12-- suppressplaceholder - if yes then checks to see if image is a placeholder and suppresses it
12-- link - page to visit when clicking on image13-- link - page to visit when clicking on image
13-- Outputs:14-- Outputs:
14-- Formatted image.15-- Formatted image.
15-- More details available at the "Module:InfoboxImage/doc" page16-- More details available at the "Module:InfoboxImage/doc" page
1617
17local i = {};18local i = {};
1819
19local placeholder_image = {20local placeholder_image = {
20 "Blue - Replace this image female.svg",21 "Blue - Replace this image female.svg",
21 "Blue - Replace this image male.svg",22 "Blue - Replace this image male.svg",
22 "Female no free image yet.png",23 "Female no free image yet.png",
23 "Flag of None (square).svg",24 "Flag of None (square).svg",
24 "Flag of None.svg",25 "Flag of None.svg",
25 "Flag of.svg",26 "Flag of.svg",
26 "Green - Replace this image female.svg",27 "Green - Replace this image female.svg",
27 "Green - Replace this image male.svg",28 "Green - Replace this image male.svg",
28 "Image is needed female.svg",29 "Image is needed female.svg",
29 "Image is needed male.svg",30 "Image is needed male.svg",
30 "Location map of None.svg",31 "Location map of None.svg",
31 "Male no free image yet.png",32 "Male no free image yet.png",
32 "Missing flag.png",33 "Missing flag.png",
33 "No flag.svg",34 "No flag.svg",
34 "No free portrait.svg",35 "No free portrait.svg",
35 "No portrait (female).svg",36 "No portrait (female).svg",
36 "No portrait (male).svg",37 "No portrait (male).svg",
37 "Red - Replace this image female.svg",38 "Red - Replace this image female.svg",
38 "Red - Replace this image male.svg",39 "Red - Replace this image male.svg",
39 "Replace this image female (blue).svg",40 "Replace this image female (blue).svg",
40 "Replace this image female.svg",41 "Replace this image female.svg",
41 "Replace this image male (blue).svg",42 "Replace this image male (blue).svg",
42 "Replace this image male.svg",43 "Replace this image male.svg",
43 "Silver - Replace this image female.svg",44 "Silver - Replace this image female.svg",
44 "Silver - Replace this image male.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",
45}90}
4691
47function i.IsPlaceholder(image)92function i.IsPlaceholder(image)
48 -- change underscores to spaces93 -- change underscores to spaces
49 image = mw.ustring.gsub(image, "_", " ");94 image = mw.ustring.gsub(image, "_", " ");
95 assert(image ~= nil, 'mw.ustring.gsub(image, "_", " ") must not return nil')
50 -- if image starts with [[ then remove that and anything after |96 -- if image starts with [[ then remove that and anything after |
51 if mw.ustring.sub(image,1,2) == "[[" then97 if mw.ustring.sub(image,1,2) == "[[" then
52 image = mw.ustring.sub(image,3);98 image = mw.ustring.sub(image,3);
53 image = mw.ustring.gsub(image, "([^|]*)|.*", "%1");99 image = mw.ustring.gsub(image, "([^|]*)|.*", "%1");
100 assert(image ~= nil, 'mw.ustring.gsub(image, "([^|]*)|.*", "%1") must not return nil')
54 end101 end
55 -- Trim spaces102 -- Trim spaces
56 image = mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1');103 image = mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1');
57 -- remove file: or image: prefix if exists104 assert(image ~= nil, "mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1') must not return nil")
58 if mw.ustring.lower(mw.ustring.sub(image,1,5)) == "file:" then105 -- remove prefix if exists
59 image = mw.ustring.sub(image,6);106 local allNames = mw.site.namespaces[6].aliases
60 end107 allNames[#allNames + 1] = mw.site.namespaces[6].name
61 if mw.ustring.lower(mw.ustring.sub(image,1,6)) == "image:" then108 allNames[#allNames + 1] = mw.site.namespaces[6].canonicalName
62 image = mw.ustring.sub(image,7);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
63 end114 end
64 -- Trim spaces115 -- Trim spaces
65 image = mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1');116 image = mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1');
66 -- capitalise first letter117 -- capitalise first letter
67 image = mw.ustring.upper(mw.ustring.sub(image,1,1)) .. mw.ustring.sub(image,2);118 image = mw.ustring.upper(mw.ustring.sub(image,1,1)) .. mw.ustring.sub(image,2);
68119
69 for i,j in pairs(placeholder_image) do120 for i,j in pairs(placeholder_image) do
70 if image == j then121 if image == j then
71 return true122 return true
72 end123 end
73 end124 end
74 return false125 return false
75end126end
76127
77function i.InfoboxImage(frame)128function i.InfoboxImage(frame)
78 local image = frame.args["image"];129 local image = frame.args["image"];
79 130
80 if image == "" or image == nil then131 if image == "" or image == nil then
81 return "";132 return "";
82 end133 end
83 if image == " " then134 if image == " " then
84 return image;135 return image;
85 end136 end
86 if frame.args["suppressplaceholder"] == "yes" then137 if frame.args["suppressplaceholder"] ~= "no" then
87 if i.IsPlaceholder(image) == true then138 if i.IsPlaceholder(image) == true then
88 return "";139 return "";
89 end140 end
90 end141 end
91142
92 if mw.ustring.lower(mw.ustring.sub(image,1,5)) == "http:" then143 if mw.ustring.lower(mw.ustring.sub(image,1,5)) == "http:" then
93 return "";144 return "";
94 end145 end
95 if mw.ustring.lower(mw.ustring.sub(image,1,6)) == "[http:" then146 if mw.ustring.lower(mw.ustring.sub(image,1,6)) == "[http:" then
96 return "";147 return "";
97 end148 end
98 if mw.ustring.lower(mw.ustring.sub(image,1,7)) == "[[http:" then149 if mw.ustring.lower(mw.ustring.sub(image,1,7)) == "[[http:" then
99 return "";150 return "";
100 end151 end
101 if mw.ustring.lower(mw.ustring.sub(image,1,6)) == "https:" then152 if mw.ustring.lower(mw.ustring.sub(image,1,6)) == "https:" then
102 return "";153 return "";
103 end154 end
104 if mw.ustring.lower(mw.ustring.sub(image,1,7)) == "[https:" then155 if mw.ustring.lower(mw.ustring.sub(image,1,7)) == "[https:" then
105 return "";156 return "";
106 end157 end
107 if mw.ustring.lower(mw.ustring.sub(image,1,8)) == "[[https:" then158 if mw.ustring.lower(mw.ustring.sub(image,1,8)) == "[[https:" then
108 return "";159 return "";
109 end160 end
110161
111 if mw.ustring.sub(image,1,2) == "[[" then162 if mw.ustring.sub(image,1,2) == "[[" then
112 -- search for thumbnail images and add to tracking cat if found163 -- search for thumbnail images and add to tracking cat if found
113 if mw.title.getCurrentTitle().namespace == 0 and (mw.ustring.find(image, "|%s*thumb%s*[|%]]") or mw.ustring.find(image, "|%s*thumbnail%s*[|%]]")) then164 if mw.title.getCurrentTitle().namespace == 0 and (mw.ustring.find(image, "|%s*thumb%s*[|%]]") or mw.ustring.find(image, "|%s*thumbnail%s*[|%]]")) then
114 return image .. "[[Category:Pages using infoboxes with thumbnail images]]";165 return image .. "[[Category:Pages using infoboxes with thumbnail images]]";
115 else166 else
116 return image;167 return image;
117 end168 end
118 elseif mw.ustring.sub(image,1,2) == "{{" and mw.ustring.sub(image,1,3) ~= "{{{" then169 elseif mw.ustring.sub(image,1,2) == "{{" and mw.ustring.sub(image,1,3) ~= "{{{" then
119 return image;170 return image;
120 elseif mw.ustring.sub(image,1,1) == "<" then171 elseif mw.ustring.sub(image,1,1) == "<" then
121 return image;172 return image;
122 elseif mw.ustring.sub(image,1,5) == mw.ustring.char(127).."UNIQ" then173 elseif mw.ustring.sub(image,1,5) == mw.ustring.char(127).."UNIQ" then
123 -- Found strip marker at begining, so pass don't process at all174 -- Found strip marker at begining, so pass don't process at all
124 return image;175 return image;
125 else176 else
126 local result = "";177 local result = "";
178 local page = frame.args["page"];
127 local size = frame.args["size"];179 local size = frame.args["size"];
128 local maxsize = frame.args["maxsize"];180 local maxsize = frame.args["maxsize"];
129 local sizedefault = frame.args["sizedefault"];181 local sizedefault = frame.args["sizedefault"];
130 local alt = frame.args["alt"];182 local alt = frame.args["alt"];
131 local link = frame.args["link"];183 local link = frame.args["link"];
132 local title = frame.args["title"];184 local title = frame.args["title"];
133 local border = frame.args["border"];185 local border = frame.args["border"];
134 local upright = frame.args["upright"] or "";186 local upright = frame.args["upright"] or "";
135 local thumbtime = frame.args["thumbtime"] or "";187 local thumbtime = frame.args["thumbtime"] or "";
136 local center= frame.args["center"];188 local center= frame.args["center"];
137 189
138 -- remove file: or image: prefix if exists190 -- remove prefix if exists
139 if mw.ustring.lower(mw.ustring.sub(image,1,5)) == "file:" then191 local allNames = mw.site.namespaces[6].aliases
140 image = mw.ustring.sub(image,6);192 allNames[#allNames + 1] = mw.site.namespaces[6].name
141 end193 allNames[#allNames + 1] = mw.site.namespaces[6].canonicalName
142 if mw.ustring.lower(mw.ustring.sub(image,1,6)) == "image:" then194 for i, name in ipairs(allNames) do
143 image = mw.ustring.sub(image,7);195 if mw.ustring.lower(mw.ustring.sub(image, 1, mw.ustring.len(name) + 1)) == mw.ustring.lower(name .. ":") then
196 image = mw.ustring.sub(image, mw.ustring.len(name) + 2);
197 break
198 end
144 end199 end
145 200
146 if maxsize ~= "" and maxsize ~= nil then201 if maxsize ~= "" and maxsize ~= nil then
147 -- if no sizedefault then set to maxsize202 -- if no sizedefault then set to maxsize
148 if sizedefault == "" or sizedefault == nil then203 if sizedefault == "" or sizedefault == nil then
149 sizedefault = maxsize204 sizedefault = maxsize
150 end205 end
151 -- check to see if size bigger than maxsize206 -- check to see if size bigger than maxsize
152 if size ~= "" and size ~= nil then207 if size ~= "" and size ~= nil then
153 local sizenumber = tonumber(mw.ustring.match(size,"%d*")) or 0;208 local sizenumber = tonumber(mw.ustring.match(size,"%d*")) or 0;
154 local maxsizenumber = tonumber(mw.ustring.match(maxsize,"%d*"));209 local maxsizenumber = tonumber(mw.ustring.match(maxsize,"%d*")) or 0;
155 if sizenumber>maxsizenumber and maxsizenumber>0 then210 if sizenumber>maxsizenumber and maxsizenumber>0 then
156 size = maxsize;211 size = maxsize;
157 end212 end
158 end213 end
159 end214 end
160 -- add px to size if just a number215 -- add px to size if just a number
161 if (tonumber(size) or 0) > 0 then216 if (tonumber(size) or 0) > 0 then
162 size = size .. "px";217 size = size .. "px";
163 end218 end
164 219
165 result = "[[File:" .. image;220 result = "[[File:" .. image;
221 if page ~= "" and page ~= nil then
222 result = result .. "|page=" .. page;
223 end
166 if size ~= "" and size ~= nil then224 if size ~= "" and size ~= nil then
167 result = result .. "|" .. size;225 result = result .. "|" .. size;
168 elseif sizedefault ~= "" and sizedefault ~= nil then226 elseif sizedefault ~= "" and sizedefault ~= nil then
169 result = result .. "|" .. sizedefault;227 result = result .. "|" .. sizedefault;
170 else228 else
171 result = result .. "|frameless";229 result = result .. "|frameless";
172 end230 end
173 if center == "yes" then231 if center == "yes" then
174 result = result .. "|center"232 result = result .. "|center"
175 end233 end
176 if alt ~= "" and alt ~= nil then234 if alt ~= "" and alt ~= nil then
177 result = result .. "|alt=" .. alt;235 result = result .. "|alt=" .. alt;
178 end236 end
179 if link ~= "" and link ~= nil then237 if link ~= "" and link ~= nil then
180 result = result .. "|link=" .. link;238 result = result .. "|link=" .. link;
181 end239 end
182 if border == "yes" then240 if border == "yes" then
183 result = result .. "|border";241 result = result .. "|border";
184 end242 end
185 if upright ~= "" then243 if upright == "yes" then
244 result = result .. "|upright";
245 elseif upright ~= "" then
186 result = result .. "|upright=" .. upright;246 result = result .. "|upright=" .. upright;
187 end247 end
188 if thumbtime ~= "" then248 if thumbtime ~= "" then
189 result = result .. "|thumbtime=" .. thumbtime;249 result = result .. "|thumbtime=" .. thumbtime;
190 end250 end
191 if title ~= "" and title ~= nil then251 if title ~= "" and title ~= nil then
192 result = result .. "|" .. title;252 result = result .. "|" .. title;
193 elseif alt ~= "" and alt ~= nil then253 elseif alt ~= "" and alt ~= nil then
194 result = result .. "|" .. alt;254 result = result .. "|" .. alt;
195 end255 end
196 result = result .. "]]";256 result = result .. "]]";
197 257
198 return result;258 return result;
199 end259 end
200end260end
201261
202return i;262return i;
Editor
Original Text
Changed Text
Recommended videos