Изменения

+ всплывающие подсказки; оф
Строка 6: Строка 6:  
end
 
end
   −
local function wikilink(lang, title, text)
+
local function wikilink(title, text, tooltip, lang)
 
if is_empty(text) then
 
if is_empty(text) then
 
text = title
 
text = title
 
end
 
end
if lang ~= 'ru' then
+
if lang ~= nil and lang ~= 'ru' then
 
title = string.format(':%s:%s', lang, title)
 
title = string.format(':%s:%s', lang, title)
 +
end
 +
if tooltip ~= nil then
 +
text = tostring(
 +
mw.html.create('span')
 +
:attr('title', tooltip)
 +
:wikitext(text)
 +
)
 
end
 
end
 
return string.format('[[%s|%s]]', title, text)
 
return string.format('[[%s|%s]]', title, text)
Строка 29: Строка 36:  
local languages = mw.loadData('Module:Languages/data')
 
local languages = mw.loadData('Module:Languages/data')
 
local error = require('Module:Error').error
 
local error = require('Module:Error').error
 +
local prepositional = require('Module:Languages').transform_lang
   −
local leave = yesno(args['l'])
+
local leave_always = yesno(args['l'])
 +
local leave_if_redirect = yesno(args['r'])
 
 
 
local categories = ''
 
local categories = ''
Строка 57: Строка 66:  
args[1] = args['надо'] or args['нужно'] or args[2] or ''
 
args[1] = args['надо'] or args['нужно'] or args[2] or ''
 
args[2] = args['текст'] or args[3]
 
args[2] = args['текст'] or args[3]
args[3] = mw.ustring.sub(temp, 2, mw.ustring.find(temp, ':', 2, true) - 1)
+
args[3] = temp:gsub('^:([a-z-]+):(.+)$', '%1')
args[4] = mw.ustring.sub(temp, mw.ustring.find(temp, ':', 2, true) + 1)
+
args[4] = temp:gsub('^:([a-z-]+):(.+)$', '%2')
 
if is_empty(args[1]) then
 
if is_empty(args[1]) then
 
args[1] = args[4]
 
args[1] = args[4]
Строка 64: Строка 73:  
end
 
end
   −
local title = args[1]
+
local page_title = mw.title.new(args[1])
 +
if leave_if_redirect and not page_title.isRedirect then
 +
leave_if_redirect = false
 +
end
 +
local exists = page_title.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 = mw.getContentLanguage():ucfirst(args[1])
 
local text = args[2]
 
local text = args[2]
local exists = mw.title.new(title).exists and not leave
+
local ru_link = wikilink(title, text)
local ru_link = wikilink('ru', title, text)
   
if exists and not mw.isSubsting() then
 
if exists and not mw.isSubsting() then
 
ru_link = tostring(
 
ru_link = tostring(
Строка 74: Строка 91:  
:wikitext(ru_link)
 
:wikitext(ru_link)
 
)
 
)
end
  −
if leave and mw.title.new(title).isRedirect and allow_cat then
  −
categories = categories .. orphan_categories['redirect']
   
end
 
end
 
 
 
local post_text_list = {}
 
local post_text_list = {}
 
local addition = args['a']
 
local addition = args['a']
local show_original = yesno(args['o']) or addition ~= nil
+
local show_originals = yesno(args['o']) or addition ~= nil
 
local wikidata_link = ''
 
local wikidata_link = ''
 
local i, j = 4, 1
 
local i, j = 4, 1
 
while args[i] or args[i - 1] or i <= 4 do
 
while args[i] or args[i - 1] or i <= 4 do
+
 
 
local lang = args[i - 1]
 
local lang = args[i - 1]
 
local iw_title = args[i]
 
local iw_title = args[i]
Строка 98: Строка 112:  
iw_text = iw_title
 
iw_text = iw_title
 
end
 
end
 +
 +
local show_original = show_originals and lang ~= 'd'
 
 
 
local lang_text
 
local lang_text
Строка 103: Строка 119:  
local lang_link
 
local lang_link
 
if lang == 'd' then
 
if lang == 'd' then
iw_text = 'd'
+
lang_text = 'd'
 
elseif languages[lang] == nil then
 
elseif languages[lang] == nil then
 
if allow_cat then
 
if allow_cat then
Строка 112: Строка 128:  
lang_text = languages[lang][1]
 
lang_text = languages[lang][1]
 
lang_title = languages[lang][2]
 
lang_title = languages[lang][2]
lang_link = wikilink('ru', lang_title, lang_text)
+
lang_link = wikilink(lang_title, lang_text)
 
end
 
end
 
+
 +
local tooltip
 +
if lang == 'd' then
 +
tooltip = string.format('Элемент статьи «%s» в Викиданных', title)
 +
else
 +
tooltip = string.format('Версия статьи «%s» на %s', title, prepositional(lang))
 +
end
 +
 
local iw_link
 
local iw_link
if show_original or lang == 'd' then
+
if show_original then
iw_link = wikilink(lang, iw_title, iw_text)
+
iw_link = wikilink(iw_title, iw_text, tooltip, lang)
 
else
 
else
iw_link = wikilink(lang, iw_title, lang_text)
+
iw_link = wikilink(iw_title, lang_text, tooltip, lang)
 
end
 
end
 
 
if lang == 'd' then
+
if show_original then
if not ( mw.isSubsting() or exists ) then
+
if mw.isSubsting() then
 +
post_text_list[j] = string.format('{{l6e|%s|%s}}', lang, iw_text)
 +
elseif exists then
 +
post_text_list[j] = string.format('%s&nbsp;%s', lang_link, italic(iw_text))
 +
else
 +
post_text_list[j] = string.format('%s&nbsp;%s', lang_link, italic(iw_link))
 +
end
 +
elseif not ( mw.isSubsting() or exists ) then
 +
if lang == 'd' then
 
wikidata_link = iw_link
 
wikidata_link = iw_link
 +
else
 +
post_text_list[j] = iw_link
 
end
 
end
elseif mw.isSubsting() or exists then
  −
if show_original then
  −
post_text_list[j] = string.format('%s&nbsp;%s', lang_link, italic(iw_text))
  −
end
  −
elseif show_original then
  −
post_text_list[j] = string.format('%s&nbsp;%s', lang_link, italic(iw_link))
  −
else
  −
post_text_list[j] = iw_link
   
end
 
end
 
 
if show_original and lang ~= 'd' then
+
if show_original then
 
i = i + 3
 
i = i + 3
 
else
 
else
Строка 157: Строка 182:  
if next(post_text_list) ~= nil or not is_empty(wikidata_link) then
 
if next(post_text_list) ~= nil or not is_empty(wikidata_link) then
 
post_text = string.format(' (%s%s%s)', wikidata_link, table.concat(post_text_list, ', '), addition)
 
post_text = string.format(' (%s%s%s)', wikidata_link, table.concat(post_text_list, ', '), addition)
if not show_original then
+
if not show_originals or ( next(post_text_list) == nil and is_empty(addition) ) then
 
post_text = tostring(
 
post_text = tostring(
 
mw.html.create('span')
 
mw.html.create('span')
 
:addClass('noprint')
 
:addClass('noprint')
 +
:css('white-space', 'nowrap')
 
:css('font-size', '85%')
 
:css('font-size', '85%')
 
:wikitext(post_text)
 
:wikitext(post_text)
Строка 175: Строка 201:  
mw.html.create('sup')
 
mw.html.create('sup')
 
:addClass('noprint')
 
:addClass('noprint')
:wikitext('[' .. italic('[[Шаблон:Не переведено#Действия после появления перевода|убрать шаблон]]') .. ']')
+
:wikitext(
 +
string.format(
 +
'&#091;%s&#093;',
 +
wikilink(
 +
'Шаблон:Не переведено#Действия после появления перевода',
 +
italic('убрать шаблон'),
 +
'Пожалуйста, удалите шаблон, заменив «{{не переведено» на  «{{подст:не переведено»'
 +
)
 +
)
 +
)
 
)
 
)
 
end
 
end
Анонимный участник