Search code examples
domhyperlinkoutputmediawikiwiki

MediaWiki template produces very messy output


I have a MediaWiki 1.33.0 website in Hebrew. Some of the articles in my website are summarized introduction-level articles that should make it easier to later read larger more complex articles with the same name and topic on Hebrew Wikipedia.

Sometimes I desire to link to a Hebrew Wikipedia articles from my own MediaWiki website; for example; I desire to quickly reference the reader to articles by given names on Hebrew Wikipedia by template, instead copy-pasting each article's link from Hebrew Wikipedia itself.

My template

Template content:

<a href="https://he.wikipedia.org/wiki/{{urlencode:{{{1}}}|PATH}}">{{{1}}}</a><noinclude>
[[קטגוריה:תבניות]]
</noinclude>

Template call example:

{{וה|קרח (כימיה)}}

My problem

My problem is that the output of this template is very messy both in DOM and in article text; a mixture of regular language, HTML, and UTF-8 special characters:

<li>
    "<a href=""
    <a rel="nofollow" class="external free" href="https://he.wikipedia.org/wiki/%D7%A7%D7%A8%D7%97%20%28%D7%9B%D7%99%D7%9E%D7%99%D7%94%29">
        https://he.wikipedia.org/wiki/%D7%A7%D7%A8%D7%97%20%28%D7%9B%D7%99%D7%9E%D7%99%D7%94%29
    </a>
    "">קרח (כימיה)</a>
</li>

In picture:

enter image description here

My question

How could I change the template to create a clickable link with the article name that was given in call, without all redundant output?


Solution

  • A MediaWiki developer, Bawolff shared the correct syntax, as can be seen in this MediaWiki support desk session:

    [https://he.wikipedia.org/wiki/{{urlencode:{{{1}}}|PATH}} {{{1}}}]<noinclude>
    [[קטגוריה:תבניות]]
    </noinclude>
    

    Please don't upvote this question, as all credit goes to Bawolff.