private function getFormatedHistoryData($history, $threadId = 0)
 {
     // VOLDEV-39: Store whether Wall is enabled
     $ns = $this->wg->EnableWallExt ? NS_USER_WALL : NS_USER_TALK;
     foreach ($history as $key => $value) {
         $type = intval($value['action']);
         if (!$this->isThreadLevel && !in_array($type, array(WH_NEW, WH_REMOVE, WH_RESTORE, WH_DELETE))) {
             unset($history[$key]);
             continue;
         }
         $title = $value['title'];
         $wm = new WallMessage($title);
         $user = $value['user'];
         $username = $user->getName();
         $userTalk = Title::newFromText($username, $ns);
         $url = $userTalk->getFullUrl();
         if ($user->isAnon()) {
             $history[$key]['displayname'] = Linker::linkKnown($userTalk, wfMessage('oasis-anon-user')->escaped());
             $history[$key]['displayname'] .= ' ' . Linker::linkKnown($userTalk, Html::element('small', array(), $username), array('class' => 'username'));
         } else {
             $history[$key]['displayname'] = Linker::linkKnown($userTalk, $username);
         }
         $history[$key]['authorurl'] = $url;
         $history[$key]['username'] = $user->getName();
         $history[$key]['userpage'] = $url;
         $history[$key]['type'] = $type;
         $history[$key]['usertimeago'] = $this->getContext()->getLanguage()->timeanddate($value['event_mw']);
         $history[$key]['reason'] = $value['reason'];
         $history[$key]['actions'] = array();
         if ($this->isThreadLevel) {
             $history[$key]['isreply'] = $isReply = $value['is_reply'];
             $history[$key]['prefix'] = $isReply === '1' ? 'reply-' : 'thread-';
             if (intval($value['page_id']) === $threadId) {
                 // if the entry is about change in top message
                 // hardcode the order number to 1
                 $history[$key]['msgid'] = 1;
             } else {
                 $history[$key]['msgid'] = $wm->getOrderId();
             }
             $wm->load();
             $messagePageUrl = $wm->getMessagePageUrl();
             $history[$key]['msgurl'] = $messagePageUrl;
             $msgUser = $wm->getUser();
             $msgPage = Title::newFromText($msgUser->getName(), $ns);
             if (empty($msgPage)) {
                 // SOC-586, SOC-578 : There is an edge case where $msgUser->getName can be empty
                 // because of a rev_deleted flag on the revision loaded by ArticleComment via the
                 // WallMessage $wm->load() above.  ArticleComment overwrites the User objects mName
                 // usertext with the first revision's usertext to preserve the thread author but in
                 // rare occasions this revision can have its user hidden via a DELETED_USER flag.
                 $history[$key]['msguserurl'] = '';
                 $history[$key]['msgusername'] = '';
             } else {
                 $history[$key]['msguserurl'] = $msgPage->getFullUrl();
                 $history[$key]['msgusername'] = $msgUser->getName();
             }
             if ($type == WH_EDIT) {
                 $rev = Revision::newFromTitle($title);
                 // mech: fixing 20617 - revision_id is available only for new entries
                 $query = array('diff' => 'prev', 'oldid' => $history[$key]['revision_id'] ? $history[$key]['revision_id'] : $title->getLatestRevID());
                 $history[$key]['actions'][] = array('href' => $rev->getTitle()->getLocalUrl($query), 'msg' => wfMessage('diff')->text());
             }
         } else {
             $msgUrl = $wm->getMessagePageUrl(true);
             $history[$key]['msgurl'] = $msgUrl;
             $history[$key]['historyLink'] = Xml::element('a', array('href' => $msgUrl . '?action=history'), wfMessage('wall-history-action-thread-history')->text());
         }
         if ($type == WH_REMOVE && !$wm->isAdminDelete() || $type == WH_DELETE && $wm->isAdminDelete()) {
             if ($wm->canRestore($this->getContext()->getUser())) {
                 if ($this->isThreadLevel) {
                     $restoreActionMsg = $isReply === '1' ? wfMessage('wall-history-action-restore-reply')->text() : wfMessage('wall-history-action-restore-thread')->text();
                 } else {
                     $restoreActionMsg = wfMessage('wall-history-action-restore')->text();
                 }
                 $history[$key]['actions'][] = array('class' => 'message-restore', 'data-id' => $value['page_id'], 'data-mode' => 'restore' . ($wm->canFastrestore($this->getContext()->getUser()) ? '-fast' : ''), 'href' => '#', 'msg' => $restoreActionMsg);
             }
         }
         $userid = $user->getId();
         if ($user->isAnon()) {
             WallRailController::addAnon($userid, $user);
         } else {
             WallRailController::addUser($userid, $user);
         }
     }
     return $history;
 }
示例#2
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 = F::build('Title', array($page, NS_USER_WALL), 'newFromText');
     }
     // create wall page by bot if not exist
     if (!$userPageTitle->exists()) {
         $userPageTitle = self::addMessageWall($userPageTitle);
     }
     if (empty($userPageTitle)) {
         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 = F::build('ArticleComment', array($body, $user, $userPageTitle, false, $metaData), 'doPost');
     } else {
         if (!$parent->canReply()) {
             wfProfileOut(__METHOD__);
             return false;
         }
         $acStatus = F::build('ArticleComment', array($body, $user, $userPageTitle, $parent->getTitle()->getArticleId(), null), 'doPost');
     }
     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 = F::build('WallMessage', array($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();
     }
     //Build data for sweet url ? id#number_of_comment
     //notify
     if ($notify) {
         $class->sendNotificationAboutLastRev();
     }
     if ($parent === false && $notifyEveryone) {
         $class->notifyEveryone();
     }
     $class->addWatch($user);
     wfRunHooks('AfterBuildNewMessageAndPost', array(&$class));
     wfProfileOut(__METHOD__);
     return $class;
 }