public function index()
 {
     if (self::$skipRendering) {
         return false;
     }
     $this->response->setTemplateEngine(WikiaResponse::TEMPLATE_ENGINE_MUSTACHE);
     $wg = $this->wg;
     $out = $wg->Out;
     $titleText = $out->getPageTitle();
     $title = $out->getTitle();
     $namespace = $title instanceof Title ? $title->getNamespace() : -1;
     $this->response->setVal('pageTitle', $this->getTitleText($titleText, $namespace));
     $article = $this->wg->Article;
     if ($article instanceof Article) {
         $revision = $article->getPage()->getRevision();
         if ($revision instanceof Revision) {
             $user = User::newFromId($revision->getRawUser());
             $userName = $user->getName();
             if (User::isIP($userName)) {
                 //For anonymous users don't display IP
                 $userName = wfMessage('wikiamobile-anonymous-edited-by')->text();
             } else {
                 //Wrap username in a link to user page
                 $userName = "******";
             }
             $this->response->setVal('lastEditedOn', wfMessage('wikiamobile-last-edited-on')->params($this->wg->Lang->date($revision->getTimestamp()))->text());
             $this->response->setVal('lastEditedBy', wfMessage('wikiamobile-last-edited-by')->params($userName)->text());
         }
     }
     if ($wg->EnableArticleCommentsExt && in_array($title->getNamespace(), $wg->ContentNamespaces) && !$wg->Title->isMainPage() && $wg->request->getVal('action', 'view') == 'view') {
         $numberOfComments = ArticleCommentList::newFromTitle($title)->getCountAllNested();
         $this->response->setVal('commentCounter', wfMessage('wikiamobile-article-comments-counter')->params($numberOfComments)->text());
     }
     $this->response->setVal('editLink', $this->getTitleEditUrl());
     if ($namespace == NS_CATEGORY) {
         $this->response->setVal('categoryPage', wfMessage('wikiamobile-categories-tagline')->inContentLanguage()->plain());
     }
     return true;
 }
Beispiel #2
0
 private static function getCsvText($title)
 {
     global $wgMemc, $wgCityId;
     $memkey = __METHOD__ . ":" . $wgCityId . ":" . $title->getPrefixedText();
     $cached = $wgMemc->get($memkey);
     if (empty($cached)) {
         $articleC = ArticleCommentList::newFromTitle($title);
         $comments = $articleC->getCommentPages(false, false);
         $csvArr = array(array('timestamp', 'username', 'comment', 'URL', 'reply to'));
         foreach ($comments as $commentArr) {
             if (isset($commentArr['level1']) && $commentArr['level1'] instanceof ArticleComment) {
                 $comment = $commentArr['level1']->getData(false);
                 $csvArr[] = array($comment['rawtimestamp'], $comment['username'], $comment['rawtext'], $commentArr['level1']->getTitle()->getFullURL());
             }
             if (isset($commentArr['level2'])) {
                 foreach ($commentArr['level2'] as $commentId => $reply) {
                     if ($reply instanceof ArticleComment) {
                         $commentReply = $reply->getData(false);
                         $csvArr[] = array($commentReply['rawtimestamp'], $commentReply['username'], $commentReply['rawtext'], $reply->getTitle()->getFullURL(), $commentArr['level1']->getTitle()->getFullURL());
                     }
                 }
             }
         }
         $csvHandle = fopen('php://temp', 'w');
         foreach ($csvArr as $fields) {
             fputcsv($csvHandle, $fields);
         }
         rewind($csvHandle);
         $csvText = stream_get_contents($csvHandle);
         fclose($csvHandle);
         $wgMemc->set($memkey, $csvText, 60 * 60);
     } else {
         $csvText = $cached;
     }
     return $csvText;
 }
 /**
  * axGetComments -- static hook/entry for ajax request for pagination
  *
  * @static
  * @access public
  *
  * @return String - HTML
  */
 static function axGetComments()
 {
     global $wgRequest, $wgTitle;
     $page = $wgRequest->getVal('page', false);
     $articleId = $wgRequest->getVal('article', false);
     $wgTitle = Title::newFromID($articleId);
     $error = 0;
     $text = $pagination = '';
     $method = 'CommentList';
     $isMobile = F::app()->checkSkin('wikiamobile');
     if ($isMobile) {
         $method = 'WikiaMobile' . $method;
     } elseif (F::app()->checkSkin('venus')) {
         $method = 'Venus' . $method;
     }
     $title = Title::newFromID($articleId);
     if (!$title) {
         $error = 1;
     } else {
         $listing = ArticleCommentList::newFromTitle($title);
         $comments = $listing->getCommentPages(false, $page);
         $text = F::app()->getView('ArticleComments', $method, array('commentListRaw' => $comments, 'page' => $page, 'useMaster' => false))->render();
         $pagination = !$isMobile ? $listing->doPagination($listing->getCountAll(), count($comments), $page === false ? 1 : $page, $title) : '';
     }
     $result = array('error' => $error, 'text' => $text, 'pagination' => $pagination);
     return $result;
 }
 protected function getArticlesDetails($articleIds, $articleKeys = [], $width = 0, $height = 0, $abstract = 0, $strict = false)
 {
     $articles = is_array($articleIds) ? $articleIds : [$articleIds];
     $ids = [];
     $collection = [];
     $resultingCollectionIds = [];
     $titles = [];
     foreach ($articles as $i) {
         //data is cached on a per-article basis
         //to avoid one article requiring purging
         //the whole collection
         $cache = $this->wg->Memc->get(self::getCacheKey($i, self::DETAILS_CACHE_ID));
         if (!is_array($cache)) {
             $ids[] = $i;
         } else {
             $collection[$i] = $cache;
             $resultingCollectionIds[] = $i;
         }
     }
     if (count($ids) > 0) {
         $titles = Title::newFromIDs($ids);
     }
     if (!empty($articleKeys)) {
         foreach ($articleKeys as $titleKey) {
             $titleObj = Title::newFromDbKey($titleKey);
             if ($titleObj instanceof Title && $titleObj->exists()) {
                 $titles[] = $titleObj;
             }
         }
     }
     if (!empty($titles)) {
         foreach ($titles as $t) {
             $fileData = [];
             if ($t->getNamespace() == NS_FILE) {
                 $fileData = $this->getFromFile($t->getText());
             } elseif ($t->getNamespace() == NS_MAIN) {
                 $fileData = ['type' => static::ARTICLE_TYPE];
             } elseif ($t->getNamespace() == NS_CATEGORY) {
                 $fileData = ['type' => static::CATEGORY_TYPE];
             }
             $id = $t->getArticleID();
             $revId = $t->getLatestRevID();
             $rev = Revision::newFromId($revId);
             if (!empty($rev)) {
                 $collection[$id] = ['id' => $id, 'title' => $t->getText(), 'ns' => $t->getNamespace(), 'url' => $t->getLocalURL(), 'revision' => ['id' => $revId, 'user' => $rev->getUserText(Revision::FOR_PUBLIC), 'user_id' => $rev->getUser(Revision::FOR_PUBLIC), 'timestamp' => wfTimestamp(TS_UNIX, $rev->getTimestamp())]];
                 $collection[$id]['comments'] = class_exists('ArticleCommentList') ? ArticleCommentList::newFromTitle($t)->getCountAllNested() : false;
                 //add file data
                 $collection[$id] = array_merge($collection[$id], $fileData);
                 $resultingCollectionIds[] = $id;
                 $this->wg->Memc->set(self::getCacheKey($id, self::DETAILS_CACHE_ID), $collection[$id], 86400);
             } else {
                 $dataLog = ['titleText' => $t->getText(), 'articleId' => $t->getArticleID(), 'revId' => $revId];
                 WikiaLogger::instance()->info('No revision found for article', $dataLog);
             }
         }
         $titles = null;
     }
     //ImageServing has separate caching
     //so processing it separately allows to
     //make the thumbnail's size parametrical without
     //invalidating the titles details' cache
     //or the need to duplicate it
     $thumbnails = $this->getArticlesThumbnails($resultingCollectionIds, $width, $height);
     $articles = null;
     //ArticleService has separate caching
     //so processing it separately allows to
     //make the length parametrical without
     //invalidating the titles details' cache
     //or the need to duplicate it
     foreach ($collection as $id => &$details) {
         if ($abstract > 0) {
             $as = new ArticleService($id);
             $snippet = $as->getTextSnippet($abstract);
         } else {
             $snippet = null;
         }
         $details['abstract'] = $snippet;
         if (isset($thumbnails[$id])) {
             $details = array_merge($details, $thumbnails[$id]);
         }
     }
     $collection = $this->appendMetadata($collection);
     $thumbnails = null;
     //The collection can be in random order (depends if item was found in memcache or not)
     //lets preserve original order even if we are not using strict mode:
     //to keep things consistent over time (some other APIs that are using sorted results are using
     //ArticleApi::getDetails to fetch info about articles)
     $orderedIdsFromTitles = array_diff(array_keys($collection), $articleIds);
     //typecasting to convert falsy values into empty array (array_merge require arrays only)
     $orderedIds = array_merge((array) $articleIds, (array) $orderedIdsFromTitles);
     $collection = $this->preserveOriginalOrder($orderedIds, $collection);
     //if strict - return array instead of associative array (dict)
     if ($strict) {
         return array_values($collection);
     } else {
         return $collection;
     }
 }
 public static function ArticleCommentEnable(&$data)
 {
     global $wgTitle;
     $skin = RequestContext::getMain()->getSkin();
     //use this hook only for skins other than Monaco
     //update: it's actually only MonoBook since Oasis and WikiaMobile use their own
     //logic and the other mobile skins do not show comments-related stuff
     if ($skin instanceof SkinMonoBook) {
         wfProfileIn(__METHOD__);
         if (self::ArticleCommentCheck()) {
             $page = ArticleCommentList::newFromTitle($wgTitle);
             $data = $page->render();
         }
         wfProfileOut(__METHOD__);
     }
     return true;
 }
 /**
  * hook
  *
  * @access public
  * @static
  *
  * @param $form MovePageForm
  * @param $oOldTitle Title
  * @param $oNewTitle Title
  */
 public static function moveComments(&$form, &$oOldTitle, &$oNewTitle)
 {
     global $wgUser, $wgRC2UDPEnabled, $wgMaxCommentsToMove, $wgEnableMultiDeleteExt, $wgCityId;
     wfProfileIn(__METHOD__);
     if (!$wgUser->isAllowed('move')) {
         wfProfileOut(__METHOD__);
         return true;
     }
     if ($wgUser->isBlocked()) {
         wfProfileOut(__METHOD__);
         return true;
     }
     $commentList = ArticleCommentList::newFromTitle($oOldTitle);
     $comments = $commentList->getCommentPages(true, false);
     if (count($comments)) {
         $mAllowTaskMove = false;
         if (isset($wgMaxCommentsToMove) && $wgMaxCommentsToMove > 0 && !empty($wgEnableMultiDeleteExt)) {
             $mAllowTaskMove = true;
         }
         $irc_backup = $wgRC2UDPEnabled;
         //backup
         $wgRC2UDPEnabled = false;
         //turn off
         $finish = $moved = 0;
         $comments = array_values($comments);
         foreach ($comments as $id => $aCommentArr) {
             /**
              * @var $oCommentTitle Title
              */
             $oCommentTitle = $aCommentArr['level1']->getTitle();
             # move comment level #1
             $error = self::moveComment($oCommentTitle, $oNewTitle, $form->reason);
             if ($error !== true) {
                 Wikia::log(__METHOD__, 'movepage', 'cannot move blog comments: old comment: ' . $oCommentTitle->getPrefixedText() . ', ' . 'new comment: ' . $oNewTitle->getPrefixedText() . ', error: ' . @implode(', ', $error));
             } else {
                 $moved++;
             }
             if (isset($aCommentArr['level2'])) {
                 foreach ($aCommentArr['level2'] as $oComment) {
                     /**
                      * @var $oComment ArticleComment
                      * @var $oCommentTitle Title
                      */
                     $oCommentTitle = $oComment->getTitle();
                     # move comment level #2
                     $error = self::moveComment($oCommentTitle, $oNewTitle, $form->reason);
                     if ($error !== true) {
                         Wikia::log(__METHOD__, 'movepage', 'cannot move blog comments: old comment: ' . $oCommentTitle->getPrefixedText() . ', ' . 'new comment: ' . $oNewTitle->getPrefixedText() . ', error: ' . @implode(', ', $error));
                     } else {
                         $moved++;
                     }
                 }
             }
             if ($mAllowTaskMove && $wgMaxCommentsToMove < $moved) {
                 $finish = $id;
                 break;
             }
         }
         # rest comments move to task
         if ($finish > 0 && $finish < count($comments)) {
             $taskParams = array('wikis' => '', 'reason' => $form->reason, 'lang' => '', 'cat' => '', 'selwikia' => $wgCityId, 'user' => self::MOVE_USER);
             for ($i = $finish + 1; $i < count($comments); $i++) {
                 $aCommentArr = $comments[$i];
                 $oCommentTitle = $aCommentArr['level1']->getTitle();
                 self::addMoveTask($oCommentTitle, $oNewTitle, $taskParams);
                 if (isset($aCommentArr['level2'])) {
                     foreach ($aCommentArr['level2'] as $oComment) {
                         $oCommentTitle = $oComment->getTitle();
                         self::addMoveTask($oCommentTitle, $oNewTitle, $taskParams);
                     }
                 }
             }
         }
         $wgRC2UDPEnabled = $irc_backup;
         //restore to whatever it was
         $listing = ArticleCommentList::newFromTitle($oNewTitle);
         $listing->purge();
     } else {
         Wikia::log(__METHOD__, 'movepage', 'cannot move article comments, because no comments: ' . $oOldTitle->getPrefixedText());
     }
     wfProfileOut(__METHOD__);
     return true;
 }
 private static function getPageForComment($title, $id)
 {
     $page = 0;
     $articleComment = ArticleCommentList::newFromTitle($title);
     $commentList = $articleComment->getCommentList(false);
     $topLevel = array_keys($commentList);
     $found = array_search($id, $topLevel);
     if ($found !== false) {
         $page = ceil(($found + 1) / $articleComment->mMaxPerPage);
     } else {
         // not found in top level comments so we have to search 2nd level comments
         $index = 0;
         foreach ($commentList as $comment) {
             $index++;
             if (isset($comment['level2'])) {
                 $found = array_search($id, $comment['level2']);
                 if ($found !== false) {
                     $page = ceil($index / $articleComment->mMaxPerPage);
                 }
             }
         }
     }
     return $page;
 }
 /**
  * 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);
 }
 private function getCommentsData(Title $title, $page, $perPage = null, $filterid = null)
 {
     wfProfileIn(__METHOD__);
     $key = implode('_', array($title->getArticleID(), $page, $perPage, $filterid));
     $data = null;
     // avoid going through all this when calling the method from the same round trip for the same paramenters
     // the real DB stuff is cached by ArticleCommentList in Memcached
     if (empty($this->dataLoaded[$key])) {
         $commentList = ArticleCommentList::newFromTitle($title);
         if (!empty($perPage)) {
             $commentList->setMaxPerPage($perPage);
         }
         if (!empty($filterid)) {
             $commentList->setId($filterid);
         }
         $data = $commentList->getData($page);
         $this->dataLoaded[$key] = $data;
     } else {
         $data = $this->dataLoaded[$key];
     }
     if (empty($data)) {
         // Seems like we should always have data, let's leave a log somewhere if this happens
         Wikia::log(__METHOD__, false, 'No data, this should not happen.');
     }
     $this->ajaxicon = $this->wg->StylePath . '/common/images/ajax.gif';
     $this->pagesCount = $data['commentsPerPage'] > 0 ? ceil($data['countComments'] / $data['commentsPerPage']) : 0;
     $this->response->setValues($data);
     wfProfileOut(__METHOD__);
     return $data;
 }
Beispiel #10
0
 public static function haveMsg($user)
 {
     $title = Title::newFromText($user->getName(), NS_USER_WALL);
     $comments = ArticleCommentList::newFromTitle($title);
     return $comments->getCountAll() > 0;
 }
 protected function getCommentsNumber($item)
 {
     $titles = Title::newFromIDs($item['pageid']);
     if (empty($titles)) {
         return null;
     }
     $title = $titles[0];
     if (class_exists('ArticleCommentList')) {
         $commentsList = ArticleCommentList::newFromTitle($title);
         return $commentsList->getCountAllNested();
     }
     return null;
 }
Beispiel #12
0
 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;
 }
Beispiel #13
0
 /**
  * @author Jakub Kurcek
  * @param format string 'rss' or 'atom'
  *
  */
 private function FeedRecentBlogComments($format)
 {
     global $wgEnableBlogArticles, $wgParser, $wgUser, $wgServer, $wgOut, $wgExtensionsPath, $wgRequest;
     if (empty($wgEnableBlogArticles)) {
         $this->showMenu();
     } else {
         // local settings
         $maxNumberOfBlogComments = 10;
         $userAvatarSize = 48;
         $sBlogPost = $wgRequest->getText("blogpost", false);
         $oTitle = Title::newFromText($sBlogPost, 500);
         if ($oTitle->getArticleID() > 0) {
             $articleCommentList = ArticleCommentList::newFromTitle($oTitle);
             $articleCommentList->newFromTitle($oTitle);
             $aCommentPages = $articleCommentList->getCommentPages();
             $counter = $maxNumberOfBlogComments;
             $feedArray = array();
             foreach ($aCommentPages as $commentPage) {
                 if ($maxNumberOfBlogComments-- == 0) {
                     break;
                 }
                 $tmpArticleComment = $commentPage['level1']->getData();
                 $feedArray[] = array('title' => '', 'description' => $tmpArticleComment['text'], 'url' => $oTitle->getFullURL(), 'date' => $commentPage['level1']->mFirstRevision->getTimestamp(), 'author' => $tmpArticleComment['author']->getName(), 'otherTags' => array('image' => AvatarService::getAvatarUrl($commentPage['level1']->mUser->getName(), $userAvatarSize)));
             }
             $this->showFeed($format, wfMsg('feed-title-blogcomments', $oTitle->getFullText()), $feedArray);
         } else {
             $oTmpl = new EasyTemplate(dirname(__FILE__) . "/templates/");
             $oTmpl->set_vars(array("blogPostName" => $sBlogPost));
             $wgOut->addHTML($oTmpl->render("error-page-blog-comments"));
         }
     }
 }
Beispiel #14
0
 /**
  * @desc Fetch Article comments count
  *
  * @param Title $title - Article title
  * @return integer
  */
 public function articleCommentsCount(Title $title)
 {
     $articleCommentList = new ArticleCommentList();
     $articleCommentList->setTitle($title);
     return $articleCommentList->getCountAll();
 }