public static function ArticleCommentCheck($title = null)
 {
     global $wgRequest, $wgUser;
     wfProfileIn(__METHOD__);
     if ($title === null) {
         global $wgTitle;
         $title = $wgTitle;
     }
     if (is_null(self::$enable) && !empty($title)) {
         self::$enable = self::ArticleCommentCheckTitle($title);
         if (self::$enable && !is_null($wgRequest->getVal('diff'))) {
             self::$enable = false;
         }
         $action = $wgRequest->getVal('action', 'view');
         if (self::$enable && $action == 'purge' && $wgUser->isAnon() && !$wgRequest->wasPosted()) {
             self::$enable = false;
         }
         if (self::$enable && $action != 'view' && $action != 'purge') {
             self::$enable = false;
         }
         if (self::$enable && !wfRunHooks('ArticleCommentCheck', array($title))) {
             self::$enable = false;
         }
     }
     wfProfileOut(__METHOD__);
     return self::$enable;
 }
 /**
  * axReply -- static hook/entry for ajax request post -- reply a comment
  *
  * @static
  * @access public
  *
  * @return String -- html -> textarea
  */
 public static function axReply()
 {
     global $wgRequest, $wgStylePath;
     $articleId = $wgRequest->getVal('article', false);
     $commentId = $wgRequest->getVal('id', false);
     $result = array('id' => $commentId);
     $title = Title::newFromID($articleId);
     if (!$title) {
         $result['error'] = 1;
         return $result;
     }
     $canComment = ArticleCommentInit::userCanComment($result, $title);
     if ($canComment == true) {
         $articleId = $wgRequest->getVal('article', false);
         $vars = array('commentId' => $commentId, 'isMiniEditorEnabled' => ArticleComment::isMiniEditorEnabled(), 'stylePath' => $wgStylePath);
         $result['html'] = F::app()->getView('ArticleComments', 'Reply', $vars)->render();
     }
     return $result;
 }
 public static function getCommentByAnonMsg()
 {
     if (is_null(self::$commentByAnonMsg)) {
         self::$commentByAnonMsg = wfMessage('article-comments-anonymous')->text();
     }
     return self::$commentByAnonMsg;
 }
 /**
  * doSaveComment -- save comment
  *
  * @access public
  *
  * @return Array or false on error. - TODO: Document what the array contains.
  */
 public function doSaveComment($text, $user, $title = null, $commentId = 0, $force = false, $summary = '')
 {
     global $wgMemc, $wgTitle;
     wfProfileIn(__METHOD__);
     $this->load(true);
     if ($force || $this->canEdit() && !ArticleCommentInit::isFbConnectionNeeded()) {
         if (wfReadOnly()) {
             wfProfileOut(__METHOD__);
             return false;
         }
         if (!$text || !strlen($text)) {
             wfProfileOut(__METHOD__);
             return false;
         }
         if (empty($this->mTitle) && !$commentId) {
             wfProfileOut(__METHOD__);
             return false;
         }
         $commentTitle = $this->mTitle ? $this->mTitle : Title::newFromId($commentId);
         /**
          * because we save different title via Ajax request
          */
         $wgTitle = $commentTitle;
         /**
          * add article using EditPage class (for hooks)
          */
         $article = new Article($commentTitle, intval($this->mLastRevId));
         $retval = self::doSaveAsArticle($text, $article, $user, $this->mMetadata, $summary);
         if (!empty($title)) {
             $key = $title->getPrefixedDBkey();
         } else {
             $key = $this->mTitle->getPrefixedDBkey();
             $explode = $this->explode($key);
             $key = $explode['title'];
         }
         $wgMemc->delete(wfMemcKey('articlecomment', 'comm', $key, 'v1'));
         $res = array($retval, $article);
     } else {
         $res = false;
     }
     $this->mLastRevId = $this->mTitle->getLatestRevID(Title::GAID_FOR_UPDATE);
     $this->mLastRevision = Revision::newFromId($this->mLastRevId);
     wfProfileOut(__METHOD__);
     return $res;
 }
 /**
  * Are article comments enabled for context title?
  */
 private function checkArticleComments()
 {
     $this->isArticleComments = class_exists('ArticleComment') && ArticleCommentInit::ArticleCommentCheckTitle($this->contextTitle);
     return $this->isArticleComments;
 }
 /**
  * getData -- return raw data for displaying commentList
  *
  * @access public
  *
  * @return array data for comments list
  */
 public function getData($page = 1)
 {
     global $wgUser, $wgTitle, $wgStylePath;
     $groups = $wgUser->getEffectiveGroups();
     //$isSysop = in_array('sysop', $groups) || in_array('staff', $groups);
     $canEdit = $wgUser->isAllowed('edit');
     $isBlocked = $wgUser->isBlocked();
     $isReadOnly = wfReadOnly();
     //$showall = $wgRequest->getText( 'showall', false );
     //default to using slave. comments are posted with ajax which hits master db
     //$commentList = $this->getCommentList(false);
     $countComments = $this->getCountAll();
     $countCommentsNested = $this->getCountAllNested();
     $countPages = ceil($countComments / $this->mMaxPerPage);
     $pageRequest = (int) $page;
     $page = 1;
     if ($pageRequest <= $countPages && $pageRequest > 0) {
         $page = $pageRequest;
     }
     $comments = $this->getCommentPages(false, $page);
     $pagination = $this->doPagination($countComments, count($comments), $page);
     $commentListHTML = '';
     if (!empty($wgTitle)) {
         $commentListHTML = F::app()->getView('ArticleComments', 'CommentList', array('commentListRaw' => $comments, 'page' => $page, 'useMaster' => false))->render();
     }
     $commentingAllowed = true;
     if (defined('NS_BLOG_ARTICLE') && $wgTitle && $wgTitle->getNamespace() == NS_BLOG_ARTICLE) {
         $props = BlogArticle::getProps($wgTitle->getArticleID());
         $commentingAllowed = isset($props['commenting']) ? (bool) $props['commenting'] : true;
     }
     $retVal = array('avatar' => AvatarService::renderAvatar($wgUser->getName(), 50), 'userurl' => AvatarService::getUrl($wgUser->getName()), 'canEdit' => $canEdit, 'commentListRaw' => $comments, 'commentListHTML' => $commentListHTML, 'commentingAllowed' => $commentingAllowed, 'commentsPerPage' => $this->mMaxPerPage, 'countComments' => $countComments, 'countCommentsNested' => $countCommentsNested, 'isAnon' => $wgUser->isAnon(), 'isBlocked' => $isBlocked, 'isFBConnectionProblem' => ArticleCommentInit::isFbConnectionNeeded(), 'isReadOnly' => $isReadOnly, 'page' => $page, 'pagination' => $pagination, 'reason' => $isBlocked ? $this->blockedPage() : '', 'stylePath' => $wgStylePath, 'title' => $wgTitle);
     return $retVal;
 }
 /**
  * Get number of article comments for current page (if enabled) or get number of revisions of talk page
  */
 public function getCommentsCount()
 {
     wfProfileIn(__METHOD__);
     global $wgMemc;
     if (!is_null($this->mTitle)) {
         $title = $this->mTitle;
     } else {
         $title = Title::newFromId($this->pageId);
     }
     // don't perform for talk pages or special pages
     if (empty($title) || $title->isTalkPage() || $title->isSpecialPage()) {
         wfProfileOut(__METHOD__);
         return 0;
     }
     // try to get cached data
     $key = $this->getKey('comments6');
     $ret = $wgMemc->get($key);
     if (!is_numeric($ret)) {
         wfProfileIn(__METHOD__ . '::miss');
         // new comments extension
         if (self::isArticleCommentsEnabled() && ArticleCommentInit::ArticleCommentCheckTitle($title)) {
             // get number of article comments
             $commentList = ArticleCommentList::newFromTitle($title);
             $data = $commentList->getData();
             $ret = $data['countCommentsNested'];
             wfDebug(__METHOD__ . "::miss - using comments count\n");
         } else {
             // get number of revisions of talk page
             $talkPage = $title->getTalkPage();
             // check if talk page exists
             if (!empty($talkPage) && $talkPage->exists()) {
                 $dbr = wfGetDB(DB_SLAVE);
                 $ret = $dbr->selectField('revision', 'count(*)', array('rev_page' => $talkPage->getArticleId()), __METHOD__);
             } else {
                 $ret = 0;
             }
             wfDebug(__METHOD__ . "::miss - using talk page revisions count\n");
         }
         $wgMemc->set($key, $ret, self::CACHE_TTL);
         wfProfileOut(__METHOD__ . '::miss');
     }
     wfProfileOut(__METHOD__);
     return intval($ret);
 }
 public static function onBeforePageDisplay(OutputPage &$out, Skin &$skin)
 {
     if (class_exists('ArticleCommentInit') && ArticleCommentInit::ArticleCommentCheck()) {
         $app = F::app();
         // This is the actual entry point for Article Comment generation
         self::$content = $app->sendRequest('ArticleComments', 'index');
         // Load MiniEditor assets (oasis skin only)
         if (ArticleComment::isMiniEditorEnabled()) {
             $app->sendRequest('MiniEditor', 'loadAssets', array('loadStyles' => !ArticleComment::isLoadingOnDemand(), 'loadOnDemand' => true, 'loadOnDemandAssets' => array('/extensions/wikia/MiniEditor/js/Wall/Wall.Animations.js')));
         }
     }
     return true;
 }