Beispiel #1
0
function getCommentProperties($articleComment)
{
    $properties = array();
    if ($articleComment->getTitle()->getNamespace() == NS_USER_WALL_MESSAGE || $articleComment->getTitle()->getNamespace() == NS_WIKIA_FORUM_BOARD_THREAD) {
        $wallMessage = WallMessage::newFromArticleComment($articleComment);
        $properties = array('archived' => intval($wallMessage->isArchive()), 'deleted' => intval($wallMessage->isAdminDelete()), 'removed' => intval($wallMessage->isRemove()));
    }
    return $properties;
}
 /**
  * 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;
 }
Beispiel #3
0
$history = new WallHistory();
$dbw = $history->getDatawareDB();
$res = $dbw->select('wall_history', array('post_user_id', 'post_user_ip', 'is_reply', 'post_ns', 'page_id', 'parent_page_id', 'metatitle', 'deleted_or_removed', 'event_date', 'reason', 'action', 'revision_id', 'deleted_or_removed'), array('migrated' => 0, 'wiki_id' => $wgCityId), __METHOD__);
$in = array();
$db = $history->getDB(DB_MASTER);
$dir = dirname(__FILE__);
if (!$db->tableExists('wall_history')) {
    echo "Try to create table\\'n";
    $db->sourceFile($IP . "/extensions/wikia/Wall/sql/wall_history_local.sql");
}
while ($row = $dbw->fetchRow($res)) {
    if ($row['action'] == WH_NEW || $row['action'] == WH_EDIT) {
        $pagesRow = $db->selectRow('revision', array('rev_timestamp'), array('rev_id' => $row['revision_id']));
        $row['event_date'] = wfTimestamp(TS_DB, $pagesRow->rev_timestamp);
    }
    $mw = WallMessage::newFromId($row['page_id']);
    if (empty($mw)) {
        continue;
    }
    /*	$history->internalAdd( 
    	$parentPageId, 
    	$postUserId, 
    	$postUserName, $
    	isReply, $commentId, $ns, $parentCommentId, $metatitle, $action, $reason, $revId, $deletedOrRemoved );
    */
    if ($mw->isMain()) {
        $parentCommentId = $row['page_id'];
        $commentId = $row['page_id'];
    } else {
        $parentCommentId = $row['parent_page_id'];
        $commentId = $row['page_id'];
Beispiel #4
0
 protected function executeBuildAndPostWallMessage($defaultWelcomeUser, $welcomeMessage, $recipientName, $textMessage)
 {
     $wallMessage = WallMessage::buildNewMessageAndPost($welcomeMessage, $recipientName, $defaultWelcomeUser, $textMessage, false, array(), false, false);
     return $wallMessage;
 }
 private function setMessageParentUserData(stdClass $data, WallMessage $parent)
 {
     $parentUser = $parent->getUser();
     if ($parentUser instanceof User) {
         $data->parent_username = $parentUser->getName();
         $data->parent_user_id = $parentUser->getId();
         if ($data->parent_user_id > 0) {
             $data->parent_displayname = $data->parent_username;
         } else {
             $data->parent_displayname = wfMessage('oasis-anon-user')->escaped();
         }
     } else {
         /* parent was deleted and somehow reply stays in the system
          * the only way I've reproduced it was: I deleted a thread
          * then I went to Special:Log/delete and restored only its reply
          * an edge case but it needs to be handled
          * --nAndy
          */
         $data->parent_username = wfMessage('oasis-anon-user')->escaped();
         $data->parent_displayname = $data->parent_username;
         $data->parent_user_id = 0;
     }
 }
Beispiel #6
0
 public function getLastMessage()
 {
     $key = wfMemcKey(__CLASS__, '-thread-lastreply-key', $this->mThreadId);
     $threadId = $this->mThreadId;
     $data = WikiaDataAccess::cache($key, 30 * 24 * 60 * 60, function () use($threadId) {
         $db = wfGetDB(DB_SLAVE);
         $row = $db->selectRow(array('comments_index'), array('max(first_rev_id) rev_id'), array('parent_comment_id' => $threadId, 'archived' => 0, 'deleted' => 0, 'removed' => 0), __METHOD__);
         return $row;
     });
     // get last post info
     $revision = Revision::newFromId($data->rev_id);
     if ($revision instanceof Revision) {
         $title = $revision->getTitle();
         $wallMessage = WallMessage::newFromId($title->getArticleId());
         if (!empty($wallMessage)) {
             $wallMessage->load();
             return $wallMessage;
         }
     }
     return null;
 }
 protected function getWallMessage()
 {
     $comment = $this->request->getVal('comment');
     if ($comment instanceof ArticleComment) {
         $wallMessage = WallMessage::newFromArticleComment($comment);
     } else {
         $wallMessage = $comment;
     }
     if ($wallMessage instanceof WallMessage) {
         $wallMessage->load();
         return $wallMessage;
     }
 }
 protected function formatData($row)
 {
     $user = null;
     if ($row['post_user_id'] > 0) {
         $user = User::newFromID($row['post_user_id']);
     } else {
         $user = User::newFromName($this->long2ip($row['post_user_ip']), false);
     }
     $message = WallMessage::newFromId($row['page_id']);
     if (empty($message)) {
         return;
     }
     $title = $message->getTitle();
     if ($title instanceof Title && $message instanceof WallMessage) {
         return array('user' => $user, 'event_date' => $row['event_date'], 'event_iso' => wfTimestamp(TS_ISO_8601, $row['event_date']), 'event_mw' => wfTimestamp(TS_MW, $row['event_date']), 'display_username' => $user->getId() == 0 ? wfMsg('oasis-anon-user') : $user->getName(), 'metatitle' => $row['metatitle'], 'page_id' => $row['page_id'], 'title' => $title, 'is_reply' => $row['is_reply'], 'action' => $row['action'], 'reason' => $row['reason'], 'revision_id' => $row['revision_id'], 'wall_message' => $message);
     } else {
         //it happened once on devbox when master&slave weren't sync'ed
         wfDebug(__METHOD__ . ": Seems like master&slave are not sync'ed\n");
     }
 }
 /**
  * @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;
 }
 /**
  * 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;
 }
Beispiel #11
0
 public function setQuoteOf($id)
 {
     if ($this->isMain()) {
         return false;
     }
     $msgParent = $this->getTopParentObj();
     /**
      * @var $quotedMsg WallMessage
      */
     $quotedMsg = WallMessage::newFromId($id, true);
     if (empty($quotedMsg)) {
         return false;
     }
     if ($quotedMsg->isMain()) {
         if ($quotedMsg->getId() != $msgParent->getId()) {
             return false;
         }
     } else {
         $quotedMsgParent = $quotedMsg->getTopParentObj();
         if ($quotedMsgParent->getId() != $msgParent->getId()) {
             return false;
         }
     }
     $this->setInProps(WPP_WALL_QUOTE_OF, $id);
     return true;
 }
 /**
  * setWelcomeTalkPage
  *
  * @access private
  *
  * @return boolean status
  */
 private function setWelcomeTalkPage()
 {
     global $wgUser, $wgEnableWallExt;
     $saveUser = $wgUser;
     Wikia::log(__METHOD__, "talk", "Setting welcome talk page on new wiki or Wall");
     Wikia::log(__METHOD__, "vars", "sitename: {$this->wikiaName}; language: {$this->wikiaLang}");
     /**
      * set apropriate staff member
      */
     $wgUser = Wikia::staffForLang($this->wikiaLang);
     $wgUser = $wgUser instanceof User ? $wgUser : User::newFromName(CreateWiki::DEFAULT_STAFF);
     $talkParams = array($this->mFounder->getName(), $wgUser->getName(), $wgUser->getRealName(), $this->wikiaName);
     $wallTitle = false;
     if (!empty($this->wikiaLang)) {
         $wallTitle = wfMsgExt("autocreatewiki-welcometalk-wall-title", array('language' => $this->wikiaLang));
     }
     if (!$wallTitle) {
         $wallTitle = wfMsg("autocreatewiki-welcometalk-wall-title");
     }
     if (!empty($wgEnableWallExt)) {
         $msg = "autocreatewiki-welcometalk-wall";
     } else {
         $msg = "autocreatewiki-welcometalk";
     }
     $talkBody = false;
     if (!empty($this->wikiaLang)) {
         /**
          * custom lang translation
          */
         $talkBody = wfMsgExt($msg, array('language' => $this->wikiaLang), $talkParams);
     }
     if (!$talkBody) {
         /**
          * wfMsgExt should always return message, but just in case...
          */
         $talkBody = wfMsg($msg, $talkParams);
     }
     if (!empty($wgEnableWallExt)) {
         $wallMessage = WallMessage::buildNewMessageAndPost($talkBody, $this->mFounder->getName(), $wgUser, $wallTitle, false, array(), true, false);
         if ($wallMessage === false) {
             return false;
         }
         Wikia::log(__METHOD__, "wall", $this->mFounder->getName());
         return true;
     }
     $talkPage = $this->mFounder->getTalkPage();
     if ($talkPage) {
         Wikia::log(__METHOD__, "talk", $talkPage->getFullUrl());
         /**
          * and now create talk article
          */
         $talkArticle = new Article($talkPage, 0);
         if (!$talkArticle->exists()) {
             $talkArticle->doEdit($talkBody, wfMsg("autocreatewiki-welcometalk-log"), EDIT_SUPPRESS_RC | EDIT_MINOR | EDIT_FORCE_BOT);
         } else {
             Wikia::log(__METHOD__, "talkpage", sprintf("%s already exists", $talkPage->getFullURL()));
         }
     } else {
         Wikia::log(__METHOD__, "error", "Can't take talk page for user " . $this->mFounder->getId());
     }
     $wgUser = $saveUser;
     // Restore user object after creating talk message
     return true;
 }
Beispiel #13
0
 /**
  * @param null $rc
  * @param array $row [ page_title, page_namespace, rev_user_text?, page_is_new?, rev_parent_id? ]
  * @return array|bool
  */
 public static function getWallTitleData($rc = null, $row = null)
 {
     wfProfileIn(__METHOD__);
     if (is_object($row)) {
         $objTitle = Title::newFromText($row->page_title, $row->page_namespace);
         $userText = !empty($row->rev_user_text) ? $row->rev_user_text : '';
         $isNew = !empty($row->page_is_new) && $row->page_is_new === '1' ? true : false;
         if (!$isNew) {
             $isNew = isset($row->rev_parent_id) && $row->rev_parent_id === '0' ? true : false;
         }
     } else {
         $objTitle = $rc->getTitle();
         $userText = $rc->getAttribute('rc_user_text');
         $isNew = false;
         // it doesn't metter for rc -- we've got there rc_log_action
     }
     if (!$objTitle instanceof Title) {
         // it can be media wiki deletion of an article -- we ignore them
         Wikia::log(__METHOD__, false, "WALL_NOTITLE_FOR_MSG_OPTS " . print_r(array($rc, $row), true));
         wfProfileOut(__METHOD__);
         return true;
     }
     $wm = WallMessage::newFromId($objTitle->getArticleId());
     if (empty($wm)) {
         // it can be media wiki deletion of an article -- we ignore them
         Wikia::log(__METHOD__, false, "WALL_NOTITLE_FOR_MSG_OPTS " . print_r(array($rc, $row), true));
         wfProfileOut(__METHOD__);
         return true;
     }
     $wm->load();
     if (!$wm->isMain()) {
         $wmw = $wm->getTopParentObj();
         if (empty($wmw)) {
             wfProfileOut(__METHOD__);
             return true;
         }
         $wmw->load();
     }
     if (!empty($wmw)) {
         $articleTitleTxt = $wmw->getMetaTitle();
         $articleId = $wmw->getId();
     } else {
         $articleTitleTxt = $wm->getMetaTitle();
         $articleId = $wm->getId();
     }
     // XSS vulnerable (MAIN-1412)
     if (!empty($articleTitleTxt)) {
         $articleTitleTxt = strip_tags($articleTitleTxt);
     }
     $ci = $wm->getCommentsIndex();
     if (empty($ci) && $row->page_namespace == NS_USER_WALL) {
         // change in NS_USER_WALL namespace mean that wall page was created (bugid:95249)
         $title = Title::newFromText($row->page_title, NS_USER_WALL);
         $out = array('articleTitle' => $title->getPrefixedText(), 'articleFullUrl' => $title->getFullUrl(), 'articleTitleVal' => '', 'articleTitleTxt' => wfMessage('wall-recentchanges-wall-created-title')->text(), 'wallTitleTxt' => $title->getPrefixedText(), 'wallPageFullUrl' => $title->getFullUrl(), 'wallPageName' => $row->page_title, 'actionUser' => $userText, 'isThread' => $wm->isMain(), 'isNew' => $isNew);
     } else {
         $title = Title::newFromText($articleId, NS_USER_WALL_MESSAGE);
         $out = array('articleTitle' => $title->getPrefixedText(), 'articleFullUrl' => $wm->getMessagePageUrl(), 'articleTitleVal' => $articleTitleTxt, 'articleTitleTxt' => empty($articleTitleTxt) ? wfMessage('wall-recentchanges-deleted-reply-title')->text() : $articleTitleTxt, 'wallTitleTxt' => $wm->getArticleTitle()->getPrefixedText(), 'wallPageFullUrl' => $wm->getArticleTitle()->getFullUrl(), 'wallPageName' => $wm->getArticleTitle()->getText(), 'actionUser' => $userText, 'isThread' => $wm->isMain(), 'isNew' => $isNew);
     }
     wfProfileOut(__METHOD__);
     return $out;
 }
 /**
  * setWelcomeTalkPage
  *
  * @return boolean status
  */
 private function setWelcomeTalkPage()
 {
     global $wgUser, $wgEnableWallExt;
     $saveUser = $wgUser;
     $this->info('Setting welcome talk page on new wiki or Wall', ['sitename' => $this->wikiName, 'language' => $this->wikiLang]);
     /**
      * set apropriate staff member
      */
     $wgUser = \Wikia::staffForLang($this->wikiLang);
     $wgUser = $wgUser instanceof \User ? $wgUser : \User::newFromName(\CreateWiki::DEFAULT_STAFF);
     $talkParams = array($this->founder->getName(), $wgUser->getName(), $wgUser->getRealName(), $this->wikiName);
     $wallTitle = false;
     if (!empty($this->wikiLang)) {
         $wallTitle = wfMsgExt("autocreatewiki-welcometalk-wall-title", array('language' => $this->wikiLang));
     }
     if (!$wallTitle) {
         $wallTitle = wfMsg("autocreatewiki-welcometalk-wall-title");
     }
     if (!empty($wgEnableWallExt)) {
         $msg = "autocreatewiki-welcometalk-wall";
     } else {
         $msg = "autocreatewiki-welcometalk";
     }
     $talkBody = false;
     if (!empty($this->wikiLang)) {
         /**
          * custom lang translation
          */
         $talkBody = wfMsgExt($msg, array('language' => $this->wikiLang), $talkParams);
     }
     if (!$talkBody) {
         /**
          * wfMsgExt should always return message, but just in case...
          */
         $talkBody = wfMsg($msg, $talkParams);
     }
     if (!empty($wgEnableWallExt)) {
         $wallMessage = \WallMessage::buildNewMessageAndPost($talkBody, $this->founder->getName(), $wgUser, $wallTitle, false, array(), true, false);
         if ($wallMessage === false) {
             return false;
         }
         $this->info("wall message created", ['founder_name' => $this->founder->getName()]);
         return true;
     }
     $talkPage = $this->founder->getTalkPage();
     if ($talkPage) {
         /**
          * and now create talk article
          */
         $talkArticle = new \Article($talkPage, 0);
         if (!$talkArticle->exists()) {
             $talkArticle->doEdit($talkBody, wfMsg("autocreatewiki-welcometalk-log"), EDIT_SUPPRESS_RC | EDIT_MINOR | EDIT_FORCE_BOT);
         } else {
             $this->warning('talkpage already exists', ['url' => $talkPage->getFullURL()]);
         }
     } else {
         $this->error("Can't take talk page for user", ['founder_id' => $this->founder->getId()]);
     }
     $wgUser = $saveUser;
     // Restore user object after creating talk message
     return true;
 }
 public function forumRelatedThreads()
 {
     $title = F::build('Title', array($this->app->wg->Title->getText()), 'newFromId');
     $this->response->setVal('showModule', false);
     if (!empty($title) && $title->getNamespace() == NS_WIKIA_FORUM_BOARD_THREAD) {
         $rp = new WallRelatedPages();
         $out = $rp->getMessageRelatetMessageIds(array($title->getArticleId()));
         $messages = array();
         $count = 0;
         foreach ($out as $key => $val) {
             if ($title->getArticleId() == $val['comment_id']) {
                 continue;
             }
             $msg = WallMessage::newFromId($val['comment_id']);
             if (!empty($msg)) {
                 $msg->load();
                 $message = array('message' => $msg);
                 if (!empty($val['last_child'])) {
                     $childMsg = WallMessage::newFromId($val['last_child']);
                     if (!empty($childMsg)) {
                         $childMsg->load();
                         $message['reply'] = $childMsg;
                     }
                 }
                 $messages[] = $message;
                 $count++;
                 if ($count == 5) {
                     break;
                 }
             }
         }
         $this->response->setVal('showModule', !empty($messages));
         $this->response->setVal('messages', $messages);
     }
 }
 /**
  * @return null|ArticleComment
  */
 public function getTopParentObj()
 {
     wfProfileIn(__METHOD__);
     $key = $this->getArticleComment()->getTopParent();
     if (!empty(self::$topObjectCache[$key])) {
         wfProfileOut(__METHOD__);
         return self::$topObjectCache[$key];
     }
     $obj = $this->getArticleComment()->getTopParentObj();
     if (empty($obj)) {
         wfProfileOut(__METHOD__);
         return null;
     }
     if ($obj instanceof ArticleComment) {
         wfProfileOut(__METHOD__);
         self::$topObjectCache[$key] = WallMessage::newFromArticleComment($obj);
         return self::$topObjectCache[$key];
     } else {
         wfProfileOut(__METHOD__);
         return null;
     }
 }
Beispiel #17
0
 /**
  * Provided a page, returns the string value of that page's title
  * This allows us to accommodate unconventional locations for titles
  * @param \Title $title
  * @return string
  */
 protected function getTitleString(\Title $title)
 {
     wfProfileIn(__METHOD__);
     if (in_array($title->getNamespace(), array(NS_WIKIA_FORUM_BOARD_THREAD, NS_USER_WALL_MESSAGE))) {
         $wm = \WallMessage::newFromId($title->getArticleID());
         if ($wm) {
             $wm->load();
             if (!$wm->isMain() && ($main = $wm->getTopParentObj()) && !empty($main)) {
                 $main->load();
                 $wm = $main;
             }
             wfProfileOut(__METHOD__);
             return (string) $wm->getMetaTitle();
         } else {
             \Wikia\Logger\WikiaLogger::instance()->warning('Null WallMessage', ['message_id' => $title->getArticleID()]);
         }
     }
     wfProfileOut(__METHOD__);
     return $title->getFullText();
 }
 /**
  * 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;
 }
 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);
 }
 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;
 }
 /**
  * Updates topics list to given message id.  It will completely override.
  * @param string $messageId - numeric id
  * @param array $relatedTopics - list of topics (article names)
  * @return string status - success/failure
  */
 public function updateTopics()
 {
     $messageId = $this->request->getVal('msgid', '');
     $relatedTopics = $this->request->getVal('relatedTopics', array());
     // place holder data, replace this with magic
     $status = 'success';
     $topics = array();
     if (!is_array($relatedTopics)) {
         $relatedTopics = array();
     }
     // cut more then 4
     $relatedTopics = array_slice($relatedTopics, 0, 4);
     // save
     /**
      * @var $mw WallMessage
      */
     $mw = WallMessage::newFromId($messageId);
     if (!empty($mw)) {
         $mw->load();
         $mw->setRelatedTopics($this->wg->User, $relatedTopics);
     }
     foreach ($relatedTopics as $topic) {
         $topicTitle = Title::newFromURL($topic);
         $topics[] = array('topic' => $topic, 'url' => WallHelper::getTopicPageURL($topicTitle));
         // I have no idea what the url will be, just a placeholder for now
     }
     // end place holder
     $this->response->setVal('status', $status);
     $this->response->setVal('topics', $topics);
 }
Beispiel #22
0
 public function getThreadMainMsg()
 {
     return WallMessage::newFromId($this->mThreadId);
 }
 /**
  * This method does the brunt of the work for populating an array with the values
  * we need when servicing the backend search indexer processes
  * @see WikiaSearchIndexer::getPages()
  * @see WikiaSearchController::getPage()
  * @param int $pageId
  * @throws WikiaException
  * @return array result
  */
 public function getPage($pageId)
 {
     wfProfileIn(__METHOD__);
     $result = array();
     $page = F::build('Article', array($pageId), 'newFromID');
     if (!$page instanceof Article) {
         throw new WikiaException('Invalid Article ID');
     }
     if (!$this->parserHookActive) {
         $this->app->registerHook('ParserClearState', 'WikiaSearchIndexer', 'onParserClearState');
         $this->parserHookActive = true;
     }
     // hack: setting wgTitle as rendering fails otherwise
     $wgTitle = $this->wg->Title;
     $this->wg->Title = $page->getTitle();
     // hack: setting action=render to exclude "Related Pages" and other unwanted stuff
     $wgRequest = $this->wg->Request;
     $this->wg->Request->setVal('action', 'render');
     if ($page->isRedirect()) {
         $redirectPage = F::build('Article', array($page->getRedirectTarget()));
         $redirectPage->loadContent();
         // hack: setting wgTitle as rendering fails otherwise
         $this->wg->Title = $page->getRedirectTarget();
         $redirectPage->render();
         $canonical = $page->getRedirectTarget()->getPrefixedText();
     } else {
         $page->render();
         $canonical = '';
     }
     $html = $this->wg->Out->getHTML();
     $namespace = $this->wg->Title->getNamespace();
     $isVideo = false;
     $isImage = false;
     if ($namespace == NS_FILE && ($file = $this->wf->findFile($this->wg->Title->getText()))) {
         $detail = WikiaFileHelper::getMediaDetail($this->wg->Title);
         $isVideo = WikiaFileHelper::isVideoFile($file);
         $isImage = $detail['mediaType'] == 'image' && !$isVideo;
         $metadata = $file->getMetadata();
         if ($metadata !== "0") {
             $metadata = unserialize($metadata);
             $fileParams = array('description', 'keywords') + ($isVideo ? array('movieTitleAndYear', 'videoTitle') : array());
             foreach ($fileParams as $datum) {
                 $html .= isset($metadata[$datum]) ? ' ' . $metadata[$datum] : '';
             }
         }
     }
     $title = $page->getTitle()->getText();
     if (in_array($namespace, array(NS_WIKIA_FORUM_BOARD_THREAD, NS_USER_WALL_MESSAGE))) {
         $wm = WallMessage::newFromId($page->getId());
         $wm->load();
         if ($wm->isMain()) {
             $title = $wm->getMetaTitle();
         } else {
             if ($main = $wm->getTopParentObj() and !empty($main)) {
                 $main->load();
                 $title = $main->getMetaTitle();
             }
         }
     }
     // clear output buffer in case we want get more pages
     $this->wg->Out->clearHTML();
     $result['wid'] = empty($this->wg->ExternalSharedDB) ? $this->wg->SearchWikiId : (int) $this->wg->CityId;
     $result['pageid'] = $pageId;
     $result['id'] = $result['wid'] . '_' . $result['pageid'];
     $result['title'] = $title;
     $result['canonical'] = $canonical;
     $result['html'] = html_entity_decode($html, ENT_COMPAT, 'UTF-8');
     $result['url'] = $page->getTitle()->getFullUrl();
     $result['ns'] = $page->getTitle()->getNamespace();
     $result['host'] = substr($this->wg->Server, 7);
     $result['lang'] = $this->wg->Lang->mCode;
     # these need to be strictly typed as bool strings since they're passed via http when in the hands of the worker
     $result['iscontent'] = in_array($result['ns'], $this->wg->ContentNamespaces) ? 'true' : 'false';
     $result['is_main_page'] = $page->getId() == Title::newMainPage()->getArticleId() && $page->getId() != 0 ? 'true' : 'false';
     $result['is_redirect'] = $canonical == '' ? 'false' : 'true';
     $result['is_video'] = $isVideo ? 'true' : 'false';
     $result['is_image'] = $isImage ? 'true' : 'false';
     if ($this->wg->EnableBacklinksExt && $this->wg->IndexBacklinks) {
         $result['backlink_text'] = Backlinks::getForArticle($page);
     }
     $result = array_merge($result, $this->getPageMetaData($page));
     // restore global state
     $this->wg->Title = $wgTitle;
     $this->wg->Request = $wgRequest;
     wfProfileOut(__METHOD__);
     return $result;
 }