Modul:RawImage
Aspect
Implementează {{imagine brută}}.
--[=[
rawimage
Implements [[Template:Raw image]]
Usage:
'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.
]=]
require('strict')
local p = {}
local getArgs = require('Modul:Arguments').getArgs
local function error_message(message)
return require('Modul:Error').error({message = table.concat({'Eroare în [[Modul:RawImage]]:', message}, ' ') .. ' Invocă cu {{imagine brută|' .. mw.title.getCurrentTitle().text .. '}}'})
end
local function _rawimage(args)
local pagename = args[1] or args.pagename
-- Bail out if no page was specified
if not pagename then
return error_message()
end
-- Check if a (valid) specific page has been given.
local page = mw.title.new(pagename, 'Pagină')
if not page then
return error_message('Numele specificat al paginii „' .. pagename .. '” este nevalid.')
end
local cats = {}
-- Add link if an IA identifier was provided
local iacat
local iatxt = ''
if args.ia then
iacat = '[[Categorie:' .. 'Imagini brute cu legături la Internet Archive' .. ']]'
iatxt = 'Digitizarea originală a acestei lucrări este disponibilă la ' .. '[' .. 'https://archive.org/details/' .. args.ia .. ' Internet Archive]'
local iazip = args.iazip or args.ia
local iaziplink = 'https://archive.org/download/' .. args.ia .. '/' .. iazip .. '_jp2.zip/'
iatxt = iatxt .. '([' .. iaziplink .. ' toate fișierele]).'
if args.iaimg then
local iaimglink = iaziplink .. iazip .. '_jp2%2F' .. args.iaimg
iatxt = iatxt .. ' O [' .. iaimglink .. ' scanare de înaltă rezoluție a acestei pagini] este disponibilă.'
iacat = '[[Categorie:' .. 'Imagini brute cu legături la pagini de la Internet Archive' .. ']]'
end
else
iacat = '[[Categorie:' .. 'Imagini brute fără legături la Internet Archive' .. ']]'
end
table.insert(cats, iacat)
-- Set the category to be used in output depending on namespace
if mw.title.getCurrentTitle():inNamespace('Pagină') then
table.insert(cats, '[[Categorie:' .. 'Pagini cu imagini brute' .. ']]')
else
table.insert(cats, '[[Categorie:' .. 'Texte cu imagini brute' .. ']]')
end
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', 'Fișier')
-- Set defaults for the output
local image = '[[Fișier:' .. pagebase .. '|page=' .. pagenum .. '|frameless|center|360px]]'
local text = '(Încărcați o imagine pentru a înlocui această imagine implicită.)'
-- Check if the hi-res version exists and use that if available
if hiRes.fileExists then
image = '[[Fișier:' .. hiRes.text .. '|frameless|center|360px]]'
text = '([[:Fișier:' .. hiRes.text .. '|Improve this image]])'
end
if iatxt ~= '' then
text = iatxt
end
-- Format the output
local frame = mw.getCurrentFrame()
local outtxt = frame:expandTemplate {
title = 'Casetă centrată',
args = {image .. frame:expandTemplate {
title = 'Dreapta',
args = {frame:expandTemplate {
title = 'X-mai mic bloc',
args = {text}
}}
}}
} .. table.concat(cats)
return outtxt
else
-- Not a subpage, so this page corresponds to a single-page image
return '[[Fișier:' .. page.text .. '|frameless|center|360px]]' .. table.concat(cats)
end
end
function p.rawimage(frame)
-- Template frame will never contain args, so skip it for performance
local args = getArgs(frame, {
wrappers = 'Format:imagine brută'
})
return _rawimage(args)
end
return p