Example #1
0
 /**
  * Show interpetation script source with line numbering (for debugging convenience)
  *
  * @param  $input				Text between <qpinterpret> and </qpinterper> tags, subset of PHP syntax.
  * @param  $argv				An array containing any arguments passed to the extension
  * @param  &$parser			The wikitext parser.
  * @param  &$frame			PPFrame object passed in MW 1.16+
  * @return 						script source with line numbering
  */
 static function showScript($input, $argv, $parser, $frame = false)
 {
     $lines_count = count(preg_split('`(\\r\\n|\\n|\\r)`', $input, -1));
     $line_numbers = '';
     if (!isset($argv['lang'])) {
         return '<strong class="error">' . wfMsg('qp_error_eval_missed_lang_attr') . '</strong>';
     }
     $lang = $argv['lang'];
     if (!array_key_exists($lang, self::$scriptLinesCount)) {
         self::$scriptLinesCount[$lang] = 1;
     }
     $slc =& self::$scriptLinesCount[$lang];
     for ($i = $slc; $i < $slc + $lines_count; $i++) {
         $line_numbers .= "{$i}\n";
     }
     $slc = $i;
     $out = array('__tag' => 'div', 'class' => 'qpoll', 0 => array());
     if (is_string($lintResult = qp_Interpret::lint($lang, $input))) {
         $out[0][] = array('__tag' => 'div', 'class' => 'interp_error', qp_Setup::specialchars($lintResult));
     }
     $out[0][] = array('__tag' => 'div', 'class' => 'line_numbers', $line_numbers);
     $out[0][] = array('__tag' => 'div', 'class' => 'script_view', qp_Setup::specialchars($input) . "\n");
     $markercount = count(self::$markerList);
     $marker = "!qpoll-script-view{$markercount}-qpoll!";
     self::$markerList[$markercount] = qp_Renderer::renderTagArray($out);
     return $marker;
 }
	/**
	 * Prepares an array of user answer to the current poll and interprets these.
	 * Stores the result in $this->interpResult
	 */
	private function interpretVote() {
		$this->interpResult = new qp_InterpResult();
		$interpTitle = $this->getInterpTitle();
		if ( $interpTitle === false ) {
			# this poll has no interpretation script
			return;
		}
		if ( !( $interpTitle instanceof Title ) || !$interpTitle->exists() ) {
			$this->interpResult->storeErroneous = false;
			$this->interpResult->setError( wfMsg( 'qp_error_no_interpretation' ) );
			return;
		}
		$interpArticle = new Article( $interpTitle, 0 );

		# prepare array of user answers that will be passed to the interpreter
		$poll_answer = array();

		foreach ( $this->Questions as $qdata ) {
			if ( !$this->isUsedQuestion( $qdata->question_id ) ) {
				continue;
			}
			$questions = array();
			foreach ( $qdata->ProposalText as $propkey => &$proposal_text ) {
				$proposals = array();
				foreach ( $qdata->Categories as $catkey => &$cat_name ) {
					$text_answer = '';
					if ( array_key_exists( $propkey, $qdata->ProposalCategoryId ) &&
								( $id_key = array_search( $catkey, $qdata->ProposalCategoryId[ $propkey ] ) ) !== false ) {
						$proposals[$catkey] = $qdata->ProposalCategoryText[ $propkey ][ $id_key ];
					}
				}
				if ( isset( $qdata->ProposalNames[$propkey] ) ) {
					$questions[$qdata->ProposalNames[$propkey]] = $proposals;
				} else {
					$questions[$propkey] = $proposals;
				}
			}
			if ( $qdata->name !== null ) {
				$poll_answer[$qdata->name] = $questions;
			} else {
				$poll_answer[$qdata->question_id] = $questions;
			}
		}

		# interpret the poll answer to get interpretation answer
		$this->interpResult = qp_Interpret::getResult( $interpArticle, array( 'answer' => $poll_answer, 'randomQuestions' => $this->randomQuestions ) );
	}