autoreview, Бюрократы, Проверяющие участников, developer, editor, Администраторы интерфейса, reviewer, Администраторы, translator
2481
правка
imported>Wikisaurus (поддержка {{основная статья|{{не переведено|...}}}}) |
Admin (обсуждение | вклад) м (Замена текста — «Википедия:» на «ЭАНМ:») |
||
(не показано 25 промежуточных версий 5 участников) | |||
Строка 1: | Строка 1: | ||
local get_args = require('Module:Arguments').getArgs | local get_args = require('Module:Arguments').getArgs | ||
local mError | local mError | ||
local yesno = function (v) return require('Module:Yesno')(v, true) end | local yesno = function (v) return require('Module:Yesno')(v, true) end | ||
Строка 10: | Строка 10: | ||
red_link = 'ЭАНМ:Страницы с модулем Hatnote с красной ссылкой', | red_link = 'ЭАНМ:Страницы с модулем Hatnote с красной ссылкой', | ||
bad_format = 'ЭАНМ:Страницы с модулем Hatnote с некорректно заполненными параметрами', | bad_format = 'ЭАНМ:Страницы с модулем Hatnote с некорректно заполненными параметрами', | ||
formatted = 'ЭАНМ:Страницы с модулем Hatnote с готовым | unparsable_link = 'ЭАНМ:Страницы с модулем Hatnote с нечитаемой ссылкой', | ||
formatted = 'ЭАНМ:Страницы с модулем Hatnote с готовым форматированием', | |||
} | } | ||
Строка 21: | Строка 22: | ||
end | end | ||
function tr. | function tr.define_categories(tracked_cases) | ||
local categories = setmetatable({}, { | local categories = setmetatable({}, { | ||
__tostring = function (self) return table.concat(self) end, | __tostring = function (self) return table.concat(self) end, | ||
__concat = concat | __concat = concat | ||
}) | }) | ||
function categories:add( | function categories:add(element, nocat) | ||
if not nocat then | if not nocat then | ||
table.insert(self, string.format('[[Категория:%s]]', | local cat_name | ||
if tracked_cases and tracked_cases[element] then | |||
cat_name = tracked_cases[element] | |||
else | |||
cat_name = element | |||
end | |||
table.insert(self, string.format('[[Категория:%s]]', cat_name)) | |||
end | end | ||
end | end | ||
Строка 43: | Строка 50: | ||
current_frame:getTitle() | current_frame:getTitle() | ||
if not preview_only or current_frame:preprocess('{{REVISIONID}}') == '' then | if not preview_only or current_frame:preprocess('{{REVISIONID}}') == '' then | ||
return mError.error{string.format('Ошибка в [[%s]]: %s', res_frame_title, msg)} .. categories | mError = require('Module:Error') | ||
return mError.error{ | |||
tag = 'div', | |||
string.format('Ошибка в [[%s]]: %s.' | |||
.. (preview_only and '<br><small>Это сообщение показывается только во время предпросмотра.</small>' or ''), res_frame_title, msg) | |||
} .. categories | |||
else | else | ||
return categories | return categories | ||
Строка 49: | Строка 61: | ||
end | end | ||
function p.parse_link(frame) | |||
link = | local args = get_args(frame) | ||
link = link:match('%[%[ | local link = args[1]:gsub('\n', '') | ||
local label | |||
link = mw.text.trim(link:match('^%[%[([^%]]+)%]%]$') or link) | |||
if link:sub(1, 1) == '/' then | |||
label = link | |||
link = current_title.prefixedText .. link | |||
end | |||
link = link:match(':?(.+)') | |||
if link:match('|') then | if link:match('|') then | ||
link, label = link:match('^([^%|]+)%|(.+)$') | link, label = link:match('^([^%|]+)%|(.+)$') | ||
end | |||
if not mw.title.new(link) then | |||
return nil, nil | |||
end | end | ||
Строка 65: | Строка 89: | ||
if not link then | if not link then | ||
link = current_title. | link = current_title.prefixedText | ||
if section then | if section then | ||
link = '#' .. section | link = '#' .. section | ||
Строка 71: | Строка 95: | ||
end | end | ||
else | else | ||
local parsed_link, parsed_label = p.parse_link{link} | |||
if parsed_link then | |||
link = parsed_link | |||
else | |||
return link | |||
end | |||
if section and not link:match('#') then | if section and not link:match('#') then | ||
link = link .. '#' .. section | link = link .. '#' .. section | ||
if parsed_label then | |||
parsed_label = parsed_label .. '#' .. section | |||
end | |||
end | end | ||
label = (label or link):gsub('^([^#]-)#(.+)$', '%1 § %2') | label = (label or parsed_label or link):gsub('^([^#]-)#(.+)$', '%1 § %2') | ||
end | end | ||
return string.format('[[:%s|%s]]', link, label | if label and label ~= link then | ||
return string.format('[[:%s|%s]]', link, label) | |||
else | |||
return string.format('[[:%s]]', link) | |||
end | |||
end | end | ||
Строка 95: | Строка 131: | ||
local page = mw.title.new(title) | local page = mw.title.new(title) | ||
if not page.exists or mw.title.equals(page, current_title) then | if not page or not page.exists or mw.title.equals(page, current_title) then | ||
return false | return false | ||
end | end | ||
Строка 122: | Строка 158: | ||
bad_format = false, | bad_format = false, | ||
formatted = false, | formatted = false, | ||
unparsable_link = false | |||
} | } | ||
Строка 134: | Строка 171: | ||
element = link -- for {{не переведено}} | element = link -- for {{не переведено}} | ||
else | else | ||
local bad_format = (link:match('|') or link:match('[%[%]]')) ~= nil | |||
local parsed_link, parsed_label = p.parse_link{link} | |||
if | if parsed_link then | ||
tracked.bad_format = tracked.bad_format or bad_format | |||
if links_ns then | |||
parsed_label = parsed_label or parsed_link | |||
parsed_link = mw.site.namespaces[links_ns].name .. ':' .. parsed_link | |||
end | |||
local title = mw.title.new(parsed_link) | |||
tracked.red_link = tracked.red_link or not (title.isExternal or title.exists) | |||
element = p.format_link{parsed_link, nil, label or parsed_label} | |||
else | |||
tracked.unparsable_link = true | |||
element = link | |||
end | end | ||
end | end | ||
Строка 154: | Строка 198: | ||
end | end | ||
return setmetatable(res_list, { | |||
return setmetatable( | |||
__index = tracked, | __index = tracked, | ||
__tostring = function (self) return self | __tostring = function (self) return mw.text.listToText(self, list_sep, last_list_sep) end, | ||
__concat = concat | __concat = concat, | ||
__pairs = function (self) return pairs(tracked) end | |||
}) | }) | ||
end | end | ||
Строка 166: | Строка 209: | ||
local args = get_args(frame) | local args = get_args(frame) | ||
local text = args[1] | local text = args[1] | ||
local id = args.id | |||
local extraclasses = args.extraclasses | local extraclasses = args.extraclasses | ||
local hide_disambig = yesno(args.hide_disambig) | local hide_disambig = yesno(args.hide_disambig) | ||
local res = mw.html.create('div') | local res = mw.html.create('div') | ||
:attr('id', id) | |||
:addClass('hatnote') | :addClass('hatnote') | ||
:addClass('navigation-not-searchable') | |||
:addClass(extraclasses) | :addClass(extraclasses) | ||
:wikitext(text) | :wikitext(text) | ||
Строка 190: | Строка 236: | ||
local nocat = yesno(args.nocat) | local nocat = yesno(args.nocat) | ||
local preview_error = yesno(args.preview_error) | local preview_error = yesno(args.preview_error) | ||
local empty_list_message = args.empty_list_message or 'Не указано ни одной страницы' | |||
categories = tr. | categories = tr.define_categories(index(_tracking_categories or {}, tracking_categories)) | ||
if not prefix then | if not prefix then | ||
Строка 199: | Строка 246: | ||
if not args[1] then | if not args[1] then | ||
categories:add('no_links', nocat) | categories:add('no_links', nocat) | ||
return tr.error( | return tr.error(empty_list_message, categories, preview_error) | ||
end | end | ||
Строка 207: | Строка 254: | ||
local list = p.list(args) | local list = p.list(args) | ||
for k, v in pairs(list) do | |||
if type(v) == 'boolean' and v then | |||
categories:add(k, nocat) | |||
end | |||
end | end | ||
правка