public function executeIndex()
 {
     wfProfileIn(__METHOD__);
     if (class_exists('ArticleCommentInit') && ArticleCommentInit::ArticleCommentCheck()) {
         $isMobile = $this->app->checkSkin('wikiamobile');
         // for non-JS version !!! (used also for Monobook and WikiaMobile)
         if ($this->wg->Request->wasPosted()) {
             $sComment = $this->wg->Request->getVal('wpArticleComment', false);
             $iArticleId = $this->wg->Request->getVal('wpArticleId', false);
             $sSubmit = $this->wg->Request->getVal('wpArticleSubmit', false);
             if ($sSubmit && $sComment && $iArticleId) {
                 $oTitle = Title::newFromID($iArticleId);
                 if ($oTitle instanceof Title) {
                     $response = ArticleComment::doPost($this->wg->Request->getVal('wpArticleComment'), $this->wg->User, $oTitle);
                     if (!$isMobile) {
                         $this->wg->Out->redirect($oTitle->getLocalURL());
                     } else {
                         $result = array();
                         $canComment = ArticleCommentInit::userCanComment($result, $oTitle);
                         //this check should be done for all the skins and before calling ArticleComment::doPost but that requires a good bit of refactoring
                         //and some design review as the OAsis/Monobook template doesn't handle error feedback from this code
                         if ($canComment == true) {
                             if (empty($response[2]['error'])) {
                                 //wgOut redirect doesn't work when running fully under the
                                 //Nirvana stack (WikiaMobile skin), also send back to the first page of comments
                                 $this->response->redirect($oTitle->getLocalURL(array('page' => 1)) . '#article-comments');
                             } else {
                                 $this->response->setVal('error', $response[2]['msg']);
                             }
                         } else {
                             $this->response->setVal('error', $result['msg']);
                         }
                     }
                 }
             }
         }
         $this->page = $this->wg->request->getVal('page', 1);
         $this->isLoadingOnDemand = ArticleComment::isLoadingOnDemand();
         $this->isMiniEditorEnabled = ArticleComment::isMiniEditorEnabled();
         if ($this->isLoadingOnDemand) {
             $this->response->setJsVar('wgArticleCommentsLoadOnDemand', true);
         } else {
             $this->getCommentsData($this->wg->Title, $this->page);
             if ($isMobile) {
                 $this->forward(__CLASS__, 'WikiaMobileIndex', false);
             } else {
                 if ($this->app->checkSkin('oasis')) {
                     $this->response->addAsset('articlecomments' . ($this->isMiniEditorEnabled ? '_mini_editor' : '') . '_scss');
                 }
             }
         }
     }
     wfProfileOut(__METHOD__);
 }
 /**
  * axPost -- static hook/entry for ajax request post
  *
  * @static
  * @access public
  *
  * @return String -- json-ized array`
  */
 public static function axPost()
 {
     global $wgRequest, $wgUser, $wgLang;
     $articleId = $wgRequest->getVal('article', false);
     $parentId = $wgRequest->getVal('parentId');
     $result = array('error' => 1);
     $title = Title::newFromID($articleId);
     if (!$title) {
         return $result;
     }
     if (!ArticleComment::canComment($title)) {
         return $result;
     }
     WikiaLogger::instance()->info(__METHOD__ . ' : Comment posted', ['skin' => $wgRequest->getVal('useskin'), 'articleId' => $articleId, 'parentId' => $parentId]);
     $response = ArticleComment::doPost(self::getConvertedContent($wgRequest->getVal('wpArticleComment')), $wgUser, $title, $parentId);
     if ($response !== false) {
         if ($title->getNamespace() == NS_USER_TALK && $response[0] == EditPage::AS_SUCCESS_NEW_ARTICLE && $title->getText() != $wgUser->getName()) {
             $user = User::newFromName($title->getText());
             if ($user) {
                 $user->setNewtalk(true);
             }
         }
         $listing = ArticleCommentList::newFromTitle($title);
         $countAll = $wgLang->formatNum($listing->getCountAllNested());
         $commentsHTML = $response[2]['text'];
         $result = array('text' => $commentsHTML, 'counter' => $countAll);
         if (F::app()->checkskin('wikiamobile')) {
             $result['counterMessage'] = wfMessage('wikiamobile-article-comments-counter')->params($countAll)->text();
         }
         if ($parentId) {
             $result['parentId'] = $parentId;
         }
         return $result;
     }
     return $result;
 }
Exemplo n.º 3
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;
 }
 /**
  * axPost -- static hook/entry for ajax request post
  *
  * @static
  * @access public
  *
  * @return String -- json-ized array`
  */
 public static function axPost()
 {
     global $wgRequest, $wgUser, $wgLang;
     $articleId = $wgRequest->getVal('article', false);
     $parentId = $wgRequest->getVal('parentId');
     $page = $wgRequest->getVal('page', 1);
     $showall = $wgRequest->getText('showall', false);
     $commentingAllowed = true;
     $result = array('error' => 1);
     $title = Title::newFromID($articleId);
     if (!$title) {
         return $result;
     }
     if (defined('NS_BLOG_ARTICLE') && $title->getNamespace() == NS_BLOG_ARTICLE) {
         $props = BlogArticle::getProps($title->getArticleID());
         $commentingAllowed = isset($props['commenting']) ? (bool) $props['commenting'] : true;
     }
     if (!$commentingAllowed) {
         return $result;
     }
     $response = ArticleComment::doPost(self::getConvertedContent($wgRequest->getVal('wpArticleComment')), $wgUser, $title, $parentId);
     if ($response !== false) {
         if ($title->getNamespace() == NS_USER_TALK && $response[0] == EditPage::AS_SUCCESS_NEW_ARTICLE && $title->getText() != $wgUser->getName()) {
             $user = User::newFromName($title->getText());
             if ($user) {
                 $user->setNewtalk(true);
             }
         }
         $listing = ArticleCommentList::newFromTitle($title);
         $countAll = $wgLang->formatNum($listing->getCountAllNested());
         $commentsHTML = $response[2]['text'];
         $result = array('text' => $commentsHTML, 'counter' => $countAll);
         if ($parentId) {
             $result['parentId'] = $parentId;
         }
         return $result;
     }
     return $result;
 }