[Mediawiki-l] Re: Two URL q's. Link to files and directories, and target = blank for new browser window
Mark Lilly
misc at tinorb.com
Wed Jun 8 18:55:29 UTC 2005
Brion Vibber <brion at ...> writes:
>
> Mark Lilly wrote:
> > 1. i am working on an internal intranet, and we have lots of directories on
> > networked servers. I would like to link to these via a URL so users can get
to
> > them. In HTML, it would be:
> > file://pathToServer\pathToDir
>
> See the FAQ for info on this:
> http://meta.wikimedia.org/wiki/MediaWiki_FAQ
got it. thanks.
> > 2. for some of my external links, i want to open a new browser. In HTML:
> > <a href="example.com" target="_blank">Click Here</a>
>
> There's no support for this unless you hack it in. We hate it. :D
OK, here's a hack; i changed the makeExternalLink() function in Skin.php and it
seems to work fine; here it is in case anyone wants it. I added the keyword
_BLANK to my world. That anywhere after the URL in an external link, and voila,
target="_BLANK" and the link opens in a new browser window. tested on IE6.
should work everywhere.
thx,
mark
function makeExternalLink( $url, $text, $escape = true ) {
$style = $this->getExternalLinkAttributes( $url, $text );
global $wgNoFollowLinks;
if( $wgNoFollowLinks ) {
$style .= ' rel="nofollow"';
}
$url = htmlspecialchars( $url );
//check for _BLANK keyword
$blank = '_BLANK';
$posBlank = strpos($text, $blank);
//replace _BLANK with '' if found
if ($posBlank !== false) {
$text = str_replace($blank, '', $text);
}
if( $escape ) {
$text = htmlspecialchars( $text );
}
//if _BLANK, add the target attribute
if ($posBlank !== false) {
return '<a href="'.$url.'"'.$style.' target="'.$blank.'">'.$text.'</a>';
} else {
return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
}
}
More information about the MediaWiki-l
mailing list