sub openiduser ($) {
my $user=shift;
- if ($user =~ m!^https?://! &&
+ if (defined $user && $user =~ m!^https?://! &&
eval q{use Net::OpenID::VerifiedIdentity; 1} && !$@) {
my $display;
my $re=quotemeta(shift);
$re=~s/\\\*/.*/g;
$re=~s/\\\?/./g;
- return $re;
+ return qr/^$re$/i;
}
package IkiWiki::FailReason;
return $path;
}
+my %glob_cache;
+
sub match_glob ($$;@) {
my $page=shift;
my $glob=shift;
$glob=derel($glob, $params{location});
- my $regexp=IkiWiki::glob2re($glob);
- if ($page=~/^$regexp$/i) {
+ # Instead of converting the glob to a regex every time,
+ # cache the compiled regex to save time.
+ my $re=$glob_cache{$glob};
+ unless (defined $re) {
+ $glob_cache{$glob} = $re = IkiWiki::glob2re($glob);
+ }
+ if ($page =~ $re) {
if (! IkiWiki::isinternal($page) || $params{internal}) {
return IkiWiki::SuccessReason->new("$glob matches $page");
}
}
sub match_creation_day ($$;@) {
+ my $page=shift;
my $d=shift;
if ($d !~ /^\d+$/) {
- return IkiWiki::FailReason->new('invalid day');
+ return IkiWiki::ErrorReason->new("invalid day $d");
}
- if ((localtime($IkiWiki::pagectime{shift()}))[3] == shift) {
+ if ((localtime($IkiWiki::pagectime{$page}))[3] == $d) {
return IkiWiki::SuccessReason->new('creation_day matched');
}
else {
}
sub match_creation_month ($$;@) {
+ my $page=shift;
my $m=shift;
if ($m !~ /^\d+$/) {
- return IkiWiki::FailReason->new('invalid month');
+ return IkiWiki::ErrorReason->new("invalid month $m");
}
- if ((localtime($IkiWiki::pagectime{shift()}))[4] + 1 == shift) {
+ if ((localtime($IkiWiki::pagectime{$page}))[4] + 1 == $m) {
return IkiWiki::SuccessReason->new('creation_month matched');
}
else {
}
sub match_creation_year ($$;@) {
+ my $page=shift;
my $y=shift;
if ($y !~ /^\d+$/) {
- return IkiWiki::FailReason->new('invalid year');
+ return IkiWiki::ErrorReason->new("invalid year $y");
}
- if ((localtime($IkiWiki::pagectime{shift()}))[5] + 1900 == $y) {
+ if ((localtime($IkiWiki::pagectime{$page}))[5] + 1900 == $y) {
return IkiWiki::SuccessReason->new('creation_year matched');
}
else {
return IkiWiki::ErrorReason->new("no user specified");
}
- if (defined $params{user} && $params{user}=~/^$regexp$/i) {
+ if (defined $params{user} && $params{user}=~$regexp) {
return IkiWiki::SuccessReason->new("user is $user");
}
elsif (! defined $params{user}) {