Модуль:URL: Розніца паміж версіямі

[дагледжаная версія][дагледжаная версія]
Змесціва выдалена Змесціва дададзена
Няма тлумачэння праўкі
актуальная версія з ru:Модуль:URL, выпраўленне праблемы з доўгімі URL
Радок 8:
p = {}
 
function formatUrlImpl( source, title, length )
local scheme, host, path
local postfix = ''
local arg1, arg2 = source, title
local isTestPage = mw.title.getCurrentTitle().prefixedText == 'Модуль:URL'
-- Дзве квадратные дужкі запар — [[вікі-спасылка]] вместо [спасылкі] — вяртаем уваход як ёсць.
if string.find( arg1, "[[", 1, true ) then
local result = arg1
if not isTestPage then
result = result .. '[[Категория:Вікіпедыя:Артыкулы з вікі-спасылкай, перададзенай у Модуль:URL]]'
if arg2 then
-- Калі ёсць arg2, а мы распарсіць спасылку не змаглі, і значыць замяніць title не зможам карэктна, гэта ёсць памылка.
result = result .. '[[Категория:Вікіпедыя:Артыкулы з памылковай працай Модуль:URL]]'
end
end
return result
end
-- Больш за адну квадратную дужку — хутчэй за ўсё, зададзена больш за адзін URL — таксама вяртаем як ёсць.
if select(2, string.gsub( arg1, "%[", "" )) > 1 then
local result = arg1
if not isTestPage then
result = result .. '[[Категория:Вікіпедыя:Артыкулы са складаным уваходам у Модуль:URL]]'
if arg2 then
-- Калі ёсць arg2, а мы распарсіць спасылку не змаглі, і значыць замяніць title не зможам карэктна, гэта ёсць памылка.
result = result .. '[[Категория:Вікіпедыя:Артыкулы з памылковай працай Модуль:URL]]'
end
end
return result
end
source = mw.text.trim( source, "%[%] " )
local titleDelimeterPosition = mw.ustring.find( source, " ", 1 )
Радок 16 ⟶ 45:
if not title or title == "" then
title = mw.ustring.sub( source, titleDelimeterPosition + 1 )
local postfixDelimeterPosition = mw.ustring.find( title, "%]", 1 )
if postfixDelimeterPosition then
postfix = mw.ustring.sub( title, postfixDelimeterPosition + 1 )
title = mw.ustring.sub( title, 1, postfixDelimeterPosition - 1 )
end
end
source = mw.ustring.sub( source, 1, titleDelimeterPosition - 1 )
Радок 28 ⟶ 62:
scheme = "//"
hostStartPosition = 3
elseif mw.ustring.find( source, "^mailto:", 1 ) then
scheme = "mailto:"
hostStartPosition = 8
elseif mw.ustring.find( source, "@", 1 ) then
scheme = "mailto:"
source = scheme .. source
hostStartPosition = 8
else
scheme = "http://"
Радок 48 ⟶ 89:
end
end
return '[' .. source .. ' ' .. title .. ']' .. postfix
end
 
Радок 70 ⟶ 111:
 
if path and path ~= '' and path ~= '/' then
returnlocal '['title .. source .. ' ' ..= host .. '/' .. path .. ']'
if length and #title > length then
title = host .. '/' .. mw.ustring.sub( path, 1, length - #title - 2 ) .. '…'
end
return '[' .. source .. ' ' .. title .. ']' .. postfix
else
return '[' .. source .. ' ' .. host .. ']' .. postfix
end
end
Радок 79 ⟶ 124:
local url = frame.args[1] or ''
local title = frame.args[2] or ''
local length = frame.args['length'] and tonumber( frame.args['length'] )
 
url = mw.text.trim( url )
Радок 89 ⟶ 135:
title = nil
end
return formatUrlImpl( url, title, length )
end
 
Радок 101 ⟶ 147:
title = options['text']
end
local length = options['length'] and tonumber( options['length'] )
return formatUrlImpl( url, title )
 
return formatUrlImpl( url, title, length )
end