Template:Urltowiki
Uses Lua: |
This template takes a wiki URL and outputs the equivalent wikilink, with optional display text. It is useful for quickly creating properly formatted wikilinks to talk page sections or external wikis. It accepts URLs from most Wikimedia wikis. The template should usually be substituted, but will work with transclusion as well.
If given a partial URL (without the protocol and the host name) the template will remove any underlines and decode percent-encoded characters. If given a valid URL that is not recognised as a Wikimedia wiki, it will output the URL unlinked. See below for how to add new wikis.
The shortcut {{u2w}}
is available.
Usage
edit- Quick usage
- CAUTION: This syntax will not work if the URL contains "=".
{{subst:u2w|<!-- URL -->|<!-- display text -->}}
- Basic usage
- The following will work for all URLs.
{{subst:u2w|1=<!-- URL -->|2=<!-- display text -->}}
{{subst:u2w|url=<!-- URL -->|display=<!-- display text -->}}
- All parameters
{{subst:u2w | url = | display = | link = | section = | colontrick = | error = }}
Parameters
edit- url - the URL you wish to be converted into wikitext. This parameter is required. You can also use the first positional parameter for the URL, but this will not work if the URL contains an equals sign.
- display - the text you would like to be displayed, if not the interwiki link itself. This is equivalent to the text that comes after the pipe in a piped link. You can also use the second positional parameter for the display text, but this will only work if the first positional parameter is also present. Therefore, if you use this for the display value there must be no equals sign in the URL.
- link - if this is set to "no", the template will not link the interwiki link, and will not display the display text.
- section - if this is set to "no", no section links will be produced.
- colontrick - if this is set to "no" the template will not use the colon trick for files and category pages. Note that if
|link=no
then the colon trick will not be used anyway - this is necessitated by a longstanding bug in Mediawiki. - error - if this is set to "no" the template will return nothing instead of producing error messages if there is missing or invalid input.
Examples
editKnown limitations
editThis template will not work correctly if the original section name contains anything that looks percent-encoded. This usually means a period followed by two characters that could be hexidecimal. For example, the code {{subst:u2w|url=https://en.wikipedia.org/wiki/Wikipedia:Sandbox#Pi_equals_3.14}}
produces Lua error in package.lua at line 80: module 'Module:InterwikiTable' not found.. To work around this you can set |section=no
and |link=no
, and add the link and the proper section name yourself. However, bear in mind that the actual link will still work properly even if it is displayed incorrectly, so it is not necessary to use the workaround if you also set the |display=
parameter.
Additionally, some Wikimedia sites may not be supported yet. If you come across a site that isn't supported, please consider adding it to Module:InterwikiTable, as then it will work for all users.
See also
edit- {{Url to diff}}, for converting diff URLs to use the {{diff}} template
The above documentation is transcluded from Template:Urltowiki/doc. (edit | history) Editors can experiment in this template's sandbox (create | mirror) and testcases (create) pages. Please add categories to the /doc subpage. Subpages of this template. |