/**
  * @brief Hook to change tabs on user wall page
  *
  * @param $template
  * @param $contentActions
  * @return bool
  *
  * @author Andrzej 'nAndy' Łukaszewski
  */
 public static function onSkinTemplateTabs($template, &$contentActions)
 {
     $app = F::App();
     if (!empty($app->wg->EnableWallExt)) {
         $helper = new WallHelper();
         $title = $app->wg->Title;
         if ($title->getNamespace() === NS_USER) {
             if (!empty($contentActions['namespaces']) && !empty($contentActions['namespaces']['user_talk'])) {
                 $contentActions['namespaces']['user_talk']['text'] = wfMessage('wall-message-wall')->text();
                 $userWallTitle = static::getWallTitle();
                 if ($userWallTitle instanceof Title) {
                     $contentActions['namespaces']['user_talk']['href'] = $userWallTitle->getLocalUrl();
                 }
                 // BugId:23000 Remove the class="new" to prevent the link from being displayed as a redlink in monobook.
                 if ($app->wg->User->getSkin() instanceof SkinMonoBook) {
                     unset($contentActions['namespaces']['user_talk']['class']);
                 }
             }
         }
         if ($title->getNamespace() === NS_USER_WALL || $title->getNamespace() === NS_USER_WALL_MESSAGE) {
             if ($title->getNamespace() === NS_USER_WALL_MESSAGE) {
                 $text = $title->getText();
                 $id = intval($text);
                 if ($id > 0) {
                     $wm = WallMessage::newFromId($id);
                 } else {
                     // sometimes (I found it on a revision diff page) $id here isn't a number from (in example) Thread:1234 link
                     // it's a text similar to this: AndLuk/@comment-38.127.199.123-20120111182821
                     // then we need to use WallMessage constructor method
                     $wm = new WallMessage($title);
                 }
                 if (empty($wm)) {
                     // FB#19394
                     return true;
                 }
                 /* @var $wm WallMessage */
                 $wall = $wm->getWall();
                 $user = $wall->getUser();
             } else {
                 $wall = Wall::newFromTitle($title);
                 $user = $wall->getUser();
             }
             $contentActions['namespaces'] = array();
             if ($user instanceof User) {
                 $contentActions['namespaces']['user-profile'] = array('class' => false, 'href' => $user->getUserPage()->getFullUrl(), 'text' => wfMessage('nstab-user')->text());
             }
             $contentActions['namespaces']['message-wall'] = array('class' => 'selected', 'href' => $wall->getUrl(), 'text' => wfMessage('wall-message-wall')->text());
         }
         if ($title->getNamespace() === NS_USER_WALL && $title->isSubpage()) {
             $userTalkPageTitle = $helper->getTitle(NS_USER_TALK);
             $contentActions = array();
             $contentActions['namespaces'] = array();
             $contentActions['namespaces']['view-source'] = array('class' => false, 'href' => $userTalkPageTitle->getLocalUrl(array('action' => 'edit')), 'text' => wfMessage('user-action-menu-view-source')->text());
             $contentActions['namespaces']['history'] = array('class' => false, 'href' => $userTalkPageTitle->getLocalUrl(array('action' => 'history')), 'text' => wfMessage('user-action-menu-history')->text());
         }
     }
     return true;
 }
示例#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 = 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;
 }