Для документации этого модуля может быть создана страница Модуль:Cite web/doc
-- <nowiki>
--
-- Этот модуль принадлежит [[Вукипедия:Шаблоны|шаблону]] [[Шаблон:Cite web|Cite web]].
local p = {}
-- Lazily load a mw.language object.
local lang
local function makeCategoryLink(cat)
return string.format('[[Категория:%s]]', cat)
end
local function makeWikitextError(msg)
local ret = ''
ret = ret .. string.format(
'<strong class="error">[[Шаблон:Cite web]] ошибка: %s.</strong>',
msg
)
if mw.title.getCurrentTitle().namespace == 0 then
ret = ret .. makeCategoryLink('Страницы с ошибками параметров шаблона')
end
return ret
end
local function makeDateLink(date, year)
lang = lang or mw.language.getContentLanguage()
local success, dateLink = pcall(
lang.formatDate, lang,
'j xg, Y',
date
)
if success and dateLink then
if year then
dateLink = dateLink .. string.format(', %s', year)
end
return dateLink
end
end
local function makeDate(date, year, month)
local ret
if date then
ret = date
elseif year then
if month then
ret = month .. ' ' .. year
else
ret = year
end
end
if ret then
return string.format(' (%s)', ret)
end
end
local function makeAccessdateBlurb(monthDay, year, yearArgName)
year = year or yearArgName
return string.format(' Проверено %s %s.', monthDay, year)
end
function p._main(args)
-- Подтверждение ввода
if not args.url or not args.title then
return makeWikitextError("параметры '''url''' и '''title''' должны быть указаны")
end
if args.archiveurl and not args.archivedate or args.archivedate and not args.archiveurl then
return makeWikitextError(
"параметры '''archiveurl''' и '''archivedate''' должны быть вместе указаны или вместе пропущены"
)
end
local ret = {}
-- Авторы
if args.author or args.last then
local display
if args.last then
display = args.last
if args.first then
display = display .. ', ' .. args.first
end
else
display = args.author
end
if args.authorlink then
ret[#ret + 1] = string.format('[[%s|%s]]', args.authorlink, display)
else
ret[#ret + 1] = display
end
if args.coauthors then
ret[#ret + 1] = '; ' .. args.coauthors
end
ret[#ret + 1] = makeDate(args.date, args.year, args.month)
ret[#ret + 1] = '. '
end
-- Редактор
if args.editor then
ret[#ret + 1] = ' ' .. args.editor .. ':'
end
-- URL
if args.title then
if args.archiveurl then
ret[#ret + 1] = string.format('[%s %s]', args.archiveurl, args.title)
elseif args.url then
ret[#ret + 1] = string.format('[%s %s]', args.url, args.title)
end
end
-- Язык
if args.language then
ret[#ret + 1] = string.format(
' <span style="font-size: 0.95em; font-weight: bold; color:#555; position: relative;">(%s)</span>',
args.language
)
end
-- Формат
if args.format then
ret[#ret + 1] = string.format(' (%s)', args.format)
end
-- Работа
if args.work then
ret[#ret + 1] = string.format(". ''%s''", args.work)
end
-- Страницы
if args.pages then
ret[#ret + 1] = ' ' .. args.pages
end
-- Издатель
if args.publisher then
ret[#ret + 1] = '. ' .. args.publisher
end
-- Добавьте дату, если не указан автор.
if not args.author and not args.last then
ret[#ret + 1] = makeDate(args.date, args.year, args.month)
end
ret[#ret + 1] = '.'
-- Дата архивирования.
if args.archivedate then
local url = args.url or '{{{url}}}'
local dateLink = makeDateLink(args.archivedate, args.archiveyear)
if dateLink then
ret[#ret + 1] = string.format(
' Архивировано из [%s первоисточника] %s.',
url, dateLink
)
end
end
-- Дата доступа
if args.accessdate then
local dateLink = makeDateLink(args.accessdate, args.accessyear)
if dateLink then
ret[#ret + 1] = string.format(' Проверено %s.', dateLink)
end
elseif args.accessmonthday then
ret[#ret + 1] = makeAccessdateBlurb(
args.accessmonthday,
args.accessyear,
'{{{accessyear}}}'
)
elseif args.accessdaymonth then
ret[#ret + 1] = makeAccessdateBlurb(
args.accessdaymonth,
args.accessyear,
'{{{accessyear}}}'
)
end
-- Цитата
if args.quote then
ret[#ret + 1] = string.format(' "%s"', args.quote)
end
return table.concat(ret)
end
function p.main(frame)
local args = {}
for k, v in pairs(frame:getParent().args) do
v = v:match('^%s*(.-)%s*$') -- trim whitespace
if v ~= '' then
args[k] = v
end
end
return p._main(args)
end
return p
-- </nowiki>
Материалы сообщества доступны в соответствии с условиями лицензии CC-BY-SA, если не указано иное.