public function getTopParentObj() { $title = $this->getTopParent(); if (empty($title)) { return null; } $title = Title::newFromText($title, $this->mNamespace); if ($title instanceof Title) { $obj = ArticleComment::newFromTitle($title); return $obj; } return null; }
/** * @static * @param Title $title * @param User $user * @param $action * @param $result * @return bool */ public static function userCan($title, $user, $action, &$result) { $namespace = $title->getNamespace(); /** * here we only handle Blog articles, everyone can read it */ if ($namespace != NS_BLOG_ARTICLE && $namespace != NS_BLOG_ARTICLE_TALK) { $result = null; return true; } /** * check if default blog post was passed (BugId:8331) */ if ($namespace == NS_BLOG_ARTICLE && $title->mTextform == '') { return true; } $username = $user->getName(); if ($namespace == NS_BLOG_ARTICLE_TALK && class_exists('ArticleComment')) { $oComment = ArticleComment::newFromTitle($title); // $oComment->load(); $canEdit = $oComment->canEdit(); $isOwner = (bool) ($canEdit && !in_array($action, array('watch', 'protect'))); $isArticle = false; //if this is TALK it is not article } else { $owner = BlogArticle::getOwner($title); $isOwner = (bool) ($username == $owner); $isArticle = (bool) ($namespace == NS_BLOG_ARTICLE); } /** * returned values */ $result = array(); $return = false; switch ($action) { case "move": case "move-target": if ($isArticle && ($user->isAllowed("blog-articles-move") || $isOwner)) { $result = true; $return = true; } break; case "read": $result = true; $return = true; break; /** * creating permissions: * -- article can be created only by blog owner * -- comment can be created by everyone */ /** * creating permissions: * -- article can be created only by blog owner * -- comment can be created by everyone */ case "create": if ($isArticle) { $return = $username == $owner; $result = $username == $owner; } else { $result = true; $return = true; } break; /** * edit permissions -- owner of blog and one who has * "blog-articles-edit" permission */ /** * edit permissions -- owner of blog and one who has * "blog-articles-edit" permission */ case "edit": if ($isArticle && ($user->isAllowed("blog-articles-edit") || $isOwner)) { $result = true; $return = true; } break; case "delete": if (!$isArticle && $user->isAllowed("blog-comments-delete")) { $result = true; $return = true; } if ($user->isAllowed('delete')) { $result = true; $return = true; } break; case "protect": if ($isArticle && $user->isAllowed("blog-articles-protect")) { $result = true; $return = true; } break; case "autopatrol": case "patrol": $result = true; $return = true; break; default: /** * for other actions we demand that user has to be logged in */ if ($user->isAnon()) { $result = array("{$action} is forbidden for anon user"); $return = false; } else { if (isset($owner) && $username != $owner) { $result = array(); } $return = isset($owner) && $username == $owner; } } return $return; }
$range = 1000; $sqlWhere = array('page_id > ' . $fromId, 'page_id <= ' . $toId); $sqlWhere = array_merge($sqlWhereBase, $sqlWhere); // get comment list $result = $db->select(array('page'), array('page_id', 'page_title', 'page_namespace', 'page_len', 'page_is_redirect', 'page_latest'), $sqlWhere, __METHOD__, array('ORDER BY' => 'page_id ASC')); $commentList = array(); while ($row = $db->fetchObject($result)) { $commentList[$row->page_id] = $row; } $db->freeResult($result); // collect and insert data foreach ($commentList as $comment) { $cnt++; echo "{$cnt} [{$fromId}-{$toId}]: ID {$comment->page_id}(NS {$comment->page_namespace}): {$comment->page_title}"; $title = Title::newFromRow($comment); $articleComment = ArticleComment::newFromTitle($title); $articleComment->load(); // parent page id $parentPageId = getParentPage($articleComment); if (empty($parentPageId)) { echo ".....Parent page NOT found.\n"; $failed++; continue; } // get parent comment id $parentCommentObj = $articleComment->getTopParentObj(); if ($parentCommentObj instanceof ArticleComment) { // posts/replies $parentCommentId = $parentCommentObj->getTitle()->getArticleID(); $lastChildCommentId = 0; } else {
/** * @return null|ArticleComment */ protected function getArticleComment() { if (empty($this->articleComment)) { $this->articleComment = ArticleComment::newFromTitle($this->title); } return $this->articleComment; }
/** * getCommentPages -- get the article contents from the list of article pages * * pass false in page parameter to get ALL pages but * try not to defeat the paging, getting ALL articles is expensive */ public function getCommentPages($master = true, $page = 1) { global $wgRequest; //initialize list of comment ids if not done already if ($this->mCommentsAll === false) { $this->getCommentList($master); } $showall = $wgRequest->getText('showall', false); //pagination if ($page !== false && ($showall != 1 || $this->getCountAllNested() > 200)) { $this->mComments = array_slice($this->mCommentsAll, ($page - 1) * $this->mMaxPerPage, $this->mMaxPerPage, true); } else { $this->mComments = $this->mCommentsAll; } $this->mCount = count($this->mComments); $this->mCountNested = 0; // grab list of required article IDs $commentsQueue = array(); foreach ($this->mComments as $id => &$levels) { if (isset($levels['level1'])) { $commentsQueue[] = $id; } if (isset($levels['level2'])) { $commentsQueue = array_merge($commentsQueue, array_keys($levels['level2'])); } } $titles = Title::newFromIds($commentsQueue); $comments = array(); foreach ($titles as $title) { $comments[$title->getArticleID()] = ArticleComment::newFromTitle($title); } // grab article contents for each comment foreach ($this->mComments as $id => &$levels) { if (isset($levels['level1'])) { $levels['level1'] = $comments[$id]; $this->mCountNested++; } if (isset($levels['level2'])) { foreach ($levels['level2'] as $subid => &$sublevel) { $sublevel = $comments[$subid]; $this->mCountNested++; } } } return $this->mComments; }