Module:WLink/doc
| This Lua module is used on approximately 9,200 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
WLink – Module with functions for strings in context of wikilinks and external links (URL). This module was imported from de:Module:WLink.
Usage
All functions expect exactly one unnamed parameter (which should be provided to get a meaningful answer). Whitespace ahead and after content is ignored. HTML Entities would not disturb syntax and might be resolved. The parameter might contain single or double bracketed links which would be extracted if appropriate.
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.
- ansiPercent
- Convert string by ANSI encoding rather than UTF-8 encoding
- Required for some 20th century servers
- Optional parameter
space– encoding of spaces:space=+– common for query componentsspace=_– as for Wikis- Default:
%20
- formatURL
- Create bracketed link, if not yet, from URL or domain
- [http://example.org/about Homepage] yields [http://example.org/about Homepage]
- http://example.org/about yields [http://example.org/about example.org/about]
- example.org yields [http://example.org/ example.org]
- getArticleBase
- Retrieve generic page title, no fragment nor brackets
- Use current page title, if omitted.
- getBaseTitle
- Retrieve last segment in subpage, no fragment
- getExtension
- Retrieve media extension
- Result is downcased (without leading dot).
- getFile
- Retrieve media page identifier
- getFragment
- Retrieve original (not decoded) fragment string after
# getLanguage- Retrieve language identifier
getNamespace- Retrieve namespace number
- getPlain
- Retrieve text with all links replaced by link titles
getProject- Retrieve project identifier within wikifarm (recommendable brief notation)
- getTarget
- Retrieve first target (wikilink or URL)
- getTargetPage
- Retrieve first target page (page name or URL of page)
- Same as getTarget if no fragment.
- getTitle
- Retrieve first link title (wikilink or URL), or wikilink target
- isBracketedLink
- Does attempt match a bracketed link?
- isBracketedURL
- Does attempt match a bracketed URL?
- isCategorization
- Does attempt match a categorization?
- isExternalLink
- Does attempt match an external link?
- isInterlanguage
- Does attempt match an interlanguage link?
- isInterwiki
- Does attempt match an interwiki link?
- isMedia
- Does attempt match a media translusion?
- isTitledLink
- Does attempt match a titled link?
- isValidLink
- Does attempt match a link?
- isWeblink
- Does attempt match an external link?
- isWikilink
- Does attempt match a wikilink?
- failsafe
- Version ID:
2016-10-05 - optional parameter
1– required version- result: empty, if requirement not met
Examples (test page)
A test page illustrates practical use.
Functions for Lua modules (API)
All functions described above can be used by other modules:
local lucky, WLink = pcall( require, "Module:WLink" )
if type( WLink ) == "table" then
WLink = WLink.WLink()
else
-- failure; WLink is the error message
return "<span class=\"error\">" .. WLink .. "</span>"
end
Subsequently there are available:
- WLink.ansiPercent(story, space)
- WLink.formatURL()
- WLink.getArticleBase()
- WLink.getBaseTitle()
- WLink.getExtension()
- WLink.getFile()
- WLink.getFragment()
false, if not found; but empty string if empty fragment.- No leading
#in result.
- WLink.getLanguage()
- WLink.getNamespace()
- WLink.getPlain()
- WLink.getProject()
- WLink.getTarget()
- WLink.getTargetPage()
- WLink.getTitle()
- WLink.isBracketedLink()
- WLink.isBracketedURL()
- WLink.isCategorization()
- WLink.isExternalLink()
- WLink.isInterlanguage()
- WLink.isInterwiki()
- WLink.isMedia()
- WLink.isTitledLink()
- WLink.isValidLink()
- WLink.isWeblink()
- WLink.isWikilink()
- WLink.wikilink()
- Yields table with wikilink components, else
false. - Components might be, if provided:
lead– leading colon:present and required, iftrueproject– project interwiki within wikifarm (recommendable brief notation)lang– known language version (downcased)ns– number of namespacespace– local canonical name of namespacetitle– page title as provided; at least empty string
- Yields table with wikilink components, else
- WLink.failsafe(atleast)
- atleast
optional
nil or required version
- atleast
- returns: string or false
If succeeding, the WLink.get*() return a string, the WLink.is*() true (if no exception mentioned); on failure always false.
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.