コード例 #1
0
	function qpuserchoice( Parser &$parser, PPFrame $frame, array $args ) {
		qp_Setup::onLoadAllMessages();
		$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>';
	}
コード例 #2
0
	/**
	 * Constructor
	 *
	 * @public
	 */
	function __construct( array $argv, qp_AbstractPollView $view ) {
		global $wgLanguageCode;
		$this->mResponse = qp_Setup::$request->response();
		# Determine which messages will be used, according to the language.
		qp_Setup::onLoadAllMessages();
		$view->setController( $this );
		# *** get visual style poll attributes ***
		$perRow = intval( array_key_exists( 'perrow', $argv ) ? $argv['perrow'] : 1 );
		if ( $perRow < 1 ) {
			$perRow = 1;
		}
		$view->setPerRow( $perRow );
		$this->view = $view;
		# reset the unique index number of the question in the current poll (used to instantiate the questions)
		$this->mQuestionId = 0; // ( corresponds to 'question_id' DB field )
		$this->username = qp_Setup::getCurrUserName();
		# setup poll view showresults
		if ( array_key_exists( 'showresults', $argv ) && qp_Setup::$global_showresults != 0 ) {
			if ( $argv['showresults'] == 'showresults' ) {
				# default showresults for the empty value of xml attribute
				$argv['showresults'] = '1';
			}
			$this->view->showResults = self::parseShowResults( $argv['showresults'] );
		}
		# get default question attributes, if any
		foreach ( $this->defaultQuestionAttributes as $attr => &$val ) {
			if ( array_key_exists( $attr, $argv ) ) {
				$val = $argv[$attr];
			}
		}
		# every poll on the page should have unique poll id, to minimize the risk of collisions
		# it is required to be set manually via id="value" parameter
		# ( used only in "declaration" mode )
		$this->mPollId = array_key_exists( 'id', $argv ) ? trim( $argv['id'] ) : null;
	}