From 29f3082772095030895111f199d6420ef1835250 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 28 Jan 2008 22:58:31 -0500 Subject: move userlink to IkiWiki.pm I have a plugin that needs to use userlink. --- IkiWiki.pm | 28 ++++++++++++++++++++++++++++ IkiWiki/CGI.pm | 28 ---------------------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/IkiWiki.pm b/IkiWiki.pm index 46060c1b2..15402211f 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -609,6 +609,34 @@ sub htmllink ($$$;@) { #{{{ return "$linktext"; } #}}} +sub userlink ($) { #{{{ + my $user=shift; + + eval q{use CGI 'escapeHTML'}; + error($@) if $@; + if ($user =~ m!^https?://! && + eval q{use Net::OpenID::VerifiedIdentity; 1} && !$@) { + # Munge user-urls, as used by eg, OpenID. + my $oid=Net::OpenID::VerifiedIdentity->new(identity => $user); + my $display=$oid->display; + # Convert "user.somehost.com" to "user [somehost.com]". + if ($display !~ /\[/) { + $display=~s/^(.*?)\.([^.]+\.[a-z]+)$/$1 [$2]/; + } + # Convert "http://somehost.com/user" to "user [somehost.com]". + if ($display !~ /\[/) { + $display=~s/^https?:\/\/(.+)\/([^\/]+)$/$2 [$1]/; + } + $display=~s!^https?://!!; # make sure this is removed + return "".escapeHTML($display).""; + } + else { + return htmllink("", "", escapeHTML( + length $config{userdir} ? $config{userdir}."/".$user : $user + ), noimageinline => 1); + } +} #}}} + sub htmlize ($$$) { #{{{ my $page=shift; my $type=shift; diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index 03c448923..5de90e1a8 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -726,32 +726,4 @@ sub cgi (;$$) { #{{{ } } #}}} -sub userlink ($) { #{{{ - my $user=shift; - - eval q{use CGI 'escapeHTML'}; - error($@) if $@; - if ($user =~ m!^https?://! && - eval q{use Net::OpenID::VerifiedIdentity; 1} && !$@) { - # Munge user-urls, as used by eg, OpenID. - my $oid=Net::OpenID::VerifiedIdentity->new(identity => $user); - my $display=$oid->display; - # Convert "user.somehost.com" to "user [somehost.com]". - if ($display !~ /\[/) { - $display=~s/^(.*?)\.([^.]+\.[a-z]+)$/$1 [$2]/; - } - # Convert "http://somehost.com/user" to "user [somehost.com]". - if ($display !~ /\[/) { - $display=~s/^https?:\/\/(.+)\/([^\/]+)$/$2 [$1]/; - } - $display=~s!^https?://!!; # make sure this is removed - return "".escapeHTML($display).""; - } - else { - return htmllink("", "", escapeHTML( - length $config{userdir} ? $config{userdir}."/".$user : $user - ), noimageinline => 1); - } -} #}}} - 1 -- cgit v1.2.3