Exemplo n.º 1
0
 /**
  * Update the contents of an existing quizElement
  * @param wgRequest quizElementId
  */
 public static function updateQuizArticle()
 {
     wfProfileIn(__METHOD__);
     $wgRequest = F::app()->getGlobal('wgRequest');
     $wgUser = F::app()->getGlobal('wgUser');
     $res = array();
     $quizElementId = $wgRequest->getInt('quizElementId');
     $quizElement = WikiaQuizElement::newFromId($quizElementId);
     //		$newTitle = $wgRequest->getVal ('question');
     //		$newTitleObject = Title::newFromText($newTitle, NS_WIKIA_QUIZARTICLE);
     //		if (is_object($newTitleObject)) {
     //			$newArticle = new Article($newTitleObject);
     //		}
     // validation
     //		if (is_object ($newTitleObject) && $newTitleObject->exists()
     //		&& $newArticle->getID() != $quizElementId) {
     //			$res = array (
     //				'success' => false,
     //				'error' => F::app()->renderView('Error', 'Index', array(wfMsg('wikiaquiz-error-duplicate-question')))
     //				);
     //		} else if ($newTitleObject == null) {
     //			$res = array (
     //				'success' => false,
     //				'error' => F::app()->renderView('Error', 'Index', array(wfMsg('wikiaquiz-error-invalid-question')))
     //				);
     //		} else {
     //
     //		}
     if (empty($quizElement) || !$quizElement->exists()) {
         $res = array('success' => false, 'error' => F::app()->renderView('Error', 'Index', array(wfMsg('wikiaquiz-error-invalid-article'))));
     } else {
         $error = null;
         $content = self::parseCreateEditQuizArticleRequest($wgRequest, $quizElement, $error);
         if ($error) {
             $res = array('success' => false, 'error' => F::app()->renderView('Error', 'Index', array($error)));
         } else {
             $article = Article::newFromID($quizElementId);
             $status = $article->doEdit($content, 'Quiz Question and Answers Updated', EDIT_UPDATE, false, $wgUser);
             $title_object = $article->getTitle();
             // @todo check status object
             $res = array('success' => true, 'quizElementId' => $article->getID(), 'url' => $title_object->getLocalUrl(), 'question' => $title_object->getPrefixedText());
         }
     }
     wfProfileOut(__METHOD__);
     return $res;
 }
Exemplo n.º 2
0
 /**
  * Load quiz data (try to use cache layer)
  */
 private function load($master = false)
 {
     global $wgMemc;
     wfProfileIn(__METHOD__);
     if (!$master) {
         $this->mData = $wgMemc->get($this->mMemcacheKey);
     }
     if (empty($this->mData)) {
         $article = Article::newFromID($this->mQuizId);
         // check quiz existence
         if (empty($article)) {
             wfDebug(__METHOD__ . ": quiz doesn't exist\n");
             wfProfileOut(__METHOD__);
             return;
         }
         // get quiz's author and creation timestamp
         $title = $article->getTitle();
         $firstRev = $title->getFirstRevision();
         $titleText = $title->getText();
         $titleScreenText = '';
         $fbRecommendationText = '';
         $images = array();
         $imageShorts = array();
         $moreInfoHeading = '';
         $moreInfoLinks = array();
         // parse wikitext containing quiz data
         $content = $article->getContent();
         $lines = explode("\n", $content);
         foreach ($lines as $line) {
             if (startsWith($line, self::TITLESCREENTEXT_MARKER)) {
                 $titleScreenText = trim(substr($line, strlen(self::TITLESCREENTEXT_MARKER)));
             } elseif (startsWith($line, self::FBRECOMMENDATIONTEXT_MARKER)) {
                 $fbRecommendationText = trim(substr($line, strlen(self::FBRECOMMENDATIONTEXT_MARKER)));
             } elseif (startsWith($line, self::IMAGE_MARKER)) {
                 $imageShort = trim(substr($line, strlen(self::IMAGE_MARKER)));
                 $images[] = $this->getImageSrc($imageShort);
                 $imageShorts[] = $imageShort;
             } elseif (startsWith($line, self::MOREINFOHEADING_MARKER)) {
                 $moreInfoHeading = trim(substr($line, strlen(self::MOREINFOHEADING_MARKER)));
             } elseif (startsWith($line, self::MOREINFOLINK_MARKER)) {
                 $moreInfo = substr($line, strlen(self::MOREINFOLINK_MARKER));
                 $moreInfoChunks = explode(self::MOREINFOLINK_TEXT_MARKER, $moreInfo);
                 if (Http::isValidURI($moreInfoChunks[0])) {
                     $moreInfoUrl = $moreInfoChunks[0];
                 } else {
                     $title = Title::newFromText($moreInfoChunks[0]);
                     $moreInfoUrl = $title->getFullUrl();
                 }
                 $moreInfoLinks[] = array('article' => $moreInfoChunks[0], 'url' => $moreInfoUrl, 'text' => isset($moreInfoChunks[1]) ? $moreInfoChunks[1] : '');
             } elseif (startsWith($line, self::REQUIRE_EMAIL_MARKER)) {
                 $line = substr($line, strlen(self::REQUIRE_EMAIL_MARKER));
                 $requireEmail = $line == 'true';
             }
         }
         // load quiz's elements
         if (empty($this->mCategory)) {
             $catName = self::QUIZ_CATEGORY_PREFIX . $titleText;
             $cat = Category::newFromName($catName);
             $this->mCategory = $cat;
         }
         $quizElements = array();
         if (empty($this->mCategory) || !$this->mCategory->getID()) {
             wfDebug(__METHOD__ . ": quiz's category doesn't exist\n");
         } else {
             // get quiz elements
             $quizIterator = $this->mCategory->getMembers();
             while ($quizElementTitle = $quizIterator->current()) {
                 $quizElement = WikiaQuizElement::newFromId($quizElementTitle->getArticleId());
                 $quizElements[] = $quizElement->getData();
                 $quizIterator->next();
             }
         }
         $this->mData = array('id' => $this->mQuizId, 'name' => $titleText, 'requireEmail' => !empty($requireEmail), 'elements' => $quizElements, 'titlescreentext' => $titleScreenText, 'fbrecommendationtext' => $fbRecommendationText, 'images' => $images, 'imageShorts' => $imageShorts, 'moreinfoheading' => $moreInfoHeading, 'moreinfo' => $moreInfoLinks);
         wfDebug(__METHOD__ . ": loaded from scratch\n");
         // store it in memcache
         $wgMemc->set($this->mMemcacheKey, $this->mData, self::CACHE_TTL);
     } else {
         wfDebug(__METHOD__ . ": loaded from memcache\n");
     }
     $this->mExists = true;
     wfProfileOut(__METHOD__);
     return;
 }
 public function executeGetQuizElement()
 {
     $wgRequest = F::app()->getGlobal('wgRequest');
     $elementId = $wgRequest->getVal('elementId');
     if ($elementId) {
         $quizElement = WikiaQuizElement::newFromId($elementId);
         $this->data = $quizElement->getData();
     }
 }