[pmwiki-users] Indicating external links

john.rankin at affinity.co.nz john.rankin at affinity.co.nz
Thu Jun 5 16:23:00 CDT 2008

>> have a look at
>> http://www.wikipublisher.org/wiki/index.php?n=Main.HomePage
>> which has 2 external links.
>> This is built into the skin for the site. If you want, I can
>> send the zipped skin to you off-list with an explanation.
> John, in case it is a different solution from the published ones[1]
> what about sharing it here if you like (or as a note to the cited recipe)?
> Luigi
It does a few extra things. I'll update the recipe, but here are the details:

- icons on external links and mailto links

- no icon if the text of the external link is itself an image

- suppress Attach: once a file has been uploaded, so linktext=filename

- tidy up the page logo link

The code in pub/skins/skinname/skinname.php:

global $PageLogoUrl, $WikiTitle, $ImgExtPattern, $HTMLStylesFmt,
  $LinkFunctions, $UrlLinkFmt, $UrlLinkTxtFmt, $UrlLinkImgFmt, $IMapLinkFmt,
  $MailLinkTxtFmt, $EnableUploadOverwrite;

if (preg_match("/$ImgExtPattern$/", $PageLogoUrl)) {
    $PageLogoUrl = "<img src='$PageLogoUrl' alt='$WikiTitle' border='0' />";
    $HTMLStylesFmt[] =
      '#wikilogo a:link, #wikilogo a:visited, #wikilogo a:hover { border:
0; }';

$LinkFunctions['http:'] = 'TxtLinkIMap';
$LinkFunctions['https:']  = 'TxtLinkIMap';
$LinkFunctions['mailto:']  = 'MailLinkIMap';
$LinkFunctions['Attach:'] = 'TxtLinkUpload';
$IMapLinkFmt['Attach:'] =
    "<a class='urllink' href='\$LinkUrl' rel='nofollow'>\$UploadText</a>";
if ($EnableUploadOverwrite)
    $IMapLinkFmt['Attach:'] .=
    "<a class='createlink' href='\$LinkUpload'>&nbsp;&Delta;</a>";
$UrlLinkTxtFmt = "<span class='url'>$UrlLinkFmt</span>";
$MailLinkTxtFmt = "<span class='mailto'>$UrlLinkFmt</span>";
$UrlLinkFmt    = $UrlLinkTxtFmt;
$UrlLinkImgFmt =
    "<a class='urllinkimg' href='\$LinkUrl' rel='nofollow'>\$LinkText</a>";

function TxtLinkIMap($pagename,$imap,$path,$title,$txt,$fmt=NULL) {
  global $UrlLinkImgFmt, $UrlLinkTxtFmt;
  if (!$fmt)
      $fmt = preg_match('/^<img/',$txt) ? $UrlLinkImgFmt : $UrlLinkTxtFmt;
  return LinkIMap($pagename,$imap,$path,$title,$txt,$fmt);

function TxtLinkUpload($pagename, $imap, $path, $title, $txt, $fmt=NULL) {
  global $FmtV;
  $FmtV['$UploadText'] = str_replace('Attach:','',$txt);
  return LinkUpload($pagename,$imap,$path,$title,$txt,$fmt);

function MailLinkIMap($pagename,$imap,$path,$title,$txt,$fmt=NULL) {
  global $UrlLinkImgFmt, $MailLinkTxtFmt;
  if (!$fmt)
      $fmt = preg_match('/^<img/',$txt) ? $UrlLinkImgFmt : $MailLinkTxtFmt;
  return LinkIMap($pagename,$imap,$path,$title,$txt,$fmt);

In the skinname.css file, I have:

span.url {
	background: url(external.png) top right no-repeat;
	padding-right: 0.9em;
span.mailto {
	background: url(mail_icon.gif) bottom right no-repeat;
	padding-right: 1.1em;

The skinname directory contains icons for external and mailto links.

As far as I can tell, it does what I expect in all cases. YMMV, of course.

> -----
> [1] http://www.pmwiki.org/wiki/Cookbook/ExternalLinks

More information about the pmwiki-users mailing list