Atathced is a patch for three poll bugs:

* When posting a top-level comment to a poll, the poll doesn't appear in 
the "Replying to" field. To reproduce, open a non-attached poll, click 
"post a comment" and look at the "Replying to" area. It'll just say "0".

* http://bugz.mostly-harmless.ca/show_bug.cgi?id=83 -- I don't seem to 
get this bug on my dev site, but I do elsewhere. Basically, posting a 
comment will cause a section_perm check in Elements.pm to fire when it 
shouldn't (poll perms are checked earlier).

* Poll search -- go to search, choose polls, you'll get one result per 
answer for each poll. The postgres patches removed a "GROUP_BY" in the 
search query that prevented that, without replacing it with something 
that works on postgres and doesn't cause this bug. I replaced the 
group_by, because it works. If it doesn't work with postgres, then it's 
up to the postgres code to preserve mysql functionality (IMO).
-------------- next part --------------
Index: lib/Scoop/Polls.pm
===================================================================
RCS file: /cvs/scoop/scoop/lib/Scoop/Polls.pm,v
retrieving revision 1.66
diff -u -r1.66 Polls.pm
--- lib/Scoop/Polls.pm	5 Oct 2003 08:56:31 -0000	1.66
+++ lib/Scoop/Polls.pm	26 Jan 2005 18:48:24 -0000
@@ -71,7 +71,7 @@
 
 	my $polllist = "";
 	my ($rv, $sth) = $S->db_select({
-		DEBUG	=> 0,
+		DEBUG	=> $DEBUG,
 		WHAT	=> 'qid, question',
 		FROM	=> 'pollquestions',
 	});	
@@ -216,7 +216,7 @@
 	# get and store the poll question and # of votes
 	my ($question, $totalvotes, $actual_totalvotes);
 	my ($rv, $sth) = $S->db_select({
-		DEBUG => 0,
+		DEBUG => $DEBUG,
 		FROM  => 'pollquestions',
 		WHAT  => 'question, voters',
 		WHERE => "qid='$qid'",
@@ -233,7 +233,7 @@
 	$S->{UI}->{BLOCKS}->{subtitle} =~ s/<.*?>//g;
 
 	($rv, $sth) = $S->db_select({
-		DEBUG => 0,
+		DEBUG => $DEBUG,
 		FROM  => 'pollanswers',
 		WHAT  => 'aid, answer, votes',
 		WHERE => "qid='$qid'",
Index: lib/Scoop/Search.pm
===================================================================
RCS file: /cvs/scoop/scoop/lib/Scoop/Search.pm,v
retrieving revision 1.71
diff -u -r1.71 Search.pm
--- lib/Scoop/Search.pm	25 Jan 2005 17:15:24 -0000	1.71
+++ lib/Scoop/Search.pm	26 Jan 2005 18:48:25 -0000
@@ -753,6 +753,7 @@
 		$query->{WHAT} = qq|*, $date_format AS ftime|;
 		$query->{FROM} = 'pollquestions,pollanswers';
 		$query->{WHERE} = qq|pollquestions.qid = pollanswers.qid AND ( pollquestions.question LIKE '%$args->{string}%' OR pollanswers.answer LIKE '%$args->{string}%' ) |;
+                $query->{GROUP_BY} = qq|pollquestions.qid|;
 		$query->{ORDER_BY} = 'pollquestions.post_date desc';
 
 	} else {
Index: lib/Scoop/Stories/Elements.pm
===================================================================
RCS file: /cvs/scoop/scoop/lib/Scoop/Stories/Elements.pm,v
retrieving revision 1.117
diff -u -r1.117 Elements.pm
--- lib/Scoop/Stories/Elements.pm	25 Jan 2005 17:15:24 -0000	1.117
+++ lib/Scoop/Stories/Elements.pm	26 Jan 2005 18:48:25 -0000
@@ -25,12 +25,8 @@
 	
 	my $rating_choice = $S->get_comment_option('ratingchoice');
 		
-	unless ($sid eq 'preview') {
+	unless ($sid eq 'preview' || $S->_does_poll_exist($sid)) {
 		$stories = $S->story_data([$sid]);
-#		$stories = $S->getstories(
-#			{-type => 'fullstory',
-#			 -sid => $sid,
-#			 -perm_override => 1});
 		if ($stories) {		 
 			$story = $stories->[0];
 		} else {
@@ -47,7 +43,6 @@
 	my $page;
 	if ( $S->_does_poll_exist($sid) == 1 ) {
 		$page .= $S->display_poll($sid);
-		# warn "displaying poll $sid";
 	} else {
 		# warn "getting story summary for $sid\n";
 		$page .= $S->story_summary($story);
@@ -75,9 +70,9 @@
 
 	my $story_section = $story->{section} || $S->_get_story_section($sid);
 	# check the section permissions
-	if ($S->have_section_perm('deny_read_stories', $story_section)) {
+	if ($S->have_section_perm('deny_read_stories', $story_section) && !$S->_does_poll_exist($sid)) {
 		$page = qq| <b>%%norm_font%%Sorry, you don't have permission to read stories posted to this section.%%norm_font_end%%</b> |;
-	} elsif ($S->have_section_perm('hide_read_stories', $section)) {
+	} elsif ($S->have_section_perm('hide_read_stories', $section) && !$S->_does_poll_exist($sid)) {
 		$page = qq| <b>%%norm_font%%Sorry, I can't seem to find that story.%%norm_font_end%%</b> |;
 	}