Jump to content

Editing Module:InfoboxImage

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 12: Line 12:
--    suppressplaceholder - if yes then checks to see if image is a placeholder and suppresses it
--    suppressplaceholder - if yes then checks to see if image is a placeholder and suppresses it
--    link - page to visit when clicking on image
--    link - page to visit when clicking on image
--    class - HTML classes to add to the image
-- Outputs:
-- Outputs:
--    Formatted image.
--    Formatted image.
Line 22: Line 21:
     "Blue - Replace this image female.svg",
     "Blue - Replace this image female.svg",
     "Blue - Replace this image male.svg",
     "Blue - Replace this image male.svg",
    "Female no free image yet.png",
     "Flag of None (square).svg",
     "Flag of None (square).svg",
     "Flag of None.svg",
     "Flag of None.svg",
Line 38: Line 38:
     "Red - Replace this image female.svg",
     "Red - Replace this image female.svg",
     "Red - Replace this image male.svg",
     "Red - Replace this image male.svg",
    "Replace this image female (blue).svg",
     "Replace this image female.svg",
     "Replace this image female.svg",
     "Replace this image male (blue).svg",
     "Replace this image male (blue).svg",
Line 87: Line 88:
"Project Trains no image.png",
"Project Trains no image.png",
"Image-request.png",
"Image-request.png",
"Noimage.gif",
}
}
local categories = {
url_image_links = "[[Category:Pages using infoboxes with URL in image parameter]]",
thumbnail_images = "[[Category:Pages using infoboxes with thumbnail images]]",
}
local function trackable()
local ns = mw.title.getCurrentTitle().nsText:lower()
return not (ns == 'user' or ns == 'user talk')
end


function i.IsPlaceholder(image)
function i.IsPlaceholder(image)
Line 134: Line 124:
     end
     end
     return false
     return false
end
local function isempty(x)
    return (not x) or x == ""
end
end


Line 143: Line 129:
     local image = frame.args["image"];
     local image = frame.args["image"];
      
      
     if isempty(image) then
     if image == "" or image == nil then
         return "";
         return "";
     end
     end
Line 154: Line 140:
         end
         end
     end
     end
      
 
     if string.find(image, "^%[*https?:") then
     if mw.ustring.lower(mw.ustring.sub(image,1,5)) == "http:" then
-- Error category.
        return "";
return trackable() and categories.url_image_links or ""
    end
end
     if mw.ustring.lower(mw.ustring.sub(image,1,6)) == "[http:" then
        return "";
    end
    if mw.ustring.lower(mw.ustring.sub(image,1,7)) == "[[http:" then
        return "";
    end
    if mw.ustring.lower(mw.ustring.sub(image,1,6)) == "https:" then
        return "";
    end
    if mw.ustring.lower(mw.ustring.sub(image,1,7)) == "[https:" then
        return "";
    end
    if mw.ustring.lower(mw.ustring.sub(image,1,8)) == "[[https:" then
        return "";
    end


     if mw.ustring.sub(image,1,2) == "[[" then
     if mw.ustring.sub(image,1,2) == "[[" then
         -- search for thumbnail images and add to tracking cat if found
         -- search for thumbnail images and add to tracking cat if found
        local cat = "";
         if mw.title.getCurrentTitle().namespace == 0 and (mw.ustring.find(image, "|%s*thumb%s*[|%]]") or mw.ustring.find(image, "|%s*thumbnail%s*[|%]]")) then
         if mw.title.getCurrentTitle().namespace == 0 and (mw.ustring.find(image, "|%s*thumb%s*[|%]]") or mw.ustring.find(image, "|%s*thumbnail%s*[|%]]")) then
             cat = trackable() and categories.thumbnail_images or ""
             return image .. "[[Category:Pages using infoboxes with thumbnail images]]";
        elseif mw.title.getCurrentTitle().namespace == 0 then
            return image .. "[[Category:Pages using deprecated image syntax]]";
        else
            return image;
         end
         end
        return image .. cat;
     elseif mw.ustring.sub(image,1,2) == "{{" and mw.ustring.sub(image,1,3) ~= "{{{" then
     elseif mw.ustring.sub(image,1,2) == "{{" and mw.ustring.sub(image,1,3) ~= "{{{" then
         return image;
         return image;
     elseif mw.ustring.sub(image,1,1) == "<" then
     elseif mw.ustring.sub(image,1,1) == "<" then
         return image;
         return image;
     elseif mw.ustring.sub(image,1,8) == mw.ustring.char(127).."'\"`UNIQ" then
     elseif mw.ustring.sub(image,1,5) == mw.ustring.char(127).."UNIQ" then
        -- Found strip marker at begining, so pass don't process at all
        return image;
    elseif mw.ustring.sub(image,4,9) == "`UNIQ-" then
         -- Found strip marker at begining, so pass don't process at all
         -- Found strip marker at begining, so pass don't process at all
         return image;
         return image;
Line 177: Line 182:
         local result = "";
         local result = "";
         local page = frame.args["page"];
         local page = frame.args["page"];
        local upright = frame.args["upright"] or ""
         local size = frame.args["size"];
         local size = frame.args["size"];
         local maxsize = frame.args["maxsize"];
         local maxsize = frame.args["maxsize"];
Line 185: Line 189:
         local title = frame.args["title"];
         local title = frame.args["title"];
         local border = frame.args["border"];
         local border = frame.args["border"];
        local upright = frame.args["upright"] or "";
         local thumbtime = frame.args["thumbtime"] or "";
         local thumbtime = frame.args["thumbtime"] or "";
         local center = frame.args["center"];
         local center= frame.args["center"];
        local class = frame.args["class"];
          
          
         -- remove prefix if exists
         -- remove prefix if exists
Line 200: Line 204:
         end
         end
          
          
         if not isempty(maxsize) then
         if maxsize ~= "" and maxsize ~= nil then
             -- if no sizedefault nor upright, then set to maxsize
             -- if no sizedefault then set to maxsize
             if isempty(sizedefault) and isempty(upright) then
             if sizedefault == "" or sizedefault == nil then
                 sizedefault = maxsize
                 sizedefault = maxsize
             end
             end
             -- check to see if size bigger than maxsize
             -- check to see if size bigger than maxsize
             local maxsizenumber = tonumber(mw.ustring.match(maxsize,"%d*")) or 0;
             if size ~= "" and size ~= nil then
            if not isempty(size) then
                 local sizenumber = tonumber(mw.ustring.match(size,"%d*")) or 0;
                 local sizenumber = tonumber(mw.ustring.match(size,"%d*")) or 0;
                 if sizenumber > maxsizenumber and maxsizenumber > 0 then
                local maxsizenumber = tonumber(mw.ustring.match(maxsize,"%d*")) or 0;
                 if sizenumber>maxsizenumber and maxsizenumber>0 then
                     size = maxsize;
                     size = maxsize;
                end
            end
            -- check to see if upright bigger than maxsize (at default preferred size)
            if not isempty(upright) then
                local uprightnumber = tonumber(upright) or (upright == "yes" and 0.75) or 0
                if uprightnumber*220 > maxsizenumber and maxsizenumber > 0 then
                    upright = tostring(maxsizenumber/220)
                 end
                 end
             end
             end
Line 231: Line 228:
          
          
         result = "[[File:" .. image;
         result = "[[File:" .. image;
         if not isempty(page) then
         if page ~= "" and page ~= nil then
             result = result .. "|page=" .. page;
             result = result .. "|page=" .. page;
         end
         end
         if not isempty(size) then
         if size ~= "" and size ~= nil then
             result = result .. "|" .. size;
             result = result .. "|" .. size;
         elseif not isempty(sizedefault) and isempty(upright) then
         elseif sizedefault ~= "" and sizedefault ~= nil then
             result = result .. "|" .. sizedefault;
             result = result .. "|" .. sizedefault;
         else
         else
Line 244: Line 241:
             result = result .. "|center"
             result = result .. "|center"
         end
         end
         if not isempty(alt) then
         if alt ~= "" and alt ~= nil then
             result = result .. "|alt=" .. alt;
             result = result .. "|alt=" .. alt;
         end
         end
         if not isempty(link) then
         if link ~= "" and link ~= nil then
             result = result .. "|link=" .. link;
             result = result .. "|link=" .. link;
         end
         end
Line 261: Line 258:
             result = result .. "|thumbtime=" .. thumbtime;
             result = result .. "|thumbtime=" .. thumbtime;
         end
         end
         if not isempty(class) then
         if title ~= "" and title ~= nil then
            result = result .. "|class=" .. class;
        end
        -- if alt value is a keyword then do not use as a description
        if alt == "thumbnail" or alt == "thumb" or alt == "frameless" or alt == "left" or alt == "center" or alt == "right" or alt == "upright" or alt == "border" or mw.ustring.match(alt or "", '^[0-9]*px$', 1) ~= nil then
            alt = nil;
        end
        if not isempty(title) then
            -- does title param contain any templatestyles? If yes then set to blank.
            if mw.ustring.match(frame:preprocess(title), 'UNIQ%-%-templatestyles', 1) ~= nil then
                title = nil;
            end
        end
        if not isempty(title) then
             result = result .. "|" .. title;
             result = result .. "|" .. title;
        elseif alt ~= "" and alt ~= nil then
            result = result .. "|" .. alt;
         end
         end
         result = result .. "]]";
         result = result .. "]]";
Please note that all contributions to American Election Wiki are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) (see American Election Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)

Templates used on this page:

Cookies help us deliver our services. By using our services, you agree to our use of cookies.