Exemplo n.º 1
0
 /**
  * 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;
 }
 /**
  * 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;
 }