Wikipedija:Lua/Module/URLutil/en
Programowanje předłohi | Diskusije | Lua | Testy | Podstrony | ||||
---|---|---|---|---|---|---|---|---|
Modul | Hornjoserbsce | English | Deutsch
|
Modul: | Dokumentacija |
URLutil
– Module with functions for strings in context of internet addressing (URL; IP address – including IPv4 and IPv6 – as well as e-mail). Internationalized adresses (IRI) are also supported.
Supposing some benefit for a Wiki project, only persistent open access in world wide web is supported. Some special cases are not implemented, but hardly relevant:
- IPv4 address not in common notation (dotted decimal)
- URL with IPv6 host (in brackets; slightly opposing wikisyntax)
- Authority with username
Functions for templates
[žórłowy tekst wobdźěłać]All functions expect exactly one unnamed parameter (which should be provided to get a meaningful answer). Whitespace ahead and after content is ignored.
The return value is an empty string (“nothing”), if the parameter value does not fulfil the expectations. If there is a result or the query condition is true, at least one visible character will be returned. The result does not begin or end with a space.
- getAuthority
- Extract server access from a resource URL (lowercase result)
- nothing – if invalid
- getHost
- Extract domain or IP address from a resource URL (lowercase result)
- nothing – if invalid
- getPort
- Extract port number from a resource URL (numeric result)
- nothing – if not present or invalid
- getScheme
- Extract scheme from a resource URL (lowercase result, including double slashes)
//
– relative protocolhttps://
– protocol- nothing – if URL begin invalid
- isAuthority
- Is it a server address (also IP) of a resource, including port?
1
– yes
- isDomain
- Is it a named domain, including sub domains?
1
– yes
- isHost
- Is it a server address without port (also IP)?
1
– yes
- isIPv4
- Is it an IPv4 address in common notation (segmentation by dots, decimal)?
1
– yes
- isIPv6
- Is it an IPv6 address?
1
– yes
- isMailAddress
- Is it an e-mail address?
1
– yes
- isMailLink
- Is it an e-mail link (mailto:)?
1
– yes
- isProtocolDialog
- Is it an URL or scheme keyword, which could be used to initiate a dialog in a Wiki?
mailto, irc, ircs, telnet
1
– yes
- isProtocolWiki
- Is it an URL or scheme keyword, which could point in a Wiki to a resource?
- Relative protocol and
ftp git http https mms nntp svn worldwind
- Not desired are here: gopher, wais as well as mailto, irc, ircs, telnet.
1
– yes
- isResourceURL
- Is it an URL, which provides general access to a resource? These are: relative protocol, http, https, ftp and also a valid host. Other URL might be used on project or functional pages, but not in encyclopedic context.
1
– yes
- isSuspiciousURL
- Is it an URL, which might be syntactically problematic and might trigger a warning?
1
– yes
- isUnescapedURL
- Is it an URL, where wikisyntax
[ | ]
is to be escaped?1
– yes
- isWebURL
- Is it a valid adress for a resource (any protocol)?
1
– yes
Examples (test page)
[žórłowy tekst wobdźěłać]A test page illustrates practical use.
Functions for Lua modules (API)
[žórłowy tekst wobdźěłać]All functions described above can be used by other modules:
local lucky, URLutil = pcall( require, "Module:URLutil" )
if type( URLutil ) == "table" then
URLutil = URLutil.URLutil()
else
-- failure; URLutil is the error message
return "<span class='error'>" .. URLutil .. "</span>"
end
Subsequently there are available:
- URLutil.getAuthority()
- URLutil.getHost()
- URLutil.getPort()
numerical value, orfalse
- URLutil.getScheme()
- URLutil.isAuthority()
- URLutil.isDomain()
- URLutil.isHost()
- URLutil.isIP()
numerical 4, 6, orfalse
- URLutil.isIPv4()
- URLutil.isIPv6()
- URLutil.isMailAddress()
- URLutil.isMailLink()
- URLutil.isProtocolDialog
- URLutil.isProtocolWiki()
- URLutil.isResourceURL()
- URLutil.isSuspiciousURL()
- URLutil.isUnescapedURL()
- URLutil.isWebURL()
If succeeding, the URLutil.get*() return a string, the URLutil.is*() true
(if no exception mentioned); on failure always false
.
Usage
[žórłowy tekst wobdźěłać]General library; no limitations.
Dependencies
[žórłowy tekst wobdźěłać]None.
See also
[žórłowy tekst wobdźěłać]- mw: Uri library – other functionalities on general URI; but in particular helpful for Wiki-URL.
Antetype
[žórłowy tekst wobdźěłać]- de:Vorlage:URLutil - 2013-05-06, which was partielly created from en:Module:IPAddress – 2013-03-01
- Unit tests: en:Module:IPAddress/tests