Move OpenID pretty-printing from openid plugin to core
authorSimon McVittie <smcv@ http://smcv.pseudorandom.co.uk/>
Fri, 10 Jul 2009 17:41:16 +0000 (18:41 +0100)
committerSimon McVittie <smcv@ http://smcv.pseudorandom.co.uk/>
Fri, 10 Jul 2009 17:41:16 +0000 (18:41 +0100)
On various sites I have two IkiWiki instances running from the same
repository: one accessible via http and only accepting openid logins,
and one accessible via authenticated https and only accepting httpauth.
The https version should still pretty-print OpenIDs seen in git history,
even though it does not itself accept OpenID logins.

IkiWiki.pm
IkiWiki/Plugin/openid.pm

index a0a61ac642424e477d26aca7977036ce1355a692..0cb3bf143cc65963b2263486d0ce3c7b8677e73f 100644 (file)
@@ -1063,6 +1063,41 @@ sub htmllink ($$$;@) {
        return "<a href=\"$bestlink\"@attrs>$linktext</a>";
 }
 
+sub openiduser ($) {
+       my $user=shift;
+
+       if ($user =~ m!^https?://! &&
+           eval q{use Net::OpenID::VerifiedIdentity; 1} && !$@) {
+               my $display;
+
+               if (Net::OpenID::VerifiedIdentity->can("DisplayOfURL")) {
+                       # this works in at least 2.x
+                       $display = Net::OpenID::VerifiedIdentity::DisplayOfURL($user);
+               }
+               else {
+                       # this only works in 1.x
+                       my $oid=Net::OpenID::VerifiedIdentity->new(identity => $user);
+                       $display=$oid->display;
+               }
+
+               # Convert "user.somehost.com" to "user [somehost.com]"
+               # (also "user.somehost.co.uk")
+               if ($display !~ /\[/) {
+                       $display=~s/^([-a-zA-Z0-9]+?)\.([-.a-zA-Z0-9]+\.[a-z]+)$/$1 [$2]/;
+               }
+               # Convert "http://somehost.com/user" to "user [somehost.com]".
+               # (also "https://somehost.com/user/")
+               if ($display !~ /\[/) {
+                       $display=~s/^https?:\/\/(.+)\/([^\/]+)\/?$/$2 [$1]/;
+               }
+               $display=~s!^https?://!!; # make sure this is removed
+               eval q{use CGI 'escapeHTML'};
+               error($@) if $@;
+               return escapeHTML($display);
+       }
+       return;
+}
+
 sub userlink ($) {
        my $user=shift;
 
index 87569915bec309e8e3e8243299f1f0db05828208..dc0e0f48ee98e70313abce4d195092989e5537c6 100644 (file)
@@ -180,43 +180,4 @@ sub getobj ($$) {
        );
 }
 
-package IkiWiki;
-
-# This is not used by this plugin, but this seems the best place to put it.
-# Used elsewhere to pretty-display the name of an openid user.
-sub openiduser ($) {
-       my $user=shift;
-
-       if ($user =~ m!^https?://! &&
-           eval q{use Net::OpenID::VerifiedIdentity; 1} && !$@) {
-               my $display;
-
-               if (Net::OpenID::VerifiedIdentity->can("DisplayOfURL")) {
-                       # this works in at least 2.x
-                       $display = Net::OpenID::VerifiedIdentity::DisplayOfURL($user);
-               }
-               else {
-                       # this only works in 1.x
-                       my $oid=Net::OpenID::VerifiedIdentity->new(identity => $user);
-                       $display=$oid->display;
-               }
-
-               # Convert "user.somehost.com" to "user [somehost.com]"
-               # (also "user.somehost.co.uk")
-               if ($display !~ /\[/) {
-                       $display=~s/^([-a-zA-Z0-9]+?)\.([-.a-zA-Z0-9]+\.[a-z]+)$/$1 [$2]/;
-               }
-               # Convert "http://somehost.com/user" to "user [somehost.com]".
-               # (also "https://somehost.com/user/")
-               if ($display !~ /\[/) {
-                       $display=~s/^https?:\/\/(.+)\/([^\/]+)\/?$/$2 [$1]/;
-               }
-               $display=~s!^https?://!!; # make sure this is removed
-               eval q{use CGI 'escapeHTML'};
-               error($@) if $@;
-               return escapeHTML($display);
-       }
-       return;
-}
-
 1