Модуль:Не переведено: различия между версиями
Перейти к навигации
Перейти к поиску
м (как сейчас в документации) |
|||
Строка 68: | Строка 68: | ||
if is_empty(args[1]) then | if is_empty(args[1]) then | ||
args[1] = args[4] | args[1] = args[4] | ||
+ | end | ||
+ | if allow_cat then | ||
+ | if yesno(args['o']) then | ||
+ | categories = categories .. '[[Категория:Страницы с полустарым синтаксисом в шаблоне «не переведено 2»]]' | ||
+ | else | ||
+ | categories = categories .. '[[Категория:Страницы с полустарым синтаксисом в шаблоне «не переведено»]]' | ||
+ | end | ||
end | end | ||
end | end |
Версия от 21:16, 17 октября 2020
Для документации этого модуля может быть создана страница Модуль:Не переведено/doc
local getArgs = require('Module:Arguments').getArgs
local p = {}
local function is_empty(param)
return param == nil or param == ''
end
local function wikilink(title, text, tooltip, lang)
if lang ~= nil and lang ~= 'ru' then
title = string.format(':%s:%s', lang, title)
end
if tooltip ~= nil then
if is_empty(text) then
text = title
end
text = tostring(
mw.html.create('span')
:attr('title', tooltip)
:wikitext(text)
)
end
if not is_empty(text) then
title = title .. '|' .. text
end
return string.format('[[%s]]', title)
end
local function italic(s)
return tostring(
mw.html.create('span')
:css('font-style', 'italic')
:wikitext(s)
)
end
function p.main(frame)
local yesno = require('Module:Yesno')
local args = getArgs(frame)
local languages = mw.loadData('Module:Languages/data')
local error = require('Module:Error').error
local prepositional = require('Module:Languages')._transform_lang
local leave_always = yesno(args['l'])
local leave_if_redirect = yesno(args['r'])
local categories = ''
local nocat = yesno(args['nocat'])
local allow_cat = mw.title.getCurrentTitle().namespace == 0 and not nocat
local orphan_categories = {
['error'] = '[[Категория:Википедия:Статьи с некорректно заполненным шаблоном Не переведено]]',
['outdated'] = '[[Категория:Википедия:Статьи с неактуальным шаблоном Не переведено]]',
['redirect'] = '[[Категория:Википедия:Запросы на замену перенаправлений переводами]]'
}
if is_empty(args[1]) then
if allow_cat then
categories = categories .. orphan_categories['error']
end
return error{'не указано название статьи'} .. categories
end
if args[1]:match('^:[a-z-]+:') then
local temp = args[1]
args[1] = args[2] or ''
args[2] = args[3]
args[3] = temp:gsub('^:([a-z-]+):(.+)$', '%1')
args[4] = temp:gsub('^:([a-z-]+):(.+)$', '%2')
if is_empty(args[1]) then
args[1] = args[4]
end
if allow_cat then
if yesno(args['o']) then
categories = categories .. '[[Категория:Страницы с полустарым синтаксисом в шаблоне «не переведено 2»]]'
else
categories = categories .. '[[Категория:Страницы с полустарым синтаксисом в шаблоне «не переведено»]]'
end
end
end
local ru_page = mw.title.new(args[1])
if ru_page == nil then
if allow_cat then
categories = categories .. orphan_categories['error']
end
return error{'некорректные символы в названии статьи'} .. categories
end
if leave_if_redirect and not ru_page.isRedirect then
leave_if_redirect = false
end
local exists = ru_page.exists and not ( leave_always or leave_if_redirect )
if leave_if_redirect and allow_cat then
categories = categories .. orphan_categories['redirect']
end
local title = args[1]
local text = args[2]
local ru_link = wikilink(title, text)
if exists and not mw.isSubsting() then
ru_link = tostring(
mw.html.create('span')
:css('background', '#ffff00')
:wikitext(ru_link)
)
end
local post_link = ''
local addition = args['a']
local show_originals = yesno(args['o']) or addition ~= nil
local wikidata_link = ''
local lang = args[3]
local iw_title = args[4]
local iw_text = args[5]
if is_empty(lang) then
lang = 'en'
end
if is_empty(iw_title) then
iw_title = title
end
if is_empty(iw_text) then
iw_text = iw_title
end
local iw_page = mw.title.new(iw_title)
if iw_page == nil then
if allow_cat then
categories = categories .. orphan_categories['error']
end
return error{'некорректные символы в названии статьи'} .. categories
end
local show_original = show_originals and lang ~= 'd'
local lang_text
local lang_title
local lang_link
if lang == 'd' then
lang_text = 'd'
elseif languages[lang] == nil then
if allow_cat then
categories = categories .. orphan_categories['error']
end
return error{'некорректный ISO-код «' .. lang .. '»'} .. categories
else
lang_text = languages[lang][1]
lang_title = languages[lang][2]
lang_link = wikilink(lang_title, lang_text)
end
local tooltip
local ucfirst_title = mw.getContentLanguage():ucfirst(title)
if lang == 'd' then
tooltip = string.format('Элемент статьи «%s» в Викиданных', ucfirst_title)
else
tooltip = string.format('Версия статьи «%s» на %s', ucfirst_title, prepositional(lang))
end
local iw_link
if show_original then
iw_link = wikilink(iw_title, iw_text, tooltip, lang)
else
iw_link = wikilink(iw_title, lang_text, tooltip, lang)
end
if show_original then
local lang_template = mw.title.new('Template:Lang-' .. lang)
if not lang_template.exists then
if allow_cat then
categories = categories .. '[[Категория:Википедия:Статьи с шаблоном Не переведено 2, использующие несуществующий шаблон lang-XX]]'
end
return error{'не найден шаблон ' .. frame:expandTemplate{ title = 'tl', args = { 'lang-' .. lang } } } .. categories
end
if mw.isSubsting() or exists then
post_link = frame:expandTemplate{ title = 'lang-' .. lang, args = { iw_text } }
else
post_link = frame:expandTemplate{ title = 'lang-' .. lang, args = { iw_link } }
end
elseif not ( mw.isSubsting() or exists ) then
if lang == 'd' then
wikidata_link = iw_link
else
post_link = iw_link
end
end
local post_text = ''
if not is_empty(addition) then
addition = '; ' .. addition
else
addition = ''
end
if not is_empty(wikidata_link) and not is_empty(post_link) then
wikidata_link = wikidata_link .. '; '
end
if not is_empty(post_link) or not is_empty(wikidata_link) then
post_text = string.format(' (%s%s%s)', wikidata_link, post_link, addition)
if not show_originals or ( is_empty(post_link) and is_empty(addition) ) then --проверить
post_text = tostring(
mw.html.create('span')
:addClass('noprint')
:css('white-space', 'nowrap')
:css('font-size', '85%')
:wikitext(post_text)
)
end
end
local exist_message = ''
if exists then
if allow_cat then
categories = categories .. orphan_categories['outdated']
end
local docname = 'Шаблон:Не переведено'
if yesno(args['o']) then
docname = 'Шаблон:Не переведено 2'
end
exist_message = tostring(
mw.html.create('sup')
:addClass('noprint')
:wikitext(
string.format(
'[\'\'%s\'\']',
wikilink(
docname .. '#Действия после появления страницы',
'убрать шаблон',
'Пожалуйста, удалите шаблон, заменив «{{не переведено» на «{{подст:не переведено»'
)
)
)
)
end
local result
result = ru_link .. post_text
if not mw.isSubsting() then
result = result .. exist_message .. categories
end
return result
end
return p