function testPageStatsService() { global $wgTitle, $wgMemc; $wgTitle = Title::newMainPage(); $articleId = $wgTitle->getArticleId(); $article = Article::newFromId($articleId); $key = wfMemcKey('services', 'pageheader', 'current-revision', $articleId); // macbre: perform this test only for existing pages if (!$wgTitle->exists()) { $this->markTestSkipped('Main page cannot be found'); return; } $service = new PageStatsService($articleId); $this->assertType('array', $service->getMostLinkedCategories()); $this->assertType('int', $service->getCommentsCount()); $this->assertType('int', $service->getLikesCount()); $this->assertType('array', $service->getCurrentRevision()); $this->assertType('array', $service->getPreviousEdits()); $this->assertType('string', $service->getFirstRevisionTimestamp()); // comments counter regenerating $comments = $service->getCommentsCount(); $service->regenerateCommentsCount(); $this->assertEquals($comments, $service->getCommentsCount()); // remove cached stats when article is edited $user = $flags = $status = false; PageStatsService::onArticleSaveComplete($article, $user, false, false, false, false, false, $flags, false, $status, false); $data = $wgMemc->get($key); $this->assertTrue(empty($data)); $service->getCurrentRevision(); $data = $wgMemc->get($key); $this->assertFalse(empty($data)); // remove cached stats when article (comment) is deleted PageStatsService::onArticleDeleteComplete($article, $user, false, $articleId); $data = $wgMemc->get($key); $this->assertTrue(empty($data)); $service->getCurrentRevision(); // regenerate data $service->regenerateData(); $data = $wgMemc->get($key); $this->assertTrue(empty($data)); }
/** * Render header for blog post */ public function executeBlogPost() { wfProfileIn(__METHOD__); global $wgTitle, $wgLang, $wgOut; // remove User_blog:xxx from title $titleParts = explode('/', $wgTitle->getText()); array_shift($titleParts); $this->title = implode('/', $titleParts); // get user name to display in header $this->userName = self::getUserName($wgTitle, BodyController::getUserPagesNamespaces()); // render avatar (48x48) $this->avatar = AvatarService::renderAvatar($this->userName, 48); // link to user page $this->userPage = AvatarService::getUrl($this->userName); if ($this->wg->EnableBlogArticles) { // link to user blog page $this->userBlogPage = AvatarService::getUrl($this->userName, NS_BLOG_ARTICLE); // user blog page message $this->userBlogPageMessage = wfMessage('user-blog-url-link', $this->userName)->inContentLanguage()->parse(); } if (!empty($this->wg->EnableGoogleAuthorInfo) && !empty($this->wg->GoogleAuthorLinks) && array_key_exists($this->userName, $this->wg->GoogleAuthorLinks)) { $this->googleAuthorLink = $this->wg->GoogleAuthorLinks[$this->userName] . '?rel=author'; } if ($this->app->wg->Request->getVal('action') == 'history' || $this->app->wg->Request->getCheck('diff')) { $this->navLinks = Wikia::link($this->app->wg->title, wfMsg('oasis-page-header-back-to-article'), array(), array(), 'known'); } // user stats (edit points, account creation date) $this->stats = $this->getStats($this->userName); // commments / likes / date of first edit if (!empty($wgTitle) && $wgTitle->exists()) { $service = new PageStatsService($wgTitle->getArticleId()); $this->editTimestamp = $wgLang->date($service->getFirstRevisionTimestamp()); $this->comments = $service->getCommentsCount(); } $actionMenu = array(); $dropdownActions = array('move', 'protect', 'unprotect', 'delete', 'undelete', 'history'); // edit button / dropdown if (isset($this->content_actions['ve-edit'])) { // new visual editor is enabled $actionMenu['action'] = $this->content_actions['ve-edit']; // add classic editor link to the possible dropdown options array_unshift($dropdownActions, 'edit'); } else { if (isset($this->content_actions['edit'])) { $actionMenu['action'] = $this->content_actions['edit']; } } foreach ($dropdownActions as $action) { if (isset($this->content_actions[$action])) { $actionMenu['dropdown'][$action] = $this->content_actions[$action]; } } $this->actionMenu = $actionMenu; // load CSS for .WikiaUserPagesHeader (BugId:9212, 10246) $wgOut->addStyle(AssetsManager::getInstance()->getSassCommonURL("skins/oasis/css/core/UserPagesHeader.scss")); wfProfileOut(__METHOD__); }
/** * Render header for blog post */ public function executeBlogPost() { wfProfileIn(__METHOD__); global $wgTitle, $wgLang, $wgOut; // remove User_blog:xxx from title $titleParts = explode('/', $wgTitle->getText()); array_shift($titleParts); $this->title = implode('/', $titleParts); // get user name to display in header $this->userName = self::getUserName($wgTitle, BodyController::getUserPagesNamespaces()); // render avatar (48x48) $this->avatar = AvatarService::renderAvatar($this->userName, 48); // link to user page $this->userPage = AvatarService::getUrl($this->userName); // user stats (edit points, account creation date) $this->stats = $this->getStats($this->userName); // commments / likes / date of first edit if (!empty($wgTitle) && $wgTitle->exists()) { $service = new PageStatsService($wgTitle->getArticleId()); $this->editTimestamp = $wgLang->date($service->getFirstRevisionTimestamp()); $this->comments = $service->getCommentsCount(); $this->likes = true; } $actionMenu = array(); // edit button / dropdown if (isset($this->content_actions['edit'])) { $actionMenu['action'] = $this->content_actions['edit']; } // dropdown actions $actions = array('move', 'protect', 'unprotect', 'delete', 'undelete', 'history'); foreach($actions as $action) { if (isset($this->content_actions[$action])) { $actionMenu['dropdown'][$action] = $this->content_actions[$action]; } } $this->actionMenu = $actionMenu; // load CSS for .WikiaUserPagesHeader (BugId:9212, 10246) $wgOut->addStyle(AssetsManager::getInstance()->getSassCommonURL("skins/oasis/css/core/UserPagesHeader.scss")); wfProfileOut(__METHOD__); }