K wobsahej skočić

Wikipedija:Lua/Module/URLutil/en

Z Wikipedije, swobodneje encyklopedije
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 protocol
  • https:// – protocol
  • nothing – if URL begin invalid
isAuthority
Is it a server address (also IP) of a resource, including port?
  • 1yes
isDomain
Is it a named domain, including sub domains?
  • 1yes
isHost
Is it a server address without port (also IP)?
  • 1yes
isIP
Is it an IP address?
  • 4 if IPv4 (in common dotted decimal notation)
  • 6 if IPv6
  • nothing – else
isIPv4
Is it an IPv4 address in common notation (segmentation by dots, decimal)?
  • 1yes
isIPv6
Is it an IPv6 address?
  • 1yes
isMailAddress
Is it an e-mail address?
  • 1yes
isMailLink
Is it an e-mail link (mailto:)?
  • 1yes
isProtocolDialog
Is it an URL or scheme keyword, which could be used to initiate a dialog in a Wiki?
mailto, irc, ircs, telnet
  • 1yes
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.
  • 1yes
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.
  • 1yes
isSuspiciousURL
Is it an URL, which might be syntactically problematic and might trigger a warning?
  • 1yes
isUnescapedURL
Is it an URL, where wikisyntax [ | ] is to be escaped?
  • 1yes
isWebURL
Is it a valid adress for a resource (any protocol)?
  • 1yes

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, or false
  • URLutil.getScheme()
  • URLutil.isAuthority()
  • URLutil.isDomain()
  • URLutil.isHost()
  • URLutil.isIP()
    numerical 4, 6, or false
  • 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.

General library; no limitations.

None.

  • mw: Uri library – other functionalities on general URI; but in particular helpful for Wiki-URL.
Z Wikipedije, swobodneje encyklopedije