Escape | (vertical bar/pipe) in URL in Wiki Markup Template

mxfh picture mxfh · May 11, 2012 · Viewed 7.8k times · Source

Is it possible to escape and keep the nonstandard | character as is in an URL in a template Wiki Markup within a table?

{| class="wikitable"
|-
! Test in Table
|-
| [http://example.org/{var1}|{var2}|{var3} Example]
|}

Should render something like this in the table cell

[http://example.org/1|2|3 Example]

and link to

http://example.org/1|2|3

with the vertical bars as is and not encoded like this

http://example.org/1%7C2%7C3

The 3rd party website requires «|» in the URL, I would fix the URL handling on the server side but that is out of my hands for now. Any help on a workaround?

I tried these:

[http://example.org/1|2|3 Example] doesn't work within a table   
[http://example.org/{var1}|{var2}|{var3} Example] works in tables

but both create valid standard URLs where the vertical bar is properly URL encoded as %7C like above which I would like to prevent.

Answer

BenMQ picture BenMQ · Dec 17, 2012

External links, without support from additional extensions, can only be produced by the [url description] syntax or a plain URL itself. Although as mentioned by skalee, you can use {{!}} or other methods to prevent the pipe symbol from being interpreted as part of the Wikitext syntax, the final link will always be encoded.

Without help from extensions, a quick solution would be JavaScript. (If it is on your own MediaWiki site, that would be very simple. MediaWiki:Common.js contains JavaScript that will be loaded for all users).