Изменения

поддержка Викиданных, небольшая реструктуризация
Строка 7: Строка 7:     
local function wikilink(lang, title, text)
 
local function wikilink(lang, title, text)
if is_empty(text) then  
+
if is_empty(text) then
 
text = title
 
text = title
 
end
 
end
if lang ~= 'ru' then  
+
if lang ~= 'ru' then
 
title = string.format(':%s:%s', lang, title)
 
title = string.format(':%s:%s', lang, title)
 
end
 
end
Строка 29: Строка 29:  
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 title
  −
local text
  −
  −
local addition = args['a']
  −
local show_original = yesno(args['o']) or addition ~= nil
   
local leave = yesno(args['l'])
 
local leave = yesno(args['l'])
 
 
Строка 47: Строка 42:  
 
 
if is_empty(args[1]) and not args['есть']:match('^:[a-z-]+:') then
 
if is_empty(args[1]) and not args['есть']:match('^:[a-z-]+:') then
if allow_cat then  
+
if allow_cat then
 
categories = categories .. orphan_categories['error']
 
categories = categories .. orphan_categories['error']
 
end
 
end
Строка 55: Строка 50:  
if not is_empty(args['есть']) or args[1]:match('^:[a-z-]+:') then
 
if not is_empty(args['есть']) or args[1]:match('^:[a-z-]+:') then
 
local temp
 
local temp
if is_empty(args['есть']) then  
+
if is_empty(args['есть']) then
 
temp = args[1]
 
temp = args[1]
 
else
 
else
Строка 64: Строка 59:  
args[3] = mw.ustring.sub(temp, 2, mw.ustring.find(temp, ':', 2, true) - 1)
 
args[3] = mw.ustring.sub(temp, 2, mw.ustring.find(temp, ':', 2, true) - 1)
 
args[4] = mw.ustring.sub(temp, mw.ustring.find(temp, ':', 2, true) + 1)
 
args[4] = mw.ustring.sub(temp, mw.ustring.find(temp, ':', 2, true) + 1)
if is_empty(args[1]) then  
+
if is_empty(args[1]) then
 
args[1] = args[4]
 
args[1] = args[4]
 
end
 
end
 
end
 
end
   −
title = args[1]
+
local title = args[1]
text = args[2]
+
local text = args[2]
 
local exists = mw.title.new(title).exists and not leave
 
local exists = mw.title.new(title).exists and not leave
 
local ru_link = wikilink('ru', title, text)
 
local ru_link = wikilink('ru', title, text)
Строка 80: Строка 75:  
)
 
)
 
end
 
end
 
+
if leave and mw.title.new(title).isRedirect and allow_cat then
local iw_list = {}
+
categories = categories .. orphan_categories['redirect']
 +
end
 +
 +
local post_text_list = {}
 +
local addition = args['a']
 +
local show_original = yesno(args['o']) or addition ~= nil
 +
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]
 
local iw_text = args[i + 1]
 
local iw_text = args[i + 1]
 +
if is_empty(lang) then
 +
lang = 'en'
 +
end
 
if is_empty(iw_title) then
 
if is_empty(iw_title) then
 
iw_title = title
 
iw_title = title
Строка 93: Строка 98:  
iw_text = iw_title
 
iw_text = iw_title
 
end
 
end
if is_empty(lang) then
+
lang = 'en'
+
local lang_text
end
+
local lang_title
if languages[lang] == nil then
+
local lang_link
if allow_cat then  
+
if lang == 'd' then
 +
iw_text = 'd'
 +
elseif languages[lang] == nil then
 +
if allow_cat then
 
categories = categories .. orphan_categories['error']
 
categories = categories .. orphan_categories['error']
 
end
 
end
return error{'некорректный ISO-код языка'} .. categories
+
return error{'некорректный ISO-код «' .. lang .. '»'} .. categories
 +
else
 +
lang_text = languages[lang][1]
 +
lang_title = languages[lang][2]
 +
lang_link = wikilink('ru', lang_title, lang_text)
 
end
 
end
 +
 
local iw_link
 
local iw_link
if show_original then
+
if show_original or lang == 'd' then
 
iw_link = wikilink(lang, iw_title, iw_text)
 
iw_link = wikilink(lang, iw_title, iw_text)
 
else
 
else
iw_link = wikilink(lang, iw_title, languages[lang][1])
+
iw_link = wikilink(lang, iw_title, lang_text)
 
end
 
end
iw_list[j] = {
+
['link'] = iw_link,
+
if lang == 'd' then
['lang'] = lang,
+
if not ( mw.isSubsting() or exists ) then
['text'] = iw_text
+
wikidata_link = iw_link
}
+
end
if show_original then
+
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
 +
 +
if show_original and lang ~= 'd' then
 
i = i + 3
 
i = i + 3
 
else
 
else
 
i = i + 2
 
i = i + 2
 
end
 
end
j = j + 1
+
if lang ~= 'd' then
 +
j = j + 1
 +
end
 
end
 
end
+
if leave and mw.title.new(title).isRedirect and allow_cat then
  −
categories = categories .. orphan_categories['redirect']
  −
end
  −
if exists and allow_cat then
  −
categories = categories .. orphan_categories['outdated']
  −
end
  −
   
local post_text = ''
 
local post_text = ''
local post_text_list = {}
  −
local i = 1
  −
while iw_list[i] do
  −
local lang = iw_list[i]['lang']
  −
local lang_link = wikilink('ru', languages[lang][2], languages[lang][1])
  −
local iw_text = iw_list[i]['text']
  −
local iw_link = iw_list[i]['link']
  −
if mw.isSubsting() or exists then
  −
if show_original then
  −
post_text_list[i] = string.format('%s&nbsp;%s', lang_link, italic(iw_text))
  −
end
  −
elseif show_original then
  −
post_text_list[i] = string.format('%s&nbsp;%s', lang_link, italic(iw_link))
  −
else
  −
post_text_list[i] = iw_link
  −
end
  −
i = i + 1
  −
end
   
if not is_empty(addition) then
 
if not is_empty(addition) then
 
addition = '; ' .. addition
 
addition = '; ' .. addition
Строка 152: Строка 152:  
addition = ''
 
addition = ''
 
end
 
end
if next(post_text_list) ~= nil then
+
if not is_empty(wikidata_link) and next(post_text_list) ~= nil then
post_text = ' (' .. table.concat(post_text_list, ', ') .. addition .. ')'
+
wikidata_link = wikidata_link .. '; '
 +
end
 +
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)
 
if not show_original then
 
if not show_original then
 
post_text = tostring(
 
post_text = tostring(
Строка 166: Строка 169:  
local exist_message = ''
 
local exist_message = ''
 
if exists then
 
if exists then
 +
if allow_cat then
 +
categories = categories .. orphan_categories['outdated']
 +
end
 
exist_message = tostring(
 
exist_message = tostring(
 
mw.html.create('sup')
 
mw.html.create('sup')
Анонимный участник