";
// If the amount of votes is not set, set it to 0
// This fixes an odd bug where "votes" would be shown
diff --git a/includes/PollPage.class.php b/includes/PollPage.class.php
index da1b4c1..8f41a5b 100644
--- a/includes/PollPage.class.php
+++ b/includes/PollPage.class.php
@@ -37,6 +37,30 @@ class PollPage extends Article {
$out->setHTMLTitle( $title->getText() );
$out->setPageTitle( $title->getText() );
+ $p = new Poll();
+
+ // NoJS POST handler for no-JS votes
+ // JS equivalent is calling ApiPollNY.php with what=vote and other appropriate params
+ $pollID = $request->getInt( 'poll_id' );
+ $choiceID = $request->getInt( 'poll_choice' );
+ if (
+ $user->isAllowed( 'pollny-vote' ) &&
+ $request->wasPosted() &&
+ $user->matchEditToken( $request->getVal( 'wpEditToken' ) ) &&
+ !$p->userVoted( $user, $pollID )
+ ) {
+ $p->addPollVote( $pollID, $choiceID, $user );
+ // Maybe redirect to a random, different poll after voting (just as the JS version does)
+ $randomURL = $p->getRandomPollURL( $user );
+ if ( $randomURL !== 'error' ) {
+ $out->redirect( Title::newFromText( $randomURL )->getFullURL( [
+ 'prev_id' => $this->getID()
+ ] ) );
+ }
+ $show_results = true;
+ // @todo FIXME: display a CTA of some kind in case of 'error', like in the JS function goToNewPoll()
+ }
+
$createPollObj = SpecialPage::getTitleFor( 'CreatePoll' );
// Get total polls count so we can tell the user how many they have
@@ -56,7 +80,6 @@ class PollPage extends Article {
$stats = new UserStats( $user->getId(), $user->getName() );
$stats_current_user = $stats->getUserStats();
- $p = new Poll();
$poll_info = $p->getPoll( $title->getArticleID() );
if ( !isset( $poll_info['id'] ) ) {
@@ -205,15 +228,18 @@ class PollPage extends Article {
) {
$output .= '