Module:RawImage

-- 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.

RawImage = {};

function RawImage.rawimage(frame) inpage = mw.title.getCurrentTitle:inNamespace("Page")

pagename = frame.args["pagename"] -- check if the pagename hasn't been passed if pagename == nil then return ' \'\'\'Error: invoke with \'\'\' ' end

if pagename == '' then return ' \'\'\'Error: invoke with \'\'\' ' end

-- check if the pagename has been given with "Page:" in front. If so, strip it   if pagename:sub(1,5) == 'Page:' then pagename = pagename:sub(6) end

-- find the last / in the pagename slash = string.reverse(pagename):find('/') if slash ~= nil then slash = #pagename - slash + 1 end if slash == nil then -- there is no slash, this page corresponds to a single-page image if inpage then category = 'Pages with raw images' else category = 'Texts with raw images' end return '' else -- this page title contains a slash, so compose the name of the hi-res file. pagebase = pagename:sub(0,slash-1) pagenum = pagename:sub(slash+1) hiRes = 'File:' .. pagebase .. '-' .. pagenum .. '.png' -- check if the hi-ref version exists if mw.title.new(hiRes).exists then -- hi-res version exists, let's link to it           if inpage then category = 'Pages with raw images (hi-res scan available)' else category = 'Texts with raw images' end return frame:expandTemplate{title='block center',args={'frameless|center|360px' .. frame:expandTemplate{title='right', args={frame:expandTemplate{title='x-smaller block', args={'(Improve this image)'}}}}}} .. ''       else -- hi-res version doesn't exists, let's link to source page if inpage then category = 'Pages with raw images' else category = 'Texts with raw images' end

return frame:expandTemplate{title='block center',args={'' .. frame:expandTemplate{title='right', args={frame:expandTemplate{title='x-smaller block', args={'(Upload an image to replace this placeholder.)'}}}}}} .. ''       end end end

return RawImage