+sub is_externallink ($$;$$) {
+ my $page = shift;
+ my $url = shift;
+ my $anchor = shift;
+ my $force = shift;
+
+ if (defined $anchor) {
+ $url.="#".$anchor;
+ }
+
+ if (! $force && $url =~ /$email_regexp/) {
+ # url looks like an email address, so we assume it
+ # is supposed to be an external link if there is no
+ # page with that name.
+ return (! (bestlink($page, linkpage($url))))
+ }
+
+ return ($url =~ /$url_regexp/)
+}
+
+sub externallink ($$;$) {
+ my $url = shift;
+ my $anchor = shift;
+ my $pagetitle = shift;
+
+ if (defined $anchor) {
+ $url.="#".$anchor;
+ }
+
+ # build pagetitle
+ if (! $pagetitle) {
+ $pagetitle = $url;
+ # use only the email address as title for mailto: urls
+ if ($pagetitle =~ /^mailto:.*/) {
+ $pagetitle =~ s/^mailto:([^?]+).*/$1/;
+ }
+ }
+
+ if ($url !~ /$url_regexp/) {
+ # handle email addresses (without mailto:)
+ $url = "mailto:" . $url;
+ }
+
+ return "<a href=\"$url\">$pagetitle</a>";
+}
+