4

I'm creating template on a personal wiki and I want some of the links to have custom attributes (e.g. rel, class, etc.).

Using HTML Syntax

I tried to put it as HTML code, but it's then escaped:

<a href="#{{{atelier-id|ex:atelier-id}}}" class="pilcrow">¶</a>
<a href="{{{auteur_url|ex:giroll.org/}}}" rel="author">{{{auteur|ex:auteur}}}</a>

Using Wiki Syntax

Then I tried using a wiki syntax, but still no good

[[#{{{atelier-id|ex:atelier-id}}}"|¶|pilcrow]]

Question

This seems trivial but I don't find any information on Help:Links page.

So how should I do to add extra attributes to my links ?

Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178

3 Answers3

2

MediaWiki has no built in way to add link attributes, however there are at least two extensions that provide that functionality. You could try:

leo
  • 8,106
  • 7
  • 48
  • 80
  • what about HTML syntax does it escape `` tag ? – Édouard Lopez Nov 15 '13 at 09:34
  • 1
    Yes, unless you set [$wgRawHtml](https://www.mediawiki.org/wiki/Manual:$wgRawHtml) to true in `LocalSettings.php` (which is a dangerous thing to do) it does escape everything except for [a few allowed tags](https://meta.wikimedia.org/wiki/Help:HTML_in_wikitext#Permitted_HTML) – leo Nov 25 '13 at 10:47
  • What Extension:LinkAttributes need (some more tests or colaborations?) to be a stable release? – Peter Krauss Feb 11 '15 at 10:10
  • @PeterKrauss An extra pair of eyes, and some testing, I belive! :-) – leo Feb 11 '15 at 10:12
-1

Have you tried creating a class in Mediawiki:Common.css that adds the desired attributes to <a> tags? Mediawiki doesn't allow raw anchor tags in the code, but wikilinks are still converted to anchor tags when the page is rendered. IF you do something like this:

.class a:link,
.class a:visited,
.class a:active,
.class a:hover {
    css: some css;
}

then you can wrap your link in the desired class, e.g. <span class="class">[[link]]</span>, and have the attributes applied automatically. You should be able to invoke javascript in this way as well.

-1

You can solve this by wrapping your links in a span with an id and adding a CSS selector for that id's a elements

In your article:

<span id="link-wrapper">[[YourLink]]</span>

In your CSS:

#link-wrapper a
{
    background-color: #ffffff;
}

I don't think I can imagine a situation where that won't suffice. There's plenty of other workarounds I can think of, let me know if this one won't do.

Robin De Schepper
  • 4,942
  • 4
  • 35
  • 56