Module:RawImage/sandbox

-- rawimage Main entry point for Lua function to replace Usage:   To invoke the module directly, use    But generally it is preferable to go through the template:    'pagename' should be the name of a page in Page: namespace, with or without the "Page:" in front. NOTE FOR EDITORS: rawimage displays images centred in the user's standard thumb size. It is not recommended to offer further display options, as this would disincentivise the replacement of raw images.

local getArgs = require('Module:Arguments').getArgs local error = require('Module:Error').error local p = {}

function p.rawimage(frame) -- Template frame will never contain args, so skip it for performance local args = getArgs(frame, {		wrappers = 'Template:raw image'	})

-- Bail out if no page was specified if args[1] == nil then return error({message = 'Invoke with '}) end

-- Check if a (valid) specific page has been given. local page = mw.title.new(args[1], 'Page') if page == nil then return error({message = 'Invalid page name ' .. args[1] .. 'specified. Invoke with '}) end

-- Add link if an IA identifier was provided local iacat = '' local iaworklink = '' local iaziplink = '' local iatxt = '' if args.ia ~= nil then iacat = '' iaworklink = 'https://archive.org/details/' .. args.ia		iatxt = 'The original scan of this work is available at the ' .. '[' .. iaworklink .. ' Internet Archive]'

if args.iazip ~= nil then iaziplink = 'https://archive.org/download/' .. args.ia .. '/' .. args.iazip .. '_jp2.zip/' else iaziplink = 'https://archive.org/download/' .. args.ia .. '/' .. args.ia .. '_jp2.zip/' end

iatxt = iatxt .. '([' .. iaziplink .. ' all files]).'

if args.iaimg ~= nil then local iaimglink = iaziplink .. args.iazip .. '_jp2%2F' .. args.iaimg iatxt = iatxt .. ' A [' .. iaimglink .. ' high-resolution scan of this page] is available.' iacat = '' end else iacat = '' end

-- Set the category to be used in output depending on namespace local category = '' if mw.title.getCurrentTitle:inNamespace('Page') then category = 'Pages with raw images' else category = 'Texts with raw images' end category = '' category = category .. iacat

if page.isSubpage then -- this page is a subpage, so compose the name of the hi-res file. local pagebase = page.baseText local pagenum = page.subpageText local hiRes = mw.title.new(pagebase .. '-' .. pagenum .. '.png', 'File')

-- Set defaults for the output local image = '' local text = '(Upload an image to replace this placeholder.)'

-- Check if the hi-res version exists and use that if available if hiRes.fileExists then image = '' text = '(Improve this image)' end

if iatxt ~= '' then text = iatxt end

-- Format the output local righttxt = frame:expandTemplate{title='right', args={frame:expandTemplate{title='x-smaller block', args={text}}}} local outtxt = frame:expandTemplate{title='block center', args={image .. righttxt}} return outtxt .. category else -- Not a subpage, so this page corresponds to a single-page image return '' .. category end end

return p