Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mediawiki open external links in a new window

Tags:

mediawiki

I want to enable opening external links in a new window function in Mediawiki. I tried to modify the "LocalSettings.php" file according to the below instructions:

http://www.mediawiki.org/wiki/Manual:Opening_external_links_in_a_new_window

But I still couldn't get it working. When I looked up in the above link "Discussion" wiki page I found more informations which confused me. Any idea how to set this work in a simple and straightforward way?

like image 423
Xianlin Avatar asked Mar 26 '12 05:03

Xianlin


2 Answers

  • If you want a few specific links to open in a new window: You can use the LinkTarget extension. You can then surround the appropriate links with an HTML element with a class of your choosing and get the extension to handle them.

    (tor's answer also had a relevant extension linked, but Wikia removed that extension and it probably will not be maintained).

  • If you want all external links to open in a new window: MediaWiki already has a setting for it: $wgExternalLinkTarget. Just add the following to your LocalSettings.php file:

    $wgExternalLinkTarget = '_blank';
    

    Do keep in mind that some internal links might not be identified as such, and therefore will open in a new window; one such example is an internal edit link created by using

    [{{fullurl:Main Page|action=edit}}]
    


Link: $wgExternalLinkTarget on MediaWiki.org

like image 190
Dror S. Avatar answered Sep 29 '22 11:09

Dror S.


I'm not sure if you want to open all external links in new windows (tabs) or only select links.

If it's the latter, then you can try our new window links extension. Not necessarily pretty, but will work if you only need a few links.

Now, if you want all external links to open up in new windows, you need to use the LinkerMakeExternalLink hook and modify the $attribs parameter to your liking.

Happy hacking!

like image 40
tor Avatar answered Sep 29 '22 11:09

tor