示例#1
0
 public static function newFromId($id, $master = false)
 {
     wfProfileIn(__METHOD__);
     if ($master == true) {
         $title = Title::newFromId($id, Title::GAID_FOR_UPDATE);
     } else {
         $title = Title::newFromId($id);
     }
     if ($title instanceof Title && $title->exists()) {
         wfProfileOut(__METHOD__);
         return WallMessage::newFromTitle($title);
     }
     if ($master == false) {
         wfProfileOut(__METHOD__);
         // if you fail from slave try again from master
         return self::newFromId($id, true);
     }
     wfProfileOut(__METHOD__);
     return null;
 }
 /**
  * Makes sure the correct URLs for thread pages and message wall page get purged.
  *
  * @param $title Title
  * @param $urls String[]
  * @return bool
  */
 public static function onTitleGetSquidURLs($title, &$urls)
 {
     wfProfileIn(__METHOD__);
     if ($title->inNamespaces(NS_USER_WALL, NS_USER_WALL_MESSAGE, NS_USER_WALL_MESSAGE_GREETING)) {
         // CONN-430: Resign from default ArticleComment purges
         $urls = [];
     }
     if ($title->inNamespaces(NS_USER_WALL_MESSAGE, NS_USER_WALL_MESSAGE_GREETING)) {
         // CONN-430: purge cache only for main thread page and owner's wall page
         // while running AfterBuildNewMessageAndPost hook
         $wallMessage = WallMessage::newFromTitle($title);
         $urls = array_merge($urls, $wallMessage->getSquidURLs(NS_USER_WALL));
     }
     wfProfileOut(__METHOD__);
     return true;
 }
示例#3
0
 /**
  * Ensure that the comments_index record (if it exists) for an article is marked as deleted
  * when an article is deleted. This event must be run inside the transaction in WikiPage::doDeleteArticleReal
  * otherwise the Article referenced will no longer exist and the lookup for it's associated
  * comments_index row will fail.
  *
  * @param WikiPage $page WikiPage object
  * @param User $user User object [not used]
  * @param string $reason [not used]
  * @param int $id [not used]
  * @return bool true
  *
  */
 public static function onArticleDoDeleteArticleBeforeLogEntry(&$page, &$user, $reason, $id)
 {
     $title = $page->getTitle();
     if ($title instanceof Title) {
         $wallMessage = WallMessage::newFromTitle($title);
         $wallMessage->setInCommentsIndex(WPP_WALL_ADMINDELETE, 1);
     }
     return true;
 }
 public function replyToMessage()
 {
     $this->response->setVal('status', true);
     $parentId = $this->request->getVal('parent');
     $parentTitle = Title::newFromId($parentId);
     $debugParentDB = 'from slave';
     // tracing bug 95249
     if (empty($parentTitle)) {
         // try again from master
         $parentTitle = Title::newFromId($parentId, Title::GAID_FOR_UPDATE);
         $debugParentDB = 'from master';
     }
     if (empty($parentTitle)) {
         $this->response->setVal('status', false);
         return true;
     }
     Wikia::log(__METHOD__, false, 'Wall::replyToMessage for parent ' . $parentTitle->getFullUrl() . ' (parentId: ' . $parentId . ') ' . $debugParentDB, true);
     /**
      * @var $wallMessage WallMessage
      */
     $wallMessage = WallMessage::newFromTitle($parentTitle);
     $body = $this->getConvertedContent($this->request->getVal('body'));
     $reply = $wallMessage->addNewReply($body, $this->wg->User);
     if ($reply === false) {
         $this->response->setVal('status', false);
         return true;
     }
     $quotedFrom = $this->request->getVal('quotedFrom');
     if (!empty($quotedFrom)) {
         $reply->setQuoteOf($quotedFrom);
     }
     $this->replyToMessageBuildResponse($this, $reply);
     // after successfully posting a reply
     // remove notification for this thread (if user is following it)
     /**
      * @var $wn WallNotifications
      */
     $wn = new WallNotifications();
     $wn->markRead($this->wg->User->getId(), $this->wg->CityId, $this->request->getVal('parent'));
 }
 public function brickHeader()
 {
     $this->wg->SuppressPageTitle = true;
     $this->response->setVal('isRemoved', false);
     $this->response->setVal('isAdminDeleted', false);
     $this->response->setVal('isNotifyeveryone', false);
     $this->response->setVal('isClosed', false);
     $path = array();
     $this->response->setVal('path', $path);
     $title = Title::newFromId($this->request->getVal('id'));
     if (empty($title)) {
         $title = Title::newFromID($this->request->getVal('id'), Title::GAID_FOR_UPDATE);
     }
     if (!empty($title) && $title->isTalkPage()) {
         $wallMessage = WallMessage::newFromTitle($title);
         $wallMessageParent = $wallMessage->getTopParentObj();
         if (!empty($wallMessageParent)) {
             $wallMessage = $wallMessageParent;
         }
         $wallMessage->load();
         if ($wallMessage->isWallOwner($this->wg->User)) {
             $wallName = wfMessage('wall-message-mywall')->escaped();
         } else {
             $wallOwner = $wallMessage->getWallOwner()->getName();
             $wallName = wfMessage('wall-message-elseswall', $wallOwner)->parse();
         }
         $wallUrl = $wallMessage->getWallUrl();
         $messageTitle = htmlspecialchars($wallMessage->getMetaTitle());
         $isRemoved = $wallMessage->isRemove();
         $isDeleted = $wallMessage->isAdminDelete();
         $this->response->setVal('isRemoved', $isRemoved);
         $this->response->setVal('isAdminDeleted', $isDeleted);
         $this->response->setVal('isNotifyeveryone', $wallMessage->getNotifyeveryone());
         $this->response->setVal('isClosed', $wallMessage->isArchive());
         if ($isRemoved || $isDeleted) {
             $this->wg->Out->setRobotPolicy("noindex,nofollow");
         }
         $user = $this->app->wg->User;
         // remove admin notification for it if Admin just checked it
         if (in_array('sysop', $user->getEffectiveGroups()) || in_array('staff', $user->getEffectiveGroups())) {
             $wna = new WallNotificationsAdmin();
             $wna->removeForThread($this->app->wg->CityId, $wallMessage->getId());
         }
         $wno = new WallNotificationsOwner();
         $wno->removeForThread($this->app->wg->CityId, $user->getId(), $wallMessage->getId());
         $path[] = array('title' => $wallName, 'url' => $wallUrl);
         $path[] = array('title' => $messageTitle);
         $this->getContext()->getOutput()->setRobotPolicy('index,follow');
         wfRunHooks('WallThreadHeader', array($title, $wallMessage, &$path, &$this->response, &$this->request));
     } else {
         wfRunHooks('WallHeader', array($this->wg->Title, &$path, &$this->response, &$this->request));
     }
     $this->response->setVal('path', $path);
 }
示例#6
0
 /**
  * MailNotifyBuildKeys -- return build keys for mail
  *
  * @static
  * @access public
  *
  * @param $keys
  * @param $action
  * @param $other_param
  *
  * @return array
  * @throws MWException
  */
 public static function mailNotifyBuildKeys(&$keys, $action, $other_param)
 {
     global $wgEnableForumExt;
     $actionsList = [self::LOG_ACTION_CATEGORY_ADD, self::LOG_ACTION_BLOG_POST];
     if (!in_array($action, $actionsList)) {
         return true;
     }
     $page = Title::newFromText($keys['$PAGETITLE']);
     /** @var Title $childTitle */
     $childTitle = $other_param['childTitle'];
     $keys['$PAGETITLE'] = $childTitle->getPrefixedText();
     $keys['$PAGETITLE_URL'] = $childTitle->getFullUrl();
     if ($action == self::LOG_ACTION_CATEGORY_ADD) {
         $keys['$CATEGORY_URL'] = $page->getFullUrl();
         $keys['$CATEGORY'] = $page->getText();
         // Format Forum thread URLs when added to category
         if (!empty($wgEnableForumExt) && $childTitle->getNamespace() === NS_WIKIA_FORUM_BOARD_THREAD) {
             $titleParts = explode('/', $childTitle->getPrefixedText());
             // Handle replies, can't use WallMessage::getTopParentObj as the comments
             // index isn't updated yet
             if (strpos($titleParts[count($titleParts) - 2], ARTICLECOMMENT_PREFIX) === 0) {
                 $titleText = implode('/', array_slice($titleParts, 0, count($titleParts) - 1));
                 $childTitle = Title::newFromText($titleText);
             }
             $wallMessage = WallMessage::newFromTitle($childTitle);
             $wallMessage->load();
             $threadTitle = Title::newFromText($wallMessage->getID(), NS_USER_WALL_MESSAGE);
             $keys['$PAGETITLE'] = $wallMessage->getMetaTitle();
             $keys['$PAGETITLE_URL'] = $threadTitle->getFullURL();
         }
         return true;
     }
     if ($action == self::LOG_ACTION_BLOG_POST) {
         $keys['$BLOGLISTING_URL'] = $page->getFullUrl();
         $keys['$BLOGLISTING'] = $page->getText();
         return true;
     }
     return true;
 }
示例#7
0
 /**
  * @desc Gets pages from watchlist depending on given parameters; The result list is grouped by static::$namespaces
  *
  * @param Integer $user_id
  * @param Integer $from
  * @param Integer $limit
  * @param Boolean $show_deleted_pages
  * @param Array $namespaces
  *
  * @return Array
  */
 private function getWatchListArray($user_id, $from, $limit, $show_deleted_pages, $namespaces)
 {
     global $wgServer, $wgScript, $wgContentNamespaces;
     wfProfileIn(__METHOD__);
     $db = wfGetDB(DB_SLAVE);
     $namespaces_keys = array_keys($namespaces);
     $queryArray = [];
     $out_data = [];
     foreach ($namespaces_keys as $value) {
         $value = (int) $value;
         $isWall = $value == NS_USER_WALL;
         $queryArray[] = "(select wl_namespace, wl_title from watchlist where wl_user = "******" and wl_namespace = " . $value . ($isWall ? " and not wl_title like '%/%' " : '') . " ORDER BY wl_wikia_addedtimestamp desc limit " . $from . "," . $limit . ")";
     }
     $res = $db->query(implode(" union ", $queryArray));
     while ($row = $db->fetchRow($res)) {
         $title = Title::makeTitle($row['wl_namespace'], $row['wl_title']);
         $row['url'] = $title->getFullURL();
         $row['hideurl'] = $wgServer . $wgScript . "?action=ajax&rs=wfAjaxWatch&rsargs[]=" . $title->getPrefixedURL() . "&rsargs[]=u";
         $row['wl_title'] = str_replace("_", " ", $row['wl_title']);
         if (defined('NS_BLOG_ARTICLE') && $row['wl_namespace'] == NS_BLOG_ARTICLE) {
             $explode = explode("/", $row['wl_title']);
             if (count($explode) > 1) {
                 $row['wl_title'] = $explode[1];
                 $row['by_user'] = $explode[0];
             }
         }
         if (defined('NS_WIKIA_FORUM_BOARD_THREAD') && $row['wl_namespace'] == NS_WIKIA_FORUM_BOARD_THREAD) {
             $wallMessage = WallMessage::newFromTitle($title);
             $wallMessage->load();
             $row['wl_title'] = $wallMessage->getMetaTitle();
             $row['wl_title_obj'] = Title::newFromText($wallMessage->getID(), NS_USER_WALL_MESSAGE);
             $row['on_board'] = Xml::tags('a', array('href' => $wallMessage->getWallUrl(), 'title' => $wallMessage->getArticleTitle()->getText()), $wallMessage->getArticleTitle()->getText());
         }
         if (in_array($row['wl_namespace'], $wgContentNamespaces) && NS_MAIN != $row['wl_namespace']) {
             $title = Title::makeTitle($row['wl_namespace'], "none");
             $row['other_namespace'] = $title->getNsText();
         }
         if ($show_deleted_pages) {
             $out_data[$namespaces[$row['wl_namespace']]][] = $row;
         } else {
             if ($title->isKnown() || $title->getNamespace() == NS_USER_WALL) {
                 $out_data[$namespaces[$row['wl_namespace']]][] = $row;
             }
         }
     }
     wfProfileOut(__METHOD__);
     return $out_data;
 }
示例#8
0
 public function getUser()
 {
     $title = F::app()->wg->Title;
     $ns = $title->getNamespace();
     $user = null;
     if ($ns == NS_USER_WALL) {
         /**
          * @var $w Wall
          */
         $w = Wall::newFromTitle($title);
         $user = $w->getUser();
     } else {
         if ($ns == NS_USER_WALL_MESSAGE) {
             // title to wall thread is Thread:dddd, which does not exist in the db. this will
             // result in articleId being 0, which will break the logic later. So we need
             // to fetch the existing title here (Username/@comment-...)
             if (intval($title->getText()) > 0) {
                 $mainTitle = Title::newFromId($title->getText());
                 if (empty($mainTitle)) {
                     $mainTitle = Title::newFromId($title->getText(), Title::GAID_FOR_UPDATE);
                 }
                 if (!empty($mainTitle)) {
                     $title = $mainTitle;
                 }
             }
             /**
              * @var $wm WallMessage
              */
             $wm = WallMessage::newFromTitle($title);
             $user = $wm->getWallOwner();
         }
     }
     if (is_null($user)) {
         return UserProfilePageHelper::getUserFromTitle($title);
     }
     return $user;
 }
 /**
  * Loads a new WallMessage object from a Revision object
  *
  * @param Revision $rev
  *
  * @return WallMessage
  */
 public function getWallMessageFromRev(Revision $rev)
 {
     $wm = WallMessage::newFromTitle($rev->getTitle());
     $wm->load();
     return $wm;
 }