Module:InfoboxImage: Difference between revisions
old>WOSlinker No edit summary |
old>WOSlinker No edit summary |
||
Line 4: | Line 4: | ||
-- sizedefault - default size to display the image if size param is blank | -- sizedefault - default size to display the image if size param is blank | ||
-- alt - alt text for image | -- alt - alt text for image | ||
-- suppressplaceholder - if yes then checks to see if image is a placeholder and suppresses it | |||
-- Outputs: | -- Outputs: | ||
-- Formatted image. | -- Formatted image. | ||
Line 39: | Line 40: | ||
function i.IsPlaceholder(image) | function i.IsPlaceholder(image) | ||
-- change underscores to spaces | -- change underscores to spaces | ||
image2 = mw.ustring.gsub(image, "_", " ") | image2 = mw.ustring.gsub(image, "_", " "); | ||
-- if image starts with [[ then remove that and anything after | | -- if image starts with [[ then remove that and anything after | | ||
if mw.ustring.sub(image2,1,2) == "[[" then | if mw.ustring.sub(image2,1,2) == "[[" then | ||
image2 = mw.ustring.sub(image2,3) | image2 = mw.ustring.sub(image2,3); | ||
image2 = mw.ustring.gsub(image2, "([^|]*)|.*", "%1") | image2 = mw.ustring.gsub(image2, "([^|]*)|.*", "%1"); | ||
end | end | ||
-- remove file: or image: prefix if exists | -- remove file: or image: prefix if exists | ||
Line 53: | Line 54: | ||
end | end | ||
-- capitalise first letter | -- capitalise first letter | ||
image2 = mw.ustring.upper(mw.ustring.sub(image2,1,1)) .. mw.ustring.sub(image2,2) | image2 = mw.ustring.upper(mw.ustring.sub(image2,1,1)) .. mw.ustring.sub(image2,2); | ||
for i,j in pairs(placeholder_image) do | for i,j in pairs(placeholder_image) do | ||
Line 67: | Line 68: | ||
if image == "" or image == nil then | if image == "" or image == nil then | ||
return "" | return ""; | ||
end | end | ||
if i.IsPlaceholder(image) == true then | if frame.args["suppressplaceholder"] == "yes" then | ||
if i.IsPlaceholder(image) == true then | |||
return ""; | |||
end | |||
end | end | ||
Revision as of 21:24, 15 March 2013
This module is used in system messages. Changes to it can cause immediate changes to the Wikipedia user interface. To avoid large-scale disruption, any changes should first be tested in this module's /sandbox or /testcases subpage, or in your own user space. The tested changes can then be added in one single edit to this module. Please discuss any changes on the talk page before implementing them. |
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
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, in pixels. Use is discouraged per WP:THUMBSIZE; see |upright= below instead.
|
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). |
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. |
class | HTML classes to add to 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}}} | maxsize={{{maxsize}}} | sizedefault={{{sizedefault}}} | upright={{{upright}}} | alt={{{alt}}} | title={{{title}}} | thumbtime={{{thumbtime}}} | link={{{link}}} | border=yes | center=yes | page={{{page}}} | class={{{class}}} }}
[[File:{{{image}}}|{{{size}}}|alt={{{alt}}}]]
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}}}|300px]]
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}}}|frameless]]
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]]
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]]
For more information, see Wikipedia: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 categories
-- Inputs:
-- image - Can either be a bare filename or a fully formatted image link
-- size - size to display the image
-- sizedefault - default size to display the image if size param is blank
-- alt - alt text for image
-- suppressplaceholder - if yes then checks to see if image is a placeholder and suppresses it
-- Outputs:
-- Formatted image.
local i = {};
local placeholder_image = {
"Blue - Replace this image female.svg",
"Blue - Replace this image male.svg",
"Female no free image yet.png",
"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 (blue).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",
}
function i.IsPlaceholder(image)
-- change underscores to spaces
image2 = mw.ustring.gsub(image, "_", " ");
-- if image starts with [[ then remove that and anything after |
if mw.ustring.sub(image2,1,2) == "[[" then
image2 = mw.ustring.sub(image2,3);
image2 = mw.ustring.gsub(image2, "([^|]*)|.*", "%1");
end
-- remove file: or image: prefix if exists
if mw.ustring.lower(mw.ustring.sub(image2,1,5)) == "file:" then
image2 = mw.ustring.sub(image2,6,mw.ustring.len(image2));
end
if mw.ustring.lower(mw.ustring.sub(image2,1,6)) == "image:" then
image2 = mw.ustring.sub(image2,7,mw.ustring.len(image2));
end
-- capitalise first letter
image2 = mw.ustring.upper(mw.ustring.sub(image2,1,1)) .. mw.ustring.sub(image2,2);
for i,j in pairs(placeholder_image) do
if image2 == j then
return true
end
end
return false
end
function i.InfoboxImage(frame)
local image = frame.args["image"];
if image == "" or image == nil then
return "";
end
if frame.args["suppressplaceholder"] == "yes" then
if i.IsPlaceholder(image) == true then
return "";
end
end
if mw.ustring.sub(image,1,2) == "[[" then
return image;
else
local result = "";
local size = frame.args["size"];
local sizedefault = frame.args["sizedefault"];
local alt = frame.args["alt"];
-- remove file: or image: prefix if exists
if mw.ustring.lower(mw.ustring.sub(image,1,5)) == "file:" then
image = mw.ustring.sub(image,6,mw.ustring.len(image));
end
if mw.ustring.lower(mw.ustring.sub(image,1,6)) == "image:" then
image = mw.ustring.sub(image,7,mw.ustring.len(image));
end
-- add px to size if just a number
if (tonumber(size) or 0) > 0 then
size = size .. "px";
end
result = "[[File:" .. image;
if size ~= "" and size ~= nil then
result = result .. "|" .. size;
elseif sizedefault ~= "" and sizedefault ~= nil then
result = result .. "|" .. sizedefault;
else
result = result .. "|frameless";
end
if alt ~= "" and alt ~= nil then
result = result .. "|alt=" .. alt;
end
result = result .. "]]";
return result;
end
end
return i;