/** * Returns percentile quality of articleId or null if not found * @return int|null */ public function getArticleQuality() { $cacheKey = wfMemcKey(__CLASS__, self::CACHE_BUSTER, $this->articleId); $percentile = $this->app->wg->Memc->get($cacheKey); if ($percentile === false) { $title = Title::newFromID($this->articleId); if ($title === null) { return null; } $article = new Article($title); $parserOutput = $article->getParserOutput(); if (!$parserOutput) { //MAIN-3592 $this->error(__METHOD__, ['message' => 'Article::getParserOutput returned false', 'articleId' => $this->articleId]); return null; } $inputs = ['outbound' => 0, 'inbound' => 0, 'length' => 0, 'sections' => 0, 'images' => 0]; /** * $title->getLinksTo() and $title->getLinksFrom() function are * too expensive to call it here as we want only the number of links */ $inputs['outbound'] = $this->countOutboundLinks($this->articleId); $inputs['inbound'] = $this->countInboundLinks($this->articleId); $inputs['sections'] = count($parserOutput->getSections()); $inputs['images'] = count($parserOutput->getImages()); $inputs['length'] = $this->getCharsCountFromHTML($parserOutput->getText()); $quality = $this->computeFormula($inputs); $percentile = $this->searchPercentile($quality); $this->app->wg->Memc->set($cacheKey, $percentile, self::MEMC_CACHE_TIME); } return $percentile; }
/** * This loads/parses the sub-contents for the in-page header TOC display. * This display shows the H2s and H3s for the current topic. * * @return array */ public function getSubContents() { $sections = array(); if (preg_match('/__NOTOC__/', $this->pArticle->getContent())) { return $sections; } $matches = $this->pArticle->getParserOutput()->getSections(); $h2 = FALSE; $headReference = array(); $headCount = 0; foreach ($matches as $match) { $level = $match['level']; if (!isset($headReference[$match['line']])) { $headReference[$match['line']] = 1; } else { $headReference[$match['line']]++; } // We don't want to include any H3s that don't have an H2 parent if ($level == 2 || $level == 3 && $h2) { if ($level == 2) { $h2 = TRUE; } $headCount = $headReference[$match['line']]; if ($headCount > 1) { $link = '#' . Sanitizer::escapeId(PonyDocsTOC::normalizeSection($match['line']), 'noninitial') . '_' . $headCount; } else { $link = '#' . Sanitizer::escapeId(PonyDocsTOC::normalizeSection($match['line']), 'noninitial'); } $sections[] = array('level' => $level, 'link' => $link, 'text' => $match['line'], 'class' => 'toclevel-' . round($level - 1, 0)); } } return $sections; }
public function index($wallMessagesPerPage = null) { wfProfileIn(__METHOD__); $this->addAsset(); $title = $this->request->getVal('title', $this->app->wg->Title); $page = $this->request->getVal('page', 1); /* for some reason nirvana passes null to this function we need to force default value */ if (empty($wallMessagesPerPage)) { $wallMessagesPerPage = self::DEFAULT_MESSAGES_PER_PAGE; } $this->getThreads($title, $page, $wallMessagesPerPage); $this->response->setVal('type', 'Board'); $this->response->setVal('showNewMessage', true); $this->response->setVal('condenseMessage', true); $this->response->setVal('renderUserTalkArchiveAnchor', $this->request->getVal('dontRenderUserTalkArchiveAnchor', false) != true); $greeting = Title::newFromText($title->getText(), NS_USER_WALL_MESSAGE_GREETING); $greetingText = ''; if (!empty($greeting) && $greeting->exists()) { $article = new Article($greeting); $article->getParserOptions(); $article->mParserOptions->setIsPreview(true); // create parser option $article->mParserOptions->setEditSection(false); $greetingText = $article->getParserOutput()->getText(); } wfRunHooks('WallGreetingContent', array(&$greetingText)); // used by SWM to add messages to Wall in monobook $this->response->setVal('greeting', $greetingText); $this->response->setVal('sortingOptions', $this->getSortingOptions()); $this->response->setVal('sortingSelected', $this->getSortingSelectedText()); $this->response->setVal('title', $title); $this->response->setVal('totalItems', $this->countComments); $this->response->setVal('itemsPerPage', $wallMessagesPerPage); $this->response->setVal('showPager', $this->countComments > $wallMessagesPerPage); $this->response->setVal('currentPage', $page); Transaction::setSizeCategoryByDistributionOffset($this->countComments, 0, self::DEFAULT_MESSAGES_PER_PAGE); // TODO: keep the varnish cache and do purging on post $this->response->setCacheValidity(WikiaResponse::CACHE_DISABLED); wfProfileOut(__METHOD__); }