Ётамс сёрматфть няфтьфонц потмос (содержаниянцты)

Модуль:URL

Википедиесь лопаста

Для документации этого модуля может быть создана страницаМодуль:URL/doc

functionstartsWith(source,substring)
ifmw.ustring.len(substring)>mw.ustring.len(source)then
returnfalse
end
returnmw.ustring.sub(source,1,mw.ustring.len(substring))==substring
end

p={}

functionformatUrlImpl(source,title)
localscheme,host,path;

source=mw.text.trim(source,"%[%]")
localtitleDelimeterPosition=mw.ustring.find(source,"",1)
iftitleDelimeterPositionthen
ifnottitleortitle==""then
title=mw.ustring.sub(source,titleDelimeterPosition+1)
end
source=mw.ustring.sub(source,1,titleDelimeterPosition-1)
end

localhostStartPosition
localschemeDelimeterPosition=mw.ustring.find(source,"://",1,true)
ifschemeDelimeterPositionthen
scheme=mw.ustring.sub(source,1,schemeDelimeterPosition+2)
hostStartPosition=schemeDelimeterPosition+3
elseifmw.ustring.find(source,"^//",1)then
scheme="//"
hostStartPosition=3
else
scheme="http://"
source=scheme..source
hostStartPosition=8
end

iftitlethen
return'['..source..' '..title..']';
end

localhostDelimeterPosition=mw.ustring.find(source,"/",hostStartPosition,true)
ifhostDelimeterPositionthen
host=mw.ustring.sub(source,hostStartPosition,hostDelimeterPosition-1)
ifhostDelimeterPosition==mw.ustring.len(source)then
path=nil
else
path=mw.ustring.sub(source,hostDelimeterPosition+1)
end
else
host=mw.ustring.sub(source,hostStartPosition)
end

-- post-split format options
ifstartsWith(host,'www.')then
host=mw.ustring.sub(host,5)
end
host=mw.language.new('en'):lc(host)

ifpathandpath~=''andpath~='/'then
return'['..source..' '..host..'/'..path..']';
else
return'['..source..' '..host..']';
end
end

functionp.formatUrl(frame)
localurl=frame.args[1]or'';
localtitle=frame.args[2]or'';

url=mw.text.trim(url)
title=mw.text.trim(title)

ifurl==''then
returnnil
end
iftitle==''then
title=nil
end
returnformatUrlImpl(url,title)
end

functionp.formatUrlSingle(context,options,url)
url=mw.text.trim(url)
ifurl==''then
returnnil
end
localtitle=nil
if(options['text']andoptions['text']~='')then
title=options['text']
end
returnformatUrlImpl(url,title)
end

returnp