This is a documentation subpage for Template:Urltowiki. It may contain usage information, categories and other content that is not part of the original template page. |
This template 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.
A similar URL-to-wikitext transformation can be done directly in the edit window using the User:Js/urldecoder user script.
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
editCode | Result |
---|---|
{{subst:u2w|error=no}}
|
|
{{subst:u2w|url=https://en.wiki.x.io/wiki/Pearl_Jam}}
|
Pearl Jam |
{{subst:u2w|url=https://en.wiki.x.io/w/index.php?title=Pearl_Jam&action=history}}
|
Pearl Jam |
{{subst:u2w|url=https://en.wiki.x.io/wiki/Wikipedia:Village_pump_%28policy%29/Archive_102#Using_.7B.7BComment.7D.7D_on_articles}}
|
Wikipedia:Village pump (policy)/Archive 102#Using {{Comment}} on articles |
{{subst:u2w|url=https://en.wiki.x.io/wiki/Wikipedia:Village_pump_%28policy%29/Archive_102#Using_.7B.7BComment.7D.7D_on_articles|display=the village pump}}
|
the village pump |
{{subst:u2w|url=https://es.wikivoyage.org/wiki/Bogot%C3%A1#En_avi.C3.B3n}}
|
voy:es:Bogotá#En avión |
{{subst:u2w|url=https://es.wikivoyage.org/wiki/Bogot%C3%A1#En_avi.C3.B3n|link=no}}
|
voy:es:Bogotá#En avión |
{{subst:u2w|url=https://es.wikivoyage.org/wiki/Bogot%C3%A1#En_avi.C3.B3n|display=Bogota by plane}}
|
Bogota by plane |
{{subst:u2w|url=https://en.wiki.x.io/wiki/Category:Wikipedians}}
|
Category:Wikipedians |
{{subst:u2w|url=https://en.wiki.x.io/wiki/Category:Wikipedians|colontrick=no}}
|
|
{{subst:u2w|url=https://en.wiki.x.io/wiki/Wikipedia:Village_pump_%28policy%29/Archive_102#Using_.7B.7BComment.7D.7D_on_articles|section=no}}
|
Wikipedia:Village pump (policy)/Archive 102 |
Known 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 hexadecimal. For example, the code {{subst:u2w|url=https://en.wiki.x.io/wiki/Wikipedia:Sandbox#Pi_equals_3.14}}
produces Wikipedia:Sandbox#Pi equals 3. 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- User:Js/urldecoder, a user script that does a similar conversion directly in the edit window
- Template:Url to diff, for converting diff URLs to use the {{diff}} template