Ajout : supporte id= comme expression rationnelle.
[ikiwiki/poll.git] / poll.pm
diff --git a/poll.pm b/poll.pm
index b79fd0e..411f3bd 100644 (file)
--- a/poll.pm
+++ b/poll.pm
@@ -187,6 +187,7 @@ sub sessioncgi ($$) {
                        use Data::Dumper;
                        error("bad page name");
                 }
+               &IkiWiki::check_canedit($page, $cgi, $session);
                
                # Did they vote before? If so, let them change their vote,
                # and check for dups.
@@ -261,19 +262,19 @@ sub sessioncgi ($$) {
                 s{
                        (?<escape>\\?)
                        \[\[\Q$prefix\E
-                               (?:\s+id="(?<id>[^"]*)")?
-                               (?<space_begin>\s+)
+                               (?:(?<id_space>\s+)id="(?<id>[^"]*)")?
+                               (?<params_space>\s+)
                                (?<params>$params_re)
-                               (?<space_end>\s*)
+                               (?<end_space>\s*)
                        \]\]
                        }
                 {$id=$+{id};
                        $+{escape}
                        .'[['.$prefix
-                               .($+{id} eq ''?'':'id="'.$+{id}.'"')
-                               .$+{space_begin}
+                               .($+{id} eq ''?'':$+{id_space}.'id="'.$+{id}.'"')
+                               .$+{params_space}
                                .$edit->($+{escape}, $+{params})
-                               .$+{space_end}
+                               .$+{end_space}
                        .']]'
                 }egsx;
                
@@ -318,9 +319,13 @@ package IkiWiki::PageSpec;
                my ($page, $match, %params) = @_;
                my $polls = $IkiWiki::pagestate{$page}{poll};
                if (defined $polls and %$polls) {
-                       my ($match_poll, $match_user, $match_choice) = $match =~ m/^id=(.*?) user=(.*?) choice=(.*?)$/;
-                       if (exists $polls->{$match_poll}) {
-                               my %poll = %{$polls->{$match_poll}};
+                       my ($match_id, $match_user, $match_choice) = $match =~ m/^id=(.*?) user=(.*?) choice=(.*?)$/;
+                       my $match_id_re = IkiWiki::glob2re($match_id?$match_id:'*');
+                       my @polls = grep {$_ =~ $match_id_re} (keys %$polls);
+                       return IkiWiki::FailReason->new("no poll match id=`$match_id'", $page => $IkiWiki::DEPEND_CONTENT)
+                               unless @polls > 0;
+                       foreach my $poll (@polls) {
+                               my %poll = %{$polls->{$poll}};
                                my $match_user_re   = IkiWiki::glob2re($match_user?$match_user:'*');
                                my $match_choice_re = IkiWiki::glob2re($match_choice?$match_choice:'*');
                                while (my ($choice, $data) = each %poll) {
@@ -340,11 +345,8 @@ package IkiWiki::PageSpec;
                                                 }
                                         }
                                 }
-                               return IkiWiki::FailReason->new("no user=`$match_user' has voted for choice=`$match_choice'", $page => $IkiWiki::DEPEND_CONTENT);
-                        }
-                       else {
-                               return IkiWiki::FailReason->new("no poll id=`$match_poll'", $page => $IkiWiki::DEPEND_CONTENT);
                         }
+                       return IkiWiki::FailReason->new("no user=`$match_user' has voted for choice=`$match_choice'", $page => $IkiWiki::DEPEND_CONTENT);
                 }
                else {
                        return IkiWiki::FailReason->new("no poll", $page => $IkiWiki::DEPEND_CONTENT);