예제 #1
0
 /**
  * @static
  * @param $body
  * @param $page
  * @param $user
  * @param string $metaTitle
  * @param bool|WallMessage $parent
  * @param array $relatedTopics
  * @param bool $notify
  * @param bool $notifyEveryone
  * @return WallMessage|Bool
  */
 public static function buildNewMessageAndPost($body, $page, $user, $metaTitle = '', $parent = false, $relatedTopics = array(), $notify = true, $notifyEveryone = false)
 {
     wfProfileIn(__METHOD__);
     if ($page instanceof Title) {
         $userPageTitle = $page;
     } else {
         $userPageTitle = Title::newFromText($page, NS_USER_WALL);
     }
     // if message wall was just created, we should later use MASTER db when creating title object
     $useMasterDB = false;
     // create wall page by bot if not exist
     if ($userPageTitle instanceof Title && !$userPageTitle->exists()) {
         $userPageTitle = self::addMessageWall($userPageTitle);
         $useMasterDB = true;
     }
     if (empty($userPageTitle)) {
         Wikia::log(__METHOD__, '', '$userPageTitle not an instance of Title');
         Wikia::logBacktrace(__METHOD__);
         wfProfileOut(__METHOD__);
         return false;
     }
     if ($parent === false) {
         $metaData = array('title' => $metaTitle);
         if ($notifyEveryone) {
             $metaData['notify_everyone'] = time();
         }
         if (!empty($relatedTopics)) {
             $metaData['related_topics'] = implode('|', $relatedTopics);
         }
         $acStatus = ArticleComment::doPost($body, $user, $userPageTitle, false, $metaData);
     } else {
         if (!$parent->canReply()) {
             wfProfileOut(__METHOD__);
             return false;
         }
         $acStatus = ArticleComment::doPost($body, $user, $userPageTitle, $parent->getId(), null);
     }
     if ($acStatus === false) {
         wfProfileOut(__METHOD__);
         return false;
     }
     $ac = ArticleComment::newFromId($acStatus[1]->getId());
     if (empty($ac)) {
         wfProfileOut(__METHOD__);
         return false;
     }
     // after successful posting invalidate Wall cache
     /**
      * @var $class WallMessage
      */
     $class = new WallMessage($ac->getTitle(), $ac);
     if ($parent === false) {
         // $db = DB_SLAVE
         $class->storeRelatedTopicsInDB($relatedTopics);
         $class->setOrderId(1);
         $class->getWall()->invalidateCache();
     } else {
         $count = $parent->getOrderId(true);
         // this is not work perfect with transations
         if (is_numeric($count)) {
             $count++;
             $parent->setOrderId($count);
             $class->setOrderId($count);
         }
         // after successful posting invalidate Thread cache
         $class->getThread()->invalidateCache();
         $rp = new WallRelatedPages();
         $rp->setLastUpdate($parent->getId());
     }
     // Build data for sweet url ? id#number_of_comment
     // notify
     if ($notify) {
         $class->sendNotificationAboutLastRev($useMasterDB);
     }
     if ($parent === false && $notifyEveryone) {
         $class->notifyEveryone();
     }
     $class->addWatch($user);
     wfRunHooks('AfterBuildNewMessageAndPost', array(&$class));
     wfProfileOut(__METHOD__);
     return $class;
 }