Allow globs to be used in user() pagespecs.
authorJoey Hess <joey@gnu.kitenet.net>
Fri, 12 Feb 2010 01:39:10 +0000 (20:39 -0500)
committerJoey Hess <joey@gnu.kitenet.net>
Fri, 12 Feb 2010 01:39:10 +0000 (20:39 -0500)
IkiWiki.pm
debian/changelog
doc/ikiwiki/pagespec.mdwn
t/pagespec_match.t

index de7dbfc79fbd7de8043265740a345c8f7f66ecf7..a96ff1236dc4849f591725f2b31db235ff91907a 100644 (file)
@@ -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}) {
index 14be7ec69b6ce1e99b653ffbc1653200635923ea..d74abd0f98996c436d202bd46eca3446e51de2c1 100644 (file)
@@ -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
 
index 5f0f44e2ebe6cf847bfe2b6c8b73d8e62ad4969b..8d8b1a507a0c65234b1cb881dd884a07d380a932 100644 (file)
@@ -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
index b96947407b44838a39ade2dd89cd90b6788bd3f3..197ff818b88db414d85446c81f25f44e6b72efd5 100755 (executable)
@@ -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}];