move openiduser function to the openid plugin
parent
55e16be44a
commit
870adf3bbf
25
IkiWiki.pm
25
IkiWiki.pm
|
@ -613,33 +613,10 @@ 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 $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
|
||||
eval q{use CGI 'escapeHTML'};
|
||||
error($@) if $@;
|
||||
return escapeHTML($display);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
sub userlink ($) { #{{{
|
||||
my $user=shift;
|
||||
|
||||
my $oiduser=openiduser($user);
|
||||
my $oiduser=eval { openiduser($user) };
|
||||
if (defined $oiduser) {
|
||||
return "<a href=\"$user\">$oiduser</a>";
|
||||
}
|
||||
|
|
|
@ -164,4 +164,31 @@ 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 $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
|
||||
eval q{use CGI 'escapeHTML'};
|
||||
error($@) if $@;
|
||||
return escapeHTML($display);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
1
|
||||
|
|
|
@ -82,7 +82,7 @@ sub store ($$$) { #{{{
|
|||
|
||||
# See if the committer is an openid.
|
||||
$change->{author}=$change->{user};
|
||||
my $oiduser=IkiWiki::openiduser($change->{user});
|
||||
my $oiduser=eval { IkiWiki::openiduser($change->{user}) };
|
||||
if (defined $oiduser) {
|
||||
$change->{authorurl}=$change->{user};
|
||||
$change->{user}=$oiduser;
|
||||
|
|
Loading…
Reference in New Issue