示例#1
0
 function qpuserchoice(Parser &$parser, PPFrame $frame, array $args)
 {
     $this->frame = $frame;
     $this->args =& $args;
     if (isset($args[0])) {
         # args[0] is a poll address
         $this->pollAddr = trim($this->frame->expand($this->args[0]));
         $this->pollStore = qp_PollStore::newFromAddr($this->pollAddr);
         if ($this->pollStore instanceof qp_PollStore && $this->pollStore->pid !== null) {
             $this->error_message = 'missing_question_id';
             if (isset($args[1])) {
                 # args[1] is question_id
                 $qdata = $this->getQuestionData(trim($frame->expand($args[1])));
                 if ($qdata instanceof qp_QuestionData) {
                     $this->error_message = 'missing_proposal_id';
                     if (isset($args[2])) {
                         # get poll's proposal choice
                         $this->proposal_id = trim($frame->expand($args[2]));
                         $this->error_message = 'invalid_proposal_id';
                         if (preg_match(qp_Setup::PREG_NON_NEGATIVE_INT4_MATCH, $this->proposal_id)) {
                             $this->defaultProposalText = isset($args[3]) ? trim($frame->expand($args[3])) : '';
                             $this->proposal_id = intval($this->proposal_id);
                             $this->error_message = 'missing_proposal_id';
                             if (array_key_exists($this->proposal_id, $qdata->ProposalText)) {
                                 return $this->qpuserchoiceValidResult($qdata);
                             }
                         }
                     }
                 }
             }
         }
     }
     return '<strong class="error">qpuserchoice: ' . wfMsgHTML('qp_func_' . $this->error_message, qp_Setup::specialchars($this->pollAddr), qp_Setup::specialchars($this->question_id), qp_Setup::specialchars($this->proposal_id)) . '</strong>';
 }
	/**
	 * Prepares qp_PollStore object
	 * @return  boolean  true on success ($this->pollStore has been created successfully)
	 *          string  error message on failure
	 */
	function getPollStore() {
		$this->pollStore = qp_PollStore::newFromAddr( $this->pollAddr );
		if ( !( $this->pollStore instanceof qp_PollStore ) || $this->pollStore->pid === null ) {
			return self::fatalErrorQuote( 'qp_error_no_such_poll', $this->pollAddr );
		}
		if ( !$this->pollStore->loadQuestions() ) {
			$this->mState = "error";
			return self::fatalErrorQuote( 'qp_error_no_stats', $this->pollAddr );
		}
		$this->pollStore->setLastUser( $this->username );
		# do not check the result, because we may show results even if the user hasn't voted
		$this->pollStore->loadUserAlreadyVoted();
		return true;
	}
示例#3
0
/**
 * Returns either scalar or associative array with structured interpretation
 * of the specified poll for the current user
 *
 * @return  scalar/array when success; null when there is no structured interpretation
 */
function qp_getStructuredInterpretation($poll_address)
{
    $pollStore = qp_PollStore::newFromAddr($poll_address);
    if (!$pollStore instanceof qp_PollStore || $pollStore->pid === null) {
        return null;
    }
    $username = qp_Setup::getCurrUserName();
    $pollStore->loadQuestions();
    $pollStore->setLastUser($username);
    if ($pollStore->interpResult->structured === '') {
        return null;
    }
    return unserialize($pollStore->interpResult->structured);
}
示例#4
0
	private function checkDependance( $dependsOn, $nonVotedDepLink = false ) {
		# check the headers for dependance to other polls
		if ( $dependsOn === '' ) {
			return true;
		}
		$depPollStore = qp_PollStore::newFromAddr( $dependsOn );
		if ( $depPollStore instanceof qp_PollStore ) {
			# process recursive dependance
			$depTitle = $depPollStore->getTitle();
			$depPollId = $depPollStore->mPollId;
			$depLink = $this->view->link( $depTitle, $depTitle->getPrefixedText() . ' (' . $depPollStore->mPollId . ')' );
			if ( $depPollStore->pid === null ) {
				return self::fatalErrorNoQuote( 'qp_error_missed_dependance_poll', qp_Setup::specialchars( $this->mPollId ), $depLink, qp_Setup::specialchars( $depPollId ) );
			}
			if ( !$depPollStore->loadQuestions() ) {
				return self::fatalErrorNoQuote( 'qp_error_vote_dependance_poll', $depLink );
			}
			$depPollStore->setLastUser( $this->username );
			if ( $depPollStore->loadUserAlreadyVoted() ) {
				# user already voted in current the poll in chain
				if ( $depPollStore->dependsOn === '' ) {
					if ( $nonVotedDepLink === false ) {
						# there was no non-voted deplinks in the chain at some previous level of recursion
						return true;
					} else {
						# there is an non-voted deplink in the chain at some previous level of recursion
						return self::fatalErrorNoQuote( 'qp_error_vote_dependance_poll', $nonVotedDepLink );
					}
				} else {
					return $this->checkDependance( $depPollStore->dependsOn, $nonVotedDepLink );
				}
			} else {
				# user hasn't voted in current the poll in chain
				if ( $depPollStore->dependsOn === '' ) {
					# current element of chain is not voted and furthermore, doesn't depend on any other polls
					return self::fatalErrorNoQuote( 'qp_error_vote_dependance_poll', $depLink );
				} else {
					# current element of chain is not voted, BUT it has it's own dependance
					# so we will check for the most deeply nested poll which hasn't voted, yet
					return $this->checkDependance( $depPollStore->dependsOn, $depLink );
				}
			}
		} else {
			# process poll address errors
			switch ( $depPollStore ) {
			case qp_Setup::ERROR_INVALID_ADDRESS :
				return self::fatalErrorQuote( 'qp_error_invalid_dependance_value', $this->mPollId, $dependsOn );
			case qp_Setup::ERROR_MISSED_TITLE :
				$depSplit = self::getPrefixedPollAddress( $dependsOn );
				if ( is_array( $depSplit ) ) {
					list( $depTitleStr, $depPollId ) = $depSplit;
					$depTitle = Title::newFromURL( $depTitleStr );
					$depTitleStr = $depTitle->getPrefixedText();
					$depLink = $this->view->link( $depTitle, $depTitleStr );
					return self::fatalErrorNoQuote( 'qp_error_missed_dependance_title', qp_Setup::specialchars( $this->mPollId ), $depLink, qp_Setup::specialchars( $depPollId ) );
				} else {
					return self::fatalErrorQuote( 'qp_error_invalid_dependance_value', $this->mPollId, $dependsOn );
				}
			default :
				throw new MWException( __METHOD__ . ' invalid dependance poll store found' );
			}
		}
	}