Module:AeroWikiImageFinder
From Aeronautica Official Wiki
More actions
Documentation for this module may be created at Module:AeroWikiImageFinder/doc
-- Created by @Sqwishyish on discord
-- Contact me for any issues
local getArgs = require('Module:Arguments').getArgs
local p = {}
local function makeInvokeFunc(funcName)
return function (frame)
local args = getArgs(frame)
return p[funcName](args)
end
end
p.find_image = makeInvokeFunc('_find_image')
p._find_image = function (args)
-- Get arguments passed from function call
local page_name = args[1] -- Name of the page to find an image for
local placeholder = args[2] -- Image to return if one is not found
local file_extentions = {'png','jpg','jpeg','webp','svg','gif','ico'}
for _, extention in ipairs(file_extentions) do
file_name = page_name .. ' 0.' .. extention -- Combine name and extention
file_object = mw.title.makeTitle("File", file_name) -- Get file object
if file_object and file_object.exists then -- Check if file exists
return file_name -- Return file name
end
end
return placeholder -- Return placeholder name if since file is not found
end
return p