MediaWiki tricks 1 – Custom link colors

This is the first post in an irregular series of nifty tricks that saved my day when using MediaWiki and which maybe are useful for you, too…

Sometimes you may want to color a wikilink (for example in order to indicate that two wikilinks are pointing to fundamental different kinds content) with something different than standard blue for existant pages (Monobook).

A minimal wiki code example for turning a wiki link green:

[[ARTICLE|<span style="color:green;">ARTICLE</span>]]

The trick is to do the coloring inside the alternative text and not outside the link brackets (thanks to Shardsofmetal for the hint). However there is a problem: In case ARTICLE does not exist, the link would be still green instead of red for indicating missing content. Using the „ifexist“ function of the parser functions extension this can be solved (splitted one-liner):

[[ARTICLE|{{#ifexist: ARTICLE
|<span style="color:green;">ARTICLE</span>
|ARTICLE}}]]

Now the link turns green in case ARTICLE exists and stays with the default red in case not.

Of course this is rather long winded and you probably want to shorten this with a template if you’re using this more than once. So the template code would be like that:

[[{{{1}}}|{{#ifexist: {{{1}}}
|<span style="color:green;">{{{1}}}</span>
|{{{1}}}}}]]

The wiki code using such a link does look with the template much shorter now:

{{TEMPLATENAME|ARTICLE}}

But now there is a new problem when using a template. You sometimes want to link with a different expression like COOL PAGE to ARTICLE. The solution for the template code is using an optional second variable:

[[{{{1}}}|{{#ifexist: {{{1}}}
|<span style="color:green;">{{{2|{{{1}}}}}}</span>
|{{{2|{{{1}}}}}}}}]]

Now you can call it both ways:

{{TEMPLATENAME|ARTICLE}}
{{TEMPLATENAME|ARTICLE|ALTERNATIVE LINK TEXT}}

Dislcaimer: Make spare use of it. To much stuff at once cocks up the „wow nice effect“.😉

8 Antworten to “MediaWiki tricks 1 – Custom link colors”

  1. Dave Hoff Says:

    This is great. I’m a n00b trying to make wiki’s, reading books, scouring sites. It so helpful to find plain English, useful tips. Made my day!

  2. Yan Says:

    Thanks, this helped me a lot for my quick fix where I didn’t have to change the pre-defined color settings that would have affected the whole wiki.

  3. John Says:

    Thanks a lot for sharing, nice trick, saved me lot of time🙂
    Vielen Danke !

  4. sidfajiof Says:

    http://en.wikipedia.org/wiki/Wikipedia:Link_color

    ^^^^ better way.

  5. facebook backgrounds layouts Says:

    It is appropriate time to make a few plans for the longer term and it is time to be happy.

    I’ve read this post and if I may I wish to recommend you some interesting issues or advice. Perhaps you can write next articles referring to this article. I wish to read more things approximately it!

  6. how to cure heartburn fast Says:

    Fascinating blog! Is your theme custom made or did you download
    it from somewhere? A design like yours with a few simple adjustements would really make my blog stand out.
    Please let me know where you got your theme.
    With thanks

  7. get taller Says:

    Hey there! This is kind of off topic but I need some guidance from an established blog.

    Is it difficult to set up your own blog? I’m not very techincal but I can figure things out pretty quick. I’m thinking about setting
    up my own but I’m not sure where to begin. Do you have any points or suggestions? Many thanks

  8. hostgator vouchers Says:

    These are actually impressive ideas in about blogging. You have touched some
    fastidious factors here. Any way keep up wrinting.

Schreibe einen Kommentar

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s


%d Bloggern gefällt das: