protected function afterArticleInitialize($mode, $title, $article) { if ($mode == self::MODE_EDIT) { $aPageProps = BlogArticle::getProps($article->getId()); $this->mFormData['isCommentingEnabled'] = empty($aPageProps['commenting']) ? 0 : $aPageProps['commenting']; $isAllowed = $this->user->isAllowed("blog-articles-edit"); if (strtolower($this->user->getName()) != strtolower(BlogArticle::getOwner($title)) && !$isAllowed) { $this->titleStatus = self::STATUS_BLOG_PERMISSION_DENIED; $this->addEditNotice(wfMsg('create-blog-permission-denied')); } } else { $this->mFormData['isCommentingEnabled'] = true; } }
/** * getProps -- get props for comment article * */ public function getProps() { if ((!$this->mProps || !is_array($this->mProps)) && class_exists('BlogArticle')) { $this->mProps = BlogArticle::getProps($this->mTitle->getArticleID()); } return $this->mProps; }
/** * 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; }
private function parseArticle($sTitle) { global $wgParser, $wgContLang; $oTitle = Title::newFromText($sTitle, NS_BLOG_ARTICLE); $oArticle = new Article($oTitle, 0); // macbre: RT #37120 $sArticleBody = $oTitle->exists() ? $oArticle->getContent() : ''; $aPageProps = BlogArticle::getProps($oArticle->getId()); $aTitleParts = explode('/', $oTitle->getText(), 2); $this->mFormData['postId'] = $oArticle->getId(); $this->mFormData['postTitle'] = $aTitleParts[1]; $this->mFormData['postBody'] = trim(preg_replace('/\\[\\[' . $wgContLang->getFormattedNsText(NS_CATEGORY) . ':(.*)\\]\\]/siU', '', $sArticleBody)); $this->mFormData['postBody'] = $sArticleBody; $this->mFormData['isVotingEnabled'] = isset($aPageProps['voting']) ? $aPageProps['voting'] : 0; $this->mFormData['isCommentingEnabled'] = isset($aPageProps['commenting']) ? $aPageProps['commenting'] : 0; $this->mFormData['isExistingArticleEditAllowed'] = 1; //create EditPage object $this->createEditPage($this->mFormData['postBody']); // CategorySelect compatibility (restore categories from article body) if ($this->mCategorySelectEnabled) { CategorySelectReplaceContent($this->mEditPage, $this->mEditPage->textbox1); } return $oArticle; }
public function executeIndex() { $this->wf->ProfileIn(__METHOD__); $this->response->setVal('render', true); if (class_exists('ArticleCommentInit') && ArticleCommentInit::ArticleCommentCheck()) { $isMobile = $this->app->checkSkin('wikiamobile'); if (defined('NS_BLOG_ARTICLE') && $this->wg->Title->getNamespace() == NS_BLOG_ARTICLE) { $props = BlogArticle::getProps($this->wg->Title->getArticleID()); $commentingAllowed = isset($props['commenting']) ? (bool) $props['commenting'] : true; if (!$commentingAllowed) { $this->response->setVal('render', false); } } // 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'); } } } } $this->wf->ProfileOut(__METHOD__); }
private static function __getResults() { global $wgLang; wfProfileIn(__METHOD__); /* main query */ $aResult = array(); $aFields = array('/* BLOGS */ rev_page as page_id', 'page_namespace', 'page_title', 'min(rev_timestamp) as create_timestamp', 'unix_timestamp(rev_timestamp) as timestamp', 'rev_timestamp', 'min(rev_id) as rev_id', 'rev_user'); $res = self::$dbr->select(array_map(array(self::$dbr, 'tableName'), self::$aTables), $aFields, self::$aWhere, __METHOD__, self::__makeDBOrder()); while ($oRow = self::$dbr->fetchObject($res)) { if (class_exists('ArticleCommentList')) { $oComments = ArticleCommentList::newFromText($oRow->page_title, $oRow->page_namespace); $iCount = $oComments ? $oComments->getCountAllNested() : 0; } else { $iCount = 0; } /* username */ $oTitle = Title::newFromText($oRow->page_title, $oRow->page_namespace); $sUsername = ""; if (!$oTitle instanceof Title) { continue; } $username = BlogArticle::getOwner($oTitle); $oRevision = Revision::newFromTitle($oTitle); $aResult[$oRow->page_id] = array("page" => $oRow->page_id, "namespace" => $oRow->page_namespace, "title" => $oRow->page_title, "page_touched" => !is_null($oRevision) ? $oRevision->getTimestamp() : $oTitle->getTouched(), "rev_timestamp" => $oRow->rev_timestamp, "timestamp" => $oRow->timestamp, "username" => isset($username) ? $username : "", "text" => self::__getRevisionText($oRow->page_id, $oRevision), "revision" => $oRow->rev_id, "comments" => $iCount, "votes" => '', "props" => BlogArticle::getProps($oRow->page_id)); // Sort by comment count for popular blog posts module if (isset(self::$aOptions['order']) && self::$aOptions['order'] == 'page_id') { uasort($aResult, array("BlogTemplateClass", "__sortByCommentCount")); } // We may need to query for 50 results but display 5 if (isset(self::$aOptions['displaycount']) && self::$aOptions['displaycount'] != self::$aOptions['count']) { $aResult = array_slice($aResult, 0, self::$aOptions['displaycount']); } } // macbre: change for Oasis to add avatars and comments / likes data wfRunHooks('BlogTemplateGetResults', array(&$aResult)); self::$dbr->freeResult($res); wfProfileOut(__METHOD__); return $aResult; }
/** * 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; }