Search code examples
mediawiki-templates

Passing an url to a template


I am trying to pass a simple mwurl to a template, but this doesn't seem to work always.

Template:U:

my link: {{{1}}}

Calling code:

{{U|[https://www.istaria-lexica.de/index.php?title=User:Elteria_Shadowhand/sandbox&action=edit test link]}}

If I use google.com instead, the template works. I assume there's some problem with special characters? What am I doing wrong?


Solution

  • The problem is with the equal sign in the URL. It has a special meaning in the template parametre syntax: what is on the left of the equal sign is treated as the parametre's name, what is on the right, its value.

    You can either:

    • Pass the URL as a named parametre rather than an anonymous: {{U|1=[https://www.istaria-lexica.de/index.php?title=User:Elteria_Shadowhand/sandbox&action=edit test link]}},
    • Replace all equal signs with the pre-defined (in recent versions of MediaWiki) template {{=}}: {{U|[https://www.istaria-lexica.de/index.php?title{{=}}User:Elteria_Shadowhand/sandbox&action{{=}}edit test link]}}.

    In addition:

    • perhaps, moving the square brackets from the template parameter to its definition would be a good idea: Template:U = my link: [{{{1}}} {{{2}}}],
    • if the link is to the same wiki, it better to let the wiki engine form it: {{fullurl:User:Elteria Shadowhand/sandbox|action=edit}} or, better, {{localurl:User:Elteria Shadowhand/sandbox|action=edit}}. The boilerplate code can be moved to the template definition as well: Template:U = [{{localurl:{{{1}}}|action=edit}} {{{2}}}], called with {{U|User:Elteria Shadowhand/sandbox|test link}},
    • if the link is on the same page that is to be edited, you can use {{FULLPAGENAME}}: Template:U = [{{localurl:{{FULLPAGENAME}}|action=edit}} {{{1}}}], called as {{U|test link}},
    • finally, if the link text is always the same, or is the linked page name, there would be no need to pass it to the template: Template:U = [{{localurl:{{FULLPAGENAME}}|action=edit}} test link], called as {{U}}, or Template:U = [{{localurl:{{FULLPAGENAME}}|action=edit}} {{FULLPAGENAME}}], also called as {{U}}, or Template:U = [{{localurl:{{{1}}}|action=edit}} {{{1}}}], called as {{U|User:Elteria Shadowhand/sandbox}}.