aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2010-02-11 20:39:10 -0500
committerJoey Hess <joey@gnu.kitenet.net>2010-02-11 20:39:10 -0500
commitc923e0ba3377f85107ccea1933a042aaec675c77 (patch)
treedd185a72ba4b63a171fd68cb2342ae64c8e73788
parent7af18f2a1ec8b5ce4764813b0464112f517e806f (diff)
downloadikiwiki-c923e0ba3377f85107ccea1933a042aaec675c77.tar
ikiwiki-c923e0ba3377f85107ccea1933a042aaec675c77.tar.gz
Allow globs to be used in user() pagespecs.
-rw-r--r--IkiWiki.pm4
-rw-r--r--debian/changelog1
-rw-r--r--doc/ikiwiki/pagespec.mdwn3
-rwxr-xr-xt/pagespec_match.t9
4 files changed, 14 insertions, 3 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm
index de7dbfc79..a96ff1236 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -2266,11 +2266,13 @@ sub match_user ($$;@) {
my $user=shift;
my %params=@_;
+ my $regexp=IkiWiki::glob2re($user);
+
if (! exists $params{user}) {
return IkiWiki::ErrorReason->new("no user specified");
}
- if (defined $params{user} && lc $params{user} eq lc $user) {
+ if (defined $params{user} && $params{user}=~/^$regexp$/i) {
return IkiWiki::SuccessReason->new("user is $user");
}
elsif (! defined $params{user}) {
diff --git a/debian/changelog b/debian/changelog
index 14be7ec69..d74abd0f9 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -21,6 +21,7 @@ ikiwiki (3.20100123) UNRELEASED; urgency=low
a button on the login form to use it.
* httpauth: Add httpauth_pagespec setting that can be used to limit
pages to only being edited via users authed with httpauth.
+ * Allow globs to be used in user() pagespecs.
-- Joey Hess <joeyh@debian.org> Tue, 26 Jan 2010 22:25:33 -0500
diff --git a/doc/ikiwiki/pagespec.mdwn b/doc/ikiwiki/pagespec.mdwn
index 5f0f44e2e..8d8b1a507 100644
--- a/doc/ikiwiki/pagespec.mdwn
+++ b/doc/ikiwiki/pagespec.mdwn
@@ -44,7 +44,8 @@ Some more elaborate limits can be added to what matches using these functions:
metadata, matching the specified glob.
* "`user(username)`" - tests whether a modification is being made by a
user with the specified username. If openid is enabled, an openid can also
- be put here.
+ be put here. Glob patterns can be used in the username. For example,
+ to match all openid users, use `user(*://.*)`
* "`admin()`" - tests whether a modification is being made by one of the
wiki admins.
* "`ip(address)`" - tests whether a modification is being made from the
diff --git a/t/pagespec_match.t b/t/pagespec_match.t
index b96947407..197ff818b 100755
--- a/t/pagespec_match.t
+++ b/t/pagespec_match.t
@@ -1,7 +1,7 @@
#!/usr/bin/perl
use warnings;
use strict;
-use Test::More tests => 64;
+use Test::More tests => 70;
BEGIN { use_ok("IkiWiki"); }
@@ -40,6 +40,13 @@ ok(! pagespec_match("foo", "foo and bar"), "foo and bar");
ok(pagespec_match("{f}oo", "{*}*"), "curly match");
ok(! pagespec_match("foo", "{*}*"), "curly !match");
+ok(pagespec_match("somepage", "user(frodo)", user => "frodo"));
+ok(pagespec_match("somepage", "user(frodo)", user => "Frodo"));
+ok(! pagespec_match("somepage", "user(frodo)", user => "Sam"));
+ok(pagespec_match("somepage", "user(*o)", user => "Bilbo"));
+ok(pagespec_match("somepage", "user(*o)", user => "frodo"));
+ok(! pagespec_match("somepage", "user(*o)", user => "Sam"));
+
# The link and backlink stuff needs this.
$config{userdir}="";
$links{foo}=[qw{bar baz}];