+ }
+ }
+package IkiWiki::PageSpec;
+ sub match_poll ($$;@) {
+ 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_user_re = IkiWiki::glob2re($match_user?$match_user:'*');
+ my $match_choice_re = IkiWiki::glob2re($match_choice?$match_choice:'*');
+ while (my ($choice, $data) = each %poll) {
+ next unless $choice =~ $match_choice_re;
+ if ($match_user eq '') {
+ if ($data->{unknown_votes} > 0) {
+ return IkiWiki::SuccessReason->new("unkown user has voted for choice=`$choice'", $page => $IkiWiki::DEPEND_CONTENT);
+ }
+ else {
+ return IkiWiki::FailReason->new("no unkown user has voted for choice=`$choice'", $page => $IkiWiki::DEPEND_CONTENT);
+ }
+ }
+ else {
+ foreach my $user (@{$data->{known_votes}}) {
+ next unless $user =~ $match_user_re;
+ return IkiWiki::SuccessReason->new("user=`$user' has voted for choice=`$choice'", $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 id=`$match_poll'", $page => $IkiWiki::DEPEND_CONTENT);
+ }
+ }
+ else {
+ return IkiWiki::FailReason->new("no poll", $page => $IkiWiki::DEPEND_CONTENT);
+ }
+ }