/** * @param WebRequest $request * * @return string */ function loadDataFromRequest($request) { if ($this->mParent->getMethod() == 'post') { if ($request->wasPosted()) { # Checkboxes are just not added to the request arrays if they're not checked, # so it's perfectly possible for there not to be an entry at all return $request->getArray($this->mName, array()); } else { # That's ok, the user has not yet submitted the form, so show the defaults return $this->getDefault(); } } else { # This is the impossible case: if we look at $_GET and see no data for our # field, is it because the user has not yet submitted the form, or that they # have submitted it with all the options unchecked? We will have to assume the # latter, which basically means that you can't specify 'positive' defaults # for GET forms. # @todo FIXME... return $request->getArray($this->mName, array()); } }
private static function parseCreateEditQuizArticleRequest(WebRequest $request, WikiaQuizElement $quizElement, &$error) { if (!empty($quizElement)) { $title = $quizElement->getTitle(); $quiz = $quizElement->getQuizTitle(); $order = $quizElement->getOrder(); } else { $order = ''; $title = trim($request->getVal('question')); $quiz = trim($request->getVal('quiz')); } $image = trim($request->getVal('image')); $explanation = trim($request->getVal('explanation')); $video = trim($request->getVal('video')); $answers = $request->getArray('answer'); // array $correctAnswer = trim($request->getVal('correct')); $answerImages = $request->getArray('answer-image'); // array $content = ""; $content .= WikiaQuizElement::TITLE_MARKER . $title . "\n"; if ($image) { if (!self::isValidImage($image)) { $error = wfMsg('wikiaquiz-error-invalid-image', $image); return; } $content .= WikiaQuizElement::IMAGE_MARKER . $image . "\n"; } if ($video) { if (!self::isValidVideo($video)) { $error = wfMsg('wikiaquiz-error-invalid-video', $video); return; } $content .= WikiaQuizElement::VIDEO_MARKER . $video . "\n"; } if ($explanation) { $content .= WikiaQuizElement::EXPLANATION_MARKER . $explanation . "\n"; } if ($quiz) { $content .= self::getCategoryText($quiz, $order); } else { $error = wfMsg('wikiaquiz-error-invalid-quiz'); return; } $answerExists = false; $correctAnswerExists = false; foreach ($answers as $index => $answer) { $answer = trim($answer); if ($answer) { $answerExists = true; $correctAnswerContent = ""; if ($index == $correctAnswer) { if ($correctAnswerExists) { $error = wfMsg('wikiaquiz-error-invalid-correct-answer'); return; } else { $correctAnswerExists = true; } $correctAnswerContent .= WikiaQuizElement::CORRECT_ANSWER_MARKER . ' '; } $answerImageContent = ""; $answerImage = trim($answerImages[$index]); if ($answerImage) { if (!self::isValidImage($answerImage)) { $error = wfMsg('wikiaquiz-error-invalid-image', $answerImage); return; } $answerImageContent .= WikiaQuizElement::ANSWER_IMAGE_MARKER . $answerImages[$index]; } $content .= WikiaQuizElement::ANSWER_MARKER . "{$correctAnswerContent}{$answer}{$answerImageContent}\n"; } } if (!$answerExists) { $error = wfMsg('wikiaquiz-error-missing-answers'); return; } if (!$correctAnswerExists) { $error = wfMsg('wikiaquiz-error-invalid-correct-answer'); return; } return $content; }
/** * Generates form elements for a (web)requested format. * * Required by getFormatSelectBox() to recieve form elements from the * Web. UIs may need to overload processFormatOptions(), * processFormatSelectBox() and getFormatSelectBox() to change behavior. * * @param WebRequest $wgRequest * @return boolean true if format options were requested and returned, else false */ protected function processFormatOptions($wgRequest) { global $wgOut; if ($wgRequest->getCheck('showformatoptions')) { // handle Ajax action $format = $wgRequest->getVal('showformatoptions'); $params = $wgRequest->getArray('params'); $wgOut->disable(); echo $this->showFormatOptions($format, $params); return true; } else { return false; } }